Skip to content

Commit

Permalink
[Relay] Add endpoints of bridge between main chain and side chain
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Mar 29, 2024
1 parent adfb544 commit 8d0392c
Show file tree
Hide file tree
Showing 20 changed files with 559 additions and 69 deletions.
4 changes: 2 additions & 2 deletions packages/relay/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ contracts:
loyaltyTransferAddress: "${LOYALTY_TRANSFER_CONTRACT_ADDRESS}"
tokenAddress : "${TOKEN_CONTRACT_ADDRESS}"
loyaltyBridgeAddress: "${LOYALTY_BRIDGE_CONTRACT_ADDRESS}"
bridgeMainSideAddress: "${SIDE_CHAIN_BRIDGE_CONTRACT_ADDRESS}"
bridgeAddress: "${SIDE_CHAIN_BRIDGE_CONTRACT_ADDRESS}"
mainChain:
network: "bosagora_testnet"
tokenAddress : "${MAIN_CHAIN_TOKEN_CONTRACT_ADDRESS}"
loyaltyBridgeAddress: "${MAIN_CHAIN_LOYALTY_BRIDGE_CONTRACT_ADDRESS}"
bridgeMainSideAddress: "${MAIN_CHAIN_BRIDGE_CONTRACT_ADDRESS}"
bridgeAddress: "${MAIN_CHAIN_BRIDGE_CONTRACT_ADDRESS}"

metrics:
accounts:
Expand Down
4 changes: 2 additions & 2 deletions packages/relay/config/config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ contracts:
loyaltyTransferAddress: "${LOYALTY_TRANSFER_CONTRACT_ADDRESS}"
tokenAddress : "${TOKEN_CONTRACT_ADDRESS}"
loyaltyBridgeAddress: "${LOYALTY_BRIDGE_CONTRACT_ADDRESS}"
bridgeMainSideAddress: "${SIDE_CHAIN_BRIDGE_CONTRACT_ADDRESS}"
bridgeAddress: "${SIDE_CHAIN_BRIDGE_CONTRACT_ADDRESS}"
mainChain:
network: "hardhat"
tokenAddress : "${MAIN_CHAIN_TOKEN_CONTRACT_ADDRESS}"
loyaltyBridgeAddress: "${MAIN_CHAIN_LOYALTY_BRIDGE_CONTRACT_ADDRESS}"
bridgeMainSideAddress: "${MAIN_CHAIN_BRIDGE_CONTRACT_ADDRESS}"
bridgeAddress: "${MAIN_CHAIN_BRIDGE_CONTRACT_ADDRESS}"

metrics:
accounts:
Expand Down
1 change: 1 addition & 0 deletions packages/relay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"test:DelegatorApproval": "TESTING=true hardhat test test/DelegatorApproval.test.ts",
"test:LoyaltyTransfer": "TESTING=true hardhat test test/LoyaltyTransfer.test.ts",
"test:LoyaltyBridge": "TESTING=true hardhat test test/LoyaltyBridge.test.ts",
"test:Bridge": "TESTING=true hardhat test test/Bridge.test.ts",
"test:DelegatedTransfer": "TESTING=true hardhat test test/DelegatedTransfer.test.ts"
},
"repository": {
Expand Down
19 changes: 16 additions & 3 deletions packages/relay/src/DefaultServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ContractManager } from "./contract/ContractManager";
import { RelaySigners } from "./contract/Signers";
import { INotificationEventHandler, INotificationSender, NotificationSender } from "./delegator/NotificationSender";
import { Metrics } from "./metrics/Metrics";
import { BridgeRouter } from "./routers/BridgeRouter";
import { PhoneLinkRouter } from "./routers/PhoneLinkRouter";
import { StorePurchaseRouter } from "./routers/StorePurchaseRouter";
import { TokenRouter } from "./routers/TokenRouter";
Expand All @@ -36,7 +37,8 @@ export class DefaultServer extends WebService {
public readonly etcRouter: ETCRouter;
public readonly purchaseRouter: StorePurchaseRouter;
public readonly tokenRouter: TokenRouter;
public readonly phonelinkRouter: PhoneLinkRouter;
public readonly phoneLinkRouter: PhoneLinkRouter;
public readonly bridgeRouter: BridgeRouter;

private readonly metrics: Metrics;

Expand Down Expand Up @@ -134,7 +136,17 @@ export class DefaultServer extends WebService {
this.graph,
this.relaySigners
);
this.phonelinkRouter = new PhoneLinkRouter(
this.phoneLinkRouter = new PhoneLinkRouter(
this,
this.config,
this.contractManager,
this.metrics,
this.storage,
this.graph,
this.relaySigners
);

this.bridgeRouter = new BridgeRouter(
this,
this.config,
this.contractManager,
Expand Down Expand Up @@ -184,7 +196,8 @@ export class DefaultServer extends WebService {
this.etcRouter.registerRoutes();
this.purchaseRouter.registerRoutes();
this.tokenRouter.registerRoutes();
this.phonelinkRouter.registerRoutes();
this.phoneLinkRouter.registerRoutes();
this.bridgeRouter.registerRoutes();

for (const m of this.schedules) await m.start();

Expand Down
22 changes: 10 additions & 12 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;
bridgeMainSideAddress: string;
bridgeAddress: string;
};
public mainChain: {
network: string;
tokenAddress: string;
loyaltyBridgeAddress: string;
bridgeMainSideAddress: string;
bridgeAddress: string;
};

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

Expand All @@ -307,13 +307,13 @@ export class ContractsConfig implements IContractsConfig {
loyaltyExchangerAddress: process.env.LOYALTY_EXCHANGER_CONTRACT_ADDRESS || "",
loyaltyTransferAddress: process.env.LOYALTY_TRANSFER_CONTRACT_ADDRESS || "",
loyaltyBridgeAddress: process.env.LOYALTY_BRIDGE_CONTRACT_ADDRESS || "",
bridgeMainSideAddress: process.env.LOYALTY_BRIDGE_CONTRACT_ADDRESS || "",
bridgeAddress: process.env.LOYALTY_BRIDGE_CONTRACT_ADDRESS || "",
},
mainChain: {
network: "bosagora_mainnet",
tokenAddress: process.env.TOKEN_CONTRACT_ADDRESS || "",
loyaltyBridgeAddress: process.env.LOYALTY_BRIDGE_CONTRACT_ADDRESS || "",
bridgeMainSideAddress: process.env.LOYALTY_TRANSFER_CONTRACT_ADDRESS || "",
bridgeAddress: process.env.LOYALTY_TRANSFER_CONTRACT_ADDRESS || "",
},
};
}
Expand All @@ -337,15 +337,13 @@ 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.bridgeMainSideAddress !== undefined)
this.sideChain.bridgeMainSideAddress = config.sideChain.bridgeMainSideAddress;
if (config.sideChain.bridgeAddress !== undefined) this.sideChain.bridgeAddress = config.sideChain.bridgeAddress;

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.bridgeMainSideAddress !== undefined)
this.mainChain.bridgeMainSideAddress = config.mainChain.bridgeMainSideAddress;
if (config.mainChain.bridgeAddress !== undefined) this.mainChain.bridgeAddress = config.mainChain.bridgeAddress;
}
}

Expand Down Expand Up @@ -471,13 +469,13 @@ export interface IContractsConfig {
currencyRateAddress: string;
loyaltyTransferAddress: string;
loyaltyBridgeAddress: string;
bridgeMainSideAddress: string;
bridgeAddress: string;
};
mainChain: {
network: string;
tokenAddress: string;
loyaltyBridgeAddress: string;
bridgeMainSideAddress: string;
bridgeAddress: 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 _sideBridgeMainSide: Bridge | undefined;
private _sideBridge: Bridge | undefined;

private _mainTokenContract: BIP20DelegatedTransfer | undefined;
private _mainLoyaltyBridgeContract: Bridge | undefined;
private _mainBridgeMainSide: Bridge | undefined;
private _mainBridge: 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._sideBridgeMainSide = factory10.attach(this.config.contracts.sideChain.bridgeMainSideAddress);
this._sideBridge = factory10.attach(this.config.contracts.sideChain.bridgeAddress);

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._mainBridgeMainSide = factory13.attach(this.config.contracts.mainChain.bridgeMainSideAddress);
this._mainBridge = factory13.attach(this.config.contracts.mainChain.bridgeAddress);

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

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

public get mainBridgeMainSide(): Bridge {
if (this._mainBridgeMainSide !== undefined) return this._mainBridgeMainSide;
public get mainBridge(): Bridge {
if (this._mainBridge !== undefined) return this._mainBridge;
else {
logger.error("mainBridgeMainSide is not ready yet.");
logger.error("mainBridge is not ready yet.");
process.exit(1);
}
}
Expand Down
Loading

0 comments on commit 8d0392c

Please sign in to comment.