Skip to content

Commit

Permalink
Change keys of config
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Apr 1, 2024
1 parent 491520e commit 15cf73d
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 93 deletions.
6 changes: 3 additions & 3 deletions packages/relay/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ contracts:
loyaltyExchangerAddress: "${LOYALTY_EXCHANGER_CONTRACT_ADDRESS}"
loyaltyTransferAddress: "${LOYALTY_TRANSFER_CONTRACT_ADDRESS}"
tokenAddress : "${TOKEN_CONTRACT_ADDRESS}"
loyaltyBridgeAddress: "${LOYALTY_BRIDGE_CONTRACT_ADDRESS}"
bridgeAddress: "${SIDE_CHAIN_BRIDGE_CONTRACT_ADDRESS}"
loyaltyBridgeAddress: "${SIDE_CHAIN_LOYALTY_BRIDGE_CONTRACT_ADDRESS}"
chainBridgeAddress: "${SIDE_CHAIN_BRIDGE_CONTRACT_ADDRESS}"
mainChain:
network: "production_main"
tokenAddress : "${MAIN_CHAIN_TOKEN_CONTRACT_ADDRESS}"
loyaltyBridgeAddress: "${MAIN_CHAIN_LOYALTY_BRIDGE_CONTRACT_ADDRESS}"
bridgeAddress: "${MAIN_CHAIN_BRIDGE_CONTRACT_ADDRESS}"
chainBridgeAddress: "${MAIN_CHAIN_BRIDGE_CONTRACT_ADDRESS}"

metrics:
accounts:
Expand Down
6 changes: 3 additions & 3 deletions packages/relay/config/config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ contracts:
loyaltyExchangerAddress: "${LOYALTY_EXCHANGER_CONTRACT_ADDRESS}"
loyaltyTransferAddress: "${LOYALTY_TRANSFER_CONTRACT_ADDRESS}"
tokenAddress : "${TOKEN_CONTRACT_ADDRESS}"
loyaltyBridgeAddress: "${LOYALTY_BRIDGE_CONTRACT_ADDRESS}"
bridgeAddress: "${SIDE_CHAIN_BRIDGE_CONTRACT_ADDRESS}"
loyaltyBridgeAddress: "${SIDE_CHAIN_LOYALTY_BRIDGE_CONTRACT_ADDRESS}"
chainBridgeAddress: "${SIDE_CHAIN_BRIDGE_CONTRACT_ADDRESS}"
mainChain:
network: "hardhat"
tokenAddress : "${MAIN_CHAIN_TOKEN_CONTRACT_ADDRESS}"
loyaltyBridgeAddress: "${MAIN_CHAIN_LOYALTY_BRIDGE_CONTRACT_ADDRESS}"
bridgeAddress: "${MAIN_CHAIN_BRIDGE_CONTRACT_ADDRESS}"
chainBridgeAddress: "${MAIN_CHAIN_BRIDGE_CONTRACT_ADDRESS}"

metrics:
accounts:
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/env/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ LOYALTY_PROVIDER_CONTRACT_ADDRESS=0xDD91A65534847537c290FEbc721cf8457f860744
LOYALTY_CONSUMER_CONTRACT_ADDRESS=0xb9CE93eeb00a74Deeec319cBCD37938b5aAE6314
LOYALTY_EXCHANGER_CONTRACT_ADDRESS=0x1ae7b2564Ae7a7Fb1E7976F3F71cAF43ef49ac6F
LOYALTY_TRANSFER_CONTRACT_ADDRESS=0xcAE5A9f266991dcEdc62bb9291f15E112f212820
LOYALTY_BRIDGE_CONTRACT_ADDRESS=0xd73e6a2f2e47236F1Ff737E72497f598652122F9
SIDE_CHAIN_LOYALTY_BRIDGE_CONTRACT_ADDRESS=0xd73e6a2f2e47236F1Ff737E72497f598652122F9
SIDE_CHAIN_BRIDGE_CONTRACT_ADDRESS=0xd73e6a2f2e47236F1Ff737E72497f598652122F9

MAIN_CHAIN_TOKEN_CONTRACT_ADDRESS=0xB1A90a5C6e30d64Ab6f64C30eD392F46eDBcb022
Expand Down
32 changes: 17 additions & 15 deletions packages/relay/src/common/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ export class ContractsConfig implements IContractsConfig {
loyaltyExchangerAddress: string;
loyaltyTransferAddress: string;
loyaltyBridgeAddress: string;
bridgeAddress: string;
chainBridgeAddress: string;
};
public mainChain: {
network: string;
tokenAddress: string;
loyaltyBridgeAddress: string;
bridgeAddress: string;
chainBridgeAddress: string;
};

constructor() {
Expand All @@ -283,20 +283,20 @@ export class ContractsConfig implements IContractsConfig {
loyaltyExchangerAddress: defaults.sideChain.loyaltyExchangerAddress,
loyaltyTransferAddress: defaults.sideChain.loyaltyTransferAddress,
loyaltyBridgeAddress: defaults.sideChain.loyaltyBridgeAddress,
bridgeAddress: defaults.sideChain.bridgeAddress,
chainBridgeAddress: defaults.sideChain.chainBridgeAddress,
};
this.mainChain = {
network: defaults.mainChain.network,
tokenAddress: defaults.mainChain.tokenAddress,
loyaltyBridgeAddress: defaults.mainChain.loyaltyBridgeAddress,
bridgeAddress: defaults.mainChain.bridgeAddress,
chainBridgeAddress: defaults.mainChain.chainBridgeAddress,
};
}

public static defaultValue(): IContractsConfig {
return {
sideChain: {
network: "production_net",
network: "production_side",
tokenAddress: process.env.TOKEN_CONTRACT_ADDRESS || "",
ledgerAddress: process.env.LEDGER_CONTRACT_ADDRESS || "",
phoneLinkerAddress: process.env.PHONE_LINKER_CONTRACT_ADDRESS || "",
Expand All @@ -306,14 +306,14 @@ export class ContractsConfig implements IContractsConfig {
loyaltyConsumerAddress: process.env.LOYALTY_CONSUMER_CONTRACT_ADDRESS || "",
loyaltyExchangerAddress: process.env.LOYALTY_EXCHANGER_CONTRACT_ADDRESS || "",
loyaltyTransferAddress: process.env.LOYALTY_TRANSFER_CONTRACT_ADDRESS || "",
loyaltyBridgeAddress: process.env.LOYALTY_BRIDGE_CONTRACT_ADDRESS || "",
bridgeAddress: process.env.LOYALTY_BRIDGE_CONTRACT_ADDRESS || "",
loyaltyBridgeAddress: process.env.SIDE_CHAIN_LOYALTY_BRIDGE_CONTRACT_ADDRESS || "",
chainBridgeAddress: process.env.SIDE_CHAIN_BRIDGE_CONTRACT_ADDRESS || "",
},
mainChain: {
network: "bosagora_mainnet",
tokenAddress: process.env.TOKEN_CONTRACT_ADDRESS || "",
loyaltyBridgeAddress: process.env.LOYALTY_BRIDGE_CONTRACT_ADDRESS || "",
bridgeAddress: process.env.LOYALTY_TRANSFER_CONTRACT_ADDRESS || "",
network: "production_main",
tokenAddress: process.env.MAIN_CHAIN_TOKEN_CONTRACT_ADDRESS || "",
loyaltyBridgeAddress: process.env.MAIN_CHAIN_LOYALTY_BRIDGE_CONTRACT_ADDRESS || "",
chainBridgeAddress: process.env.MAIN_CHAIN_BRIDGE_CONTRACT_ADDRESS || "",
},
};
}
Expand All @@ -337,13 +337,15 @@ export class ContractsConfig implements IContractsConfig {
this.sideChain.loyaltyTransferAddress = config.sideChain.loyaltyTransferAddress;
if (config.sideChain.loyaltyBridgeAddress !== undefined)
this.sideChain.loyaltyBridgeAddress = config.sideChain.loyaltyBridgeAddress;
if (config.sideChain.bridgeAddress !== undefined) this.sideChain.bridgeAddress = config.sideChain.bridgeAddress;
if (config.sideChain.chainBridgeAddress !== undefined)
this.sideChain.chainBridgeAddress = config.sideChain.chainBridgeAddress;

if (config.mainChain.network !== undefined) this.mainChain.network = config.mainChain.network;
if (config.mainChain.tokenAddress !== undefined) this.mainChain.tokenAddress = config.mainChain.tokenAddress;
if (config.mainChain.loyaltyBridgeAddress !== undefined)
this.mainChain.loyaltyBridgeAddress = config.mainChain.loyaltyBridgeAddress;
if (config.mainChain.bridgeAddress !== undefined) this.mainChain.bridgeAddress = config.mainChain.bridgeAddress;
if (config.mainChain.chainBridgeAddress !== undefined)
this.mainChain.chainBridgeAddress = config.mainChain.chainBridgeAddress;
}
}

Expand Down Expand Up @@ -469,13 +471,13 @@ export interface IContractsConfig {
currencyRateAddress: string;
loyaltyTransferAddress: string;
loyaltyBridgeAddress: string;
bridgeAddress: string;
chainBridgeAddress: string;
};
mainChain: {
network: string;
tokenAddress: string;
loyaltyBridgeAddress: string;
bridgeAddress: string;
chainBridgeAddress: string;
};
}

Expand Down
20 changes: 10 additions & 10 deletions packages/relay/src/contract/ContractManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export class ContractManager {
private _sideLoyaltyExchangerContract: LoyaltyExchanger | undefined;
private _sideLoyaltyTransferContract: LoyaltyTransfer | undefined;
private _sideLoyaltyBridgeContract: LoyaltyBridge | undefined;
private _sideBridge: Bridge | undefined;
private _sideChainBridge: Bridge | undefined;

private _mainTokenContract: BIP20DelegatedTransfer | undefined;
private _mainLoyaltyBridgeContract: Bridge | undefined;
private _mainBridge: Bridge | undefined;
private _mainChainBridge: Bridge | undefined;

private _sideChainProvider: ethers.providers.Provider | undefined;
private _mainChainProvider: ethers.providers.Provider | undefined;
Expand Down Expand Up @@ -80,7 +80,7 @@ export class ContractManager {
this._sideLoyaltyBridgeContract = factory9.attach(this.config.contracts.sideChain.loyaltyBridgeAddress);

const factory10 = await hre.ethers.getContractFactory("Bridge");
this._sideBridge = factory10.attach(this.config.contracts.sideChain.bridgeAddress);
this._sideChainBridge = factory10.attach(this.config.contracts.sideChain.chainBridgeAddress);

await hre.changeNetwork(this.config.contracts.mainChain.network);
this._mainChainProvider = hre.ethers.provider;
Expand All @@ -92,7 +92,7 @@ export class ContractManager {
this._mainLoyaltyBridgeContract = factory12.attach(this.config.contracts.mainChain.loyaltyBridgeAddress);

const factory13 = await hre.ethers.getContractFactory("Bridge");
this._mainBridge = factory13.attach(this.config.contracts.mainChain.bridgeAddress);
this._mainChainBridge = factory13.attach(this.config.contracts.mainChain.chainBridgeAddress);

this._mainChainId = (await this._mainChainProvider.getNetwork()).chainId;
}
Expand Down Expand Up @@ -209,10 +209,10 @@ export class ContractManager {
}
}

public get sideBridge(): Bridge {
if (this._sideBridge !== undefined) return this._sideBridge;
public get sideChainBridge(): Bridge {
if (this._sideChainBridge !== undefined) return this._sideChainBridge;
else {
logger.error("sideBridge is not ready yet.");
logger.error("sideChainBridge is not ready yet.");
process.exit(1);
}
}
Expand All @@ -233,10 +233,10 @@ export class ContractManager {
}
}

public get mainBridge(): Bridge {
if (this._mainBridge !== undefined) return this._mainBridge;
public get mainChainBridge(): Bridge {
if (this._mainChainBridge !== undefined) return this._mainChainBridge;
else {
logger.error("mainBridge is not ready yet.");
logger.error("mainChainBridge is not ready yet.");
process.exit(1);
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/relay/src/routers/BridgeRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class BridgeRouter {
private async getDepositId(account: string): Promise<string> {
while (true) {
const id = ContractUtils.getRandomId(account);
if (await this.contractManager.sideBridge.isAvailableDepositId(id)) return id;
if (await this.contractManager.sideChainBridge.isAvailableDepositId(id)) return id;
}
}

Expand All @@ -186,7 +186,7 @@ export class BridgeRouter {
const nonce = await this.contractManager.sideTokenContract.nonceOf(account);
const message = ContractUtils.getTransferMessage(
account,
this.contractManager.sideBridge.address,
this.contractManager.sideChainBridge.address,
amount,
nonce,
this.contractManager.sideChainId
Expand All @@ -199,7 +199,7 @@ export class BridgeRouter {
await this.contractManager.sideTokenContract.symbol()
);
const depositId = await this.getDepositId(account);
const tx = await this.contractManager.sideBridge
const tx = await this.contractManager.sideChainBridge
.connect(signerItem.signer)
.depositToBridge(tokenId, depositId, account, amount, signature);

Expand Down Expand Up @@ -234,7 +234,7 @@ export class BridgeRouter {
const nonce = await this.contractManager.mainTokenContract.nonceOf(account);
const message = ContractUtils.getTransferMessage(
account,
this.contractManager.mainBridge.address,
this.contractManager.mainChainBridge.address,
amount,
nonce,
this.contractManager.mainChainId
Expand All @@ -247,7 +247,7 @@ export class BridgeRouter {
await this.contractManager.mainTokenContract.symbol()
);
const depositId = await this.getDepositId(account);
const tx = await this.contractManager.mainBridge
const tx = await this.contractManager.mainChainBridge
.connect(signerItem.signer)
.depositToBridge(tokenId, depositId, account, amount, signature);

Expand Down
40 changes: 20 additions & 20 deletions packages/relay/test/Bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ describe("Test of Bridge", function () {
config.contracts.sideChain.loyaltyExchangerAddress = deployments.getContractAddress("LoyaltyExchanger") || "";
config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || "";
config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || "";
config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || "";
config.contracts.sideChain.chainBridgeAddress = deployments.getContractAddress("SideChainBridge") || "";

config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || "";
config.contracts.mainChain.loyaltyBridgeAddress =
deployments.getContractAddress("MainChainLoyaltyBridge") || "";
config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || "";
config.contracts.mainChain.chainBridgeAddress = deployments.getContractAddress("MainChainBridge") || "";

config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey);
config.relay.relayEndpoint = `http://127.0.0.1:${config.server.port}`;
Expand Down Expand Up @@ -104,13 +104,13 @@ describe("Test of Bridge", function () {
const amount = Amount.make(500, 18).value;

const balance0 = await contractManager.mainTokenContract.balanceOf(account.address);
const balance1 = await contractManager.mainTokenContract.balanceOf(contractManager.mainBridge.address);
const balance1 = await contractManager.mainTokenContract.balanceOf(contractManager.mainChainBridge.address);
const balance2 = await contractManager.sideTokenContract.balanceOf(account.address);

const nonce = await contractManager.mainTokenContract.nonceOf(account.address);
const message = await ContractUtils.getTransferMessage(
account.address,
contractManager.mainBridge.address,
contractManager.mainChainBridge.address,
amount,
nonce,
contractManager.mainChainId
Expand All @@ -129,25 +129,25 @@ describe("Test of Bridge", function () {
expect(response.data.data.txHash).to.match(/^0x[A-Fa-f0-9]{64}$/i);

/// Approve of Validators
await contractManager.sideBridge
await contractManager.sideChainBridge
.connect(deployments.accounts.bridgeValidators[0])
.withdrawFromBridge(response.data.data.tokenId, response.data.data.depositId, account.address, amount);

await contractManager.sideBridge
await contractManager.sideChainBridge
.connect(deployments.accounts.bridgeValidators[1])
.withdrawFromBridge(response.data.data.tokenId, response.data.data.depositId, account.address, amount);

await contractManager.sideBridge
await contractManager.sideChainBridge
.connect(deployments.accounts.bridgeValidators[2])
.withdrawFromBridge(response.data.data.tokenId, response.data.data.depositId, account.address, amount);
///

expect(await contractManager.mainTokenContract.balanceOf(account.address)).to.deep.equal(balance0.sub(amount));
expect(await contractManager.mainTokenContract.balanceOf(contractManager.mainBridge.address)).to.deep.equal(
balance1.add(amount)
);
expect(
await contractManager.mainTokenContract.balanceOf(contractManager.mainChainBridge.address)
).to.deep.equal(balance1.add(amount));

const fee = await contractManager.sideBridge.getFee(tokenId);
const fee = await contractManager.sideChainBridge.getFee(tokenId);
expect(await contractManager.sideTokenContract.balanceOf(account.address)).to.deep.equal(
balance2.add(amount).sub(fee)
);
Expand All @@ -163,13 +163,13 @@ describe("Test of Bridge", function () {
const amount = Amount.make(200, 18).value;

const balance0 = await contractManager.mainTokenContract.balanceOf(account.address);
const balance1 = await contractManager.mainTokenContract.balanceOf(contractManager.mainBridge.address);
const balance1 = await contractManager.mainTokenContract.balanceOf(contractManager.mainChainBridge.address);
const balance2 = await contractManager.sideTokenContract.balanceOf(account.address);

const nonce = await contractManager.sideTokenContract.nonceOf(account.address);
const message = await ContractUtils.getTransferMessage(
account.address,
contractManager.sideBridge.address,
contractManager.sideChainBridge.address,
amount,
nonce,
contractManager.sideChainId
Expand All @@ -188,26 +188,26 @@ describe("Test of Bridge", function () {
expect(response.data.data.txHash).to.match(/^0x[A-Fa-f0-9]{64}$/i);

/// Approve of Validators
await contractManager.mainBridge
await contractManager.mainChainBridge
.connect(deployments.accounts.bridgeValidators[0])
.withdrawFromBridge(response.data.data.tokenId, response.data.data.depositId, account.address, amount);

await contractManager.mainBridge
await contractManager.mainChainBridge
.connect(deployments.accounts.bridgeValidators[1])
.withdrawFromBridge(response.data.data.tokenId, response.data.data.depositId, account.address, amount);

await contractManager.mainBridge
await contractManager.mainChainBridge
.connect(deployments.accounts.bridgeValidators[2])
.withdrawFromBridge(response.data.data.tokenId, response.data.data.depositId, account.address, amount);
///

const fee = await contractManager.mainBridge.getFee(tokenId);
const fee = await contractManager.mainChainBridge.getFee(tokenId);
expect(await contractManager.mainTokenContract.balanceOf(account.address)).to.deep.equal(
balance0.add(amount).sub(fee)
);
expect(await contractManager.mainTokenContract.balanceOf(contractManager.mainBridge.address)).to.deep.equal(
balance1.sub(amount)
);
expect(
await contractManager.mainTokenContract.balanceOf(contractManager.mainChainBridge.address)
).to.deep.equal(balance1.sub(amount));
//
expect(await contractManager.sideTokenContract.balanceOf(account.address)).to.deep.equal(balance2.sub(amount));
});
Expand Down
4 changes: 2 additions & 2 deletions packages/relay/test/DelegatedTransfer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ describe("Test of delegated transfer", function () {
config.contracts.sideChain.loyaltyExchangerAddress = deployments.getContractAddress("LoyaltyExchanger") || "";
config.contracts.sideChain.loyaltyTransferAddress = deployments.getContractAddress("LoyaltyTransfer") || "";
config.contracts.sideChain.loyaltyBridgeAddress = deployments.getContractAddress("LoyaltyBridge") || "";
config.contracts.sideChain.bridgeAddress = deployments.getContractAddress("SideChainBridge") || "";
config.contracts.sideChain.chainBridgeAddress = deployments.getContractAddress("SideChainBridge") || "";

config.contracts.mainChain.tokenAddress = deployments.getContractAddress("MainChainKIOS") || "";
config.contracts.mainChain.loyaltyBridgeAddress =
deployments.getContractAddress("MainChainLoyaltyBridge") || "";
config.contracts.mainChain.bridgeAddress = deployments.getContractAddress("MainChainBridge") || "";
config.contracts.mainChain.chainBridgeAddress = deployments.getContractAddress("MainChainBridge") || "";

config.relay.managerKeys = deployments.accounts.certifiers.map((m) => m.privateKey);
config.relay.relayEndpoint = `http://127.0.0.1:${config.server.port}`;
Expand Down
Loading

0 comments on commit 15cf73d

Please sign in to comment.