Skip to content

Commit

Permalink
Merge pull request #37 from stc-community/op
Browse files Browse the repository at this point in the history
Feat: OP Chain adapt
  • Loading branch information
rovast authored Aug 9, 2023
2 parents 1efcfcb + ee75e01 commit 331e911
Show file tree
Hide file tree
Showing 15 changed files with 259 additions and 48 deletions.
8 changes: 6 additions & 2 deletions src/components/Modal/account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { ref } from "vue";
import { useLang } from "@/hooks/useLang";
const { t } = useLang();
import { getNewNostrPrivateKey } from "@/utils/shared";
import { getNewNostrPrivateKey, md5 } from "@/utils/shared";
import { getPublicKey } from "nostr-tools";
import { getUserHubContract } from "@/utils/contract/user-hub";
import { handleEtherError, encrypt } from "@/utils/shared";
Expand Down Expand Up @@ -40,7 +40,11 @@ const handleSubmit = async () => {
privateKey.value,
nostrEncryptKey
);
const transaction = await contract.registerUser(publicKey, nostrEncryptKey);
const transaction = await contract.registerUser(
publicKey,
nostrEncryptKey,
md5(publicKey)
);
await transaction.wait();
window.location.reload();
Expand Down
10 changes: 3 additions & 7 deletions src/components/Modal/new-deployment.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { getContainerContract } from "@/utils/contract/container";
import { getCurrentChain } from "@/config/chain";
import { reactive, onBeforeUnmount } from "vue";
import type { EventLog } from "ethers";
import eventBus from "@/utils/event-bus";
Expand All @@ -13,11 +14,6 @@ defineOptions({
name: "deployment-modal"
});
const PARAM = {
jobID: "68c1dc5cd63841459ff2395a931f042c",
oracle: "0xC1A56c1c85a4D957a513719FdB30eac50a861433"
};
const data = reactive({
res: "",
loading: false,
Expand Down Expand Up @@ -58,8 +54,8 @@ const handleSubmit = async () => {
try {
const transaction = await contract.requestContainerDeploy(
PARAM.oracle,
PARAM.jobID,
getCurrentChain().oracle,
getCurrentChain().deploymentJobId,
window.btoa(data.requestData),
`https://stc-test.${getCurrentSiteName(
"gw"
Expand Down
7 changes: 4 additions & 3 deletions src/components/Modal/new-pod.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { getPodContract, PARAM } from "@/utils/contract/pod";
import { reactive, onBeforeUnmount } from "vue";
import { getPodContract } from "@/utils/contract/pod";
import { getCurrentChain } from "@/config/chain";
import type { EventLog } from "ethers";
import eventBus from "@/utils/event-bus";
import { getCurrentSiteName, md5 } from "@/utils/shared";
Expand Down Expand Up @@ -46,8 +47,8 @@ const handleSubmit = async () => {
try {
const transaction = await contract.requestContainerPod(
PARAM.oracle,
PARAM.jobID,
getCurrentChain().oracle,
getCurrentChain().podJobId,
window.btoa(data.requestData),
`https://stc-test.${getCurrentSiteName(
"gw"
Expand Down
99 changes: 99 additions & 0 deletions src/config/chain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// 合约相关的配置

type ChainName = "Optimism Goerli Testnet" | "Sepolia";

type Chain = {
chainId: string;
chainName: ChainName;

chainlistUrl: string;

oracle: string;

podContract: string; // 新建 pod
podJobId: string;

deploymentContract: string; // 新建 deployment
deploymentJobId: string;

nodeContract: string; // 新建 node
nodeJobId: string;
nodeOracle: string;

zeroTrustContract: string; // mesh 菜单中的切换网络状态和证书监听状态
meshContract: string; // 服务熔断限流
codContract: string; // 函数运算

stcMarketContract: string;
stcMarketTokenContract: string;

userHubContract: string;
};

const chains: Chain[] = [
{
chainId: "0x1a4",
chainName: "Optimism Goerli Testnet",
chainlistUrl: "https://chainlist.org/chain/420",

oracle: "0xac463983a9379e175D6117d2F961a8621037931c",

podContract: "0x3aDb761e02a76e9E8C8aBD12B2744f32F15D7166",
podJobId: "780d3dd1933a4a9d839f4c78d92ab595",

deploymentContract: "0xD6540c5eC23f664D3Fee7E2Aa608C6B197FD24ce",
deploymentJobId: "68c1dc5cd63841459ff2395a931f042c",

nodeContract: "0x05D3256D6aEd676dcd65A7250dE4094239Aa6a67",
nodeJobId: "aa7198c0190f4cc29d4e4470c08f6391",
nodeOracle: "0xac463983a9379e175D6117d2F961a8621037931c",

zeroTrustContract: "0x0A873038d29bf16871232f59D589deA2B849C846",

meshContract: "0x7A338445C1eAE2f13E294C28050541686187Cd5F",

codContract: "0x98e7f2Bc989Bd181a009DA780C83A78e00AD9549",

stcMarketContract: "0xE972F4bB8313102bFEF7Fe1F7adfC6Ae2Bc0f933",
stcMarketTokenContract: "0xc07f40758d3bb0f8B8E4C4d146f79265484ba6Fe",

userHubContract: "0x1a441523e6FF0f657222bb673C05BF1EeE551174"
},
{
chainId: "0xaa36a7",
chainName: "Sepolia",
chainlistUrl: "https://chainlist.org/chain/11155111",

oracle: "0xC1A56c1c85a4D957a513719FdB30eac50a861433",

podContract: "0xC033615137D482f51718106489035bE6CCDcE0DD",
podJobId: "780d3dd1933a4a9d839f4c78d92ab595",

deploymentContract: "0x70F4C5425bf1eAcd1fcfdaC5BfF5393EF45cA53E",
deploymentJobId: "68c1dc5cd63841459ff2395a931f042c",

nodeContract: "0x1Acc504c02768ff00fBcEB331dB5Eda37fAC006E",
nodeJobId: "aa7198c0190f4cc29d4e4470c08f6391",
nodeOracle: "0x248E10ec1C54CB570F7A15933286BAa1D59B70c0",

zeroTrustContract: "0x1Dd5940C70FFAeFe80EF4902ea5Ae9a2Ec3b574D",

meshContract: "0x51aeb604fBfC7D40aB331ffFc007F246C2Db9180",

codContract: "0x754e87664F278f2be89b3f496955752f127fBdf8",

stcMarketContract: "0x6051273DB68F2af68617589f30F8a91f859e5b82",
stcMarketTokenContract: "0x8b321Dde4CAe93848f756895fdb34E889A6c831b",

userHubContract: "0xE87a986fDc35170c66C3a2449bC4Aee6350cc1F6"
}
];

let currentChain: ChainName = "Optimism Goerli Testnet";
export function setCurrentChain(name: ChainName) {
currentChain = name;
}

export function getCurrentChain() {
return chains.find(i => i.chainName === currentChain);
}
7 changes: 5 additions & 2 deletions src/utils/contract/cod.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { getWritebleContractInstance } from "./web3";
import { getCurrentChain } from "@/config/chain";

// @ts-ignore
import ABI from "./cod-abi.json?raw";
const ADDR = "0x754e87664F278f2be89b3f496955752f127fBdf8";

export async function getCodConrtact() {
const contract = await getWritebleContractInstance(ADDR, ABI);
const contract = await getWritebleContractInstance(
getCurrentChain().codContract,
ABI
);

return contract;
}
7 changes: 5 additions & 2 deletions src/utils/contract/container.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { getWritebleContractInstance } from "./web3";
import { getCurrentChain } from "@/config/chain";

// @ts-ignore
import ABI from "./container-abi.json?raw";
const ADDR = "0x70F4C5425bf1eAcd1fcfdaC5BfF5393EF45cA53E";

export async function getContainerContract() {
const contract = await getWritebleContractInstance(ADDR, ABI);
const contract = await getWritebleContractInstance(
getCurrentChain().deploymentContract,
ABI
);

return contract;
}
12 changes: 9 additions & 3 deletions src/utils/contract/dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import {
getReadonlyConractInstance,
getWritebleContractInstance
} from "./web3";
import { getCurrentChain } from "@/config/chain";

// @ts-ignore
import ABI from "./dao-abi.json?raw";
const ADDR = "0x6051273DB68F2af68617589f30F8a91f859e5b82";

let writeContract;
export async function getDaoContract() {
if (!writeContract) {
writeContract = await getWritebleContractInstance(ADDR, ABI);
writeContract = await getWritebleContractInstance(
getCurrentChain().stcMarketContract,
ABI
);
}

return writeContract;
Expand All @@ -19,7 +22,10 @@ export async function getDaoContract() {
let readContract;
export async function getReadonlyDaoContract() {
if (!readContract) {
readContract = await getReadonlyConractInstance(ADDR, ABI);
readContract = await getReadonlyConractInstance(
getCurrentChain().stcMarketContract,
ABI
);
}

return readContract;
Expand Down
7 changes: 5 additions & 2 deletions src/utils/contract/mesh.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { getWritebleContractInstance } from "./web3";
import { getCurrentChain } from "@/config/chain";

// @ts-ignore
import ABI from "./mesh-abi.json?raw";
const ADDR = "0x1Dd5940C70FFAeFe80EF4902ea5Ae9a2Ec3b574D";

export async function getMeshConrtact() {
const contract = await getWritebleContractInstance(ADDR, ABI);
const contract = await getWritebleContractInstance(
getCurrentChain().zeroTrustContract,
ABI
);

return contract;
}
12 changes: 5 additions & 7 deletions src/utils/contract/node.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { getWritebleContractInstance } from "./web3";
import { getCurrentChain } from "@/config/chain";

// @ts-ignore
import ABI from "./node-abi.json?raw";
const ADDR = "0x1Acc504c02768ff00fBcEB331dB5Eda37fAC006E";

export const PARAM = {
jobID: "aa7198c0190f4cc29d4e4470c08f6391",
oracle: "0x248E10ec1C54CB570F7A15933286BAa1D59B70c0"
};

export async function getNodeContract() {
const contract = await getWritebleContractInstance(ADDR, ABI);
const contract = await getWritebleContractInstance(
getCurrentChain().nodeContract,
ABI
);

return contract;
}
12 changes: 5 additions & 7 deletions src/utils/contract/pod.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { getWritebleContractInstance } from "./web3";
import { getCurrentChain } from "@/config/chain";

// @ts-ignore
import ABI from "./pod-abi.json?raw";
const ADDR = "0xC033615137D482f51718106489035bE6CCDcE0DD";

export const PARAM = {
jobID: "780d3dd1933a4a9d839f4c78d92ab595",
oracle: "0xC1A56c1c85a4D957a513719FdB30eac50a861433"
};

export async function getPodContract() {
const contract = await getWritebleContractInstance(ADDR, ABI);
const contract = await getWritebleContractInstance(
getCurrentChain().podContract,
ABI
);

return contract;
}
12 changes: 9 additions & 3 deletions src/utils/contract/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import {
getReadonlyConractInstance,
getWritebleContractInstance
} from "./web3";
import { getCurrentChain } from "@/config/chain";

// @ts-ignore
import ABI from "./token.json?raw";
const ADDR = "0x8b321Dde4CAe93848f756895fdb34E889A6c831b";

let writeContract;
export async function getTokenContract() {
if (!writeContract) {
writeContract = await getWritebleContractInstance(ADDR, ABI);
writeContract = await getWritebleContractInstance(
getCurrentChain().stcMarketTokenContract,
ABI
);
}

return writeContract;
Expand All @@ -19,7 +22,10 @@ export async function getTokenContract() {
let readContract;
export async function getReadonlyTokenContract() {
if (!readContract) {
readContract = await getReadonlyConractInstance(ADDR, ABI);
readContract = await getReadonlyConractInstance(
getCurrentChain().stcMarketTokenContract,
ABI
);
}

return readContract;
Expand Down
Loading

0 comments on commit 331e911

Please sign in to comment.