Skip to content

Commit

Permalink
Merge pull request #206 from interlay/feat-add-phala-intr-ibtc
Browse files Browse the repository at this point in the history
Feat: add Phala adapter for INTR and iBTC
  • Loading branch information
bvotteler authored Sep 5, 2024
2 parents 675e4a2 + a14fbf0 commit 57d6d72
Show file tree
Hide file tree
Showing 13 changed files with 385 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/xcm-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
-r scripts/configs/kusama.yml \
-p scripts/configs/kintsugi.yml \
-p scripts/configs/karura.yml \
-p scripts/configs/parallel-heiko.yml \
-p scripts/configs/bifrost.yml \
&> log.txt &
echo "Waiting for log to show chopsticks is ready..."
Expand Down Expand Up @@ -72,6 +71,7 @@ jobs:
-p scripts/configs/acala.yml \
-p scripts/configs/astar.yml \
-p scripts/configs/bifrost-polkadot.yml \
-p scripts/configs/phala.yml \
&> log.txt &
echo "Waiting for log to show chopsticks is ready..."
tail -f log.txt | grep -q "Connected parachains"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@interlay/bridge",
"version": "0.6.0",
"version": "0.6.1",
"description": "polkawallet bridge sdk",
"main": "build/index.js",
"typings": "build/index.d.ts",
Expand Down
14 changes: 9 additions & 5 deletions scripts/chopsticks-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ async function checkTransfer(fromChain: ChainName, toChain: ChainName, token: st
let feeOverestimationFactor = feeBudget.div(actualFee);
let actualFeePlancks = actualFee._getInner();
// console.log(`Fee budget: ${feeBudget}, actual fee: ${actualFee} (= ${actualFeePlancks} plank), marginFactor: ${feeOverestimationFactor}`);
if (feeOverestimationFactor.toNumber() <= 2) {
let message = `Fees need to be increased in config. The actual fees are ${actualFee} (= ${actualFeePlancks} plank). Fee overestimation factor was ${feeOverestimationFactor} - we want at least 2.0`;

// expect 2x actual fees, except for PHA to interlay where fees are very high.
const minimumFeeOverestimationFactor = (token === "PHA" && toChain === "interlay") ? 1.1 : 2;

if (feeOverestimationFactor.toNumber() < minimumFeeOverestimationFactor) {
let message = `Fees need to be increased in config. The actual fees are ${actualFee} (= ${actualFeePlancks} plank). Fee overestimation factor was ${feeOverestimationFactor} - we want at least ${minimumFeeOverestimationFactor}`;

// if below 1, this is an error.
if (feeOverestimationFactor.toNumber() < 1) {
Expand Down Expand Up @@ -171,7 +175,7 @@ async function retryCheckTransfer(
): Promise<Awaited<ReturnType<typeof checkTransfer>>> {
const result = await checkTransfer(fromChain, toChain, token, bridge);

if (result.result === ResultCode.OK) {
if (result.result !== ResultCode.FAIL) {
return result;
}

Expand Down Expand Up @@ -301,10 +305,10 @@ export async function runTestCasesAndExit(
case ResultCode.WARN:
console.log(icon, 'action required');
problematicTestStrings.forEach((logMessage) => console.log(logMessage));
process.exit(-1);
process.exit(0);
case ResultCode.FAIL:
console.log(icon, 'some channels FAILED');
problematicTestStrings.forEach((logMessage) => console.log(logMessage));
process.exit(-2);
process.exit(-1);
}
}
5 changes: 5 additions & 0 deletions scripts/configs/interlay.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ import-storage:
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice, hdx
- foreignAsset: 13
- free: '1000000000000000'
-
-
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice, pha
- foreignAsset: 14
- free: '1000000000000000'
32 changes: 32 additions & 0 deletions scripts/configs/phala.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
endpoint:
- wss://api.phala.network/ws
- wss://phala-rpc.dwellir.com
mock-signature-host: true

import-storage:
System:
Account:
-
-
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice
- providers: 1
data:
free: '100000000000000000'
-
-
- 5Eg2fntQS1bgCgPtXQ9Ysip6RUQkQJEMZqZ9u9qX6fcnhB4H # sibl 2032 (interlay sov)
- providers: 1
data:
free: '100000000000000000'
Assets:
Account:
-
-
- 14 # IBTC
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice
- balance: '1000000000000000'
-
-
- 13 # INTR
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice
- balance: '1000000000000000'
2 changes: 1 addition & 1 deletion scripts/configs/statemine.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
endpoint:
- wss://statemine-rpc.dwellir.com
- wss://asset-hub-kusama-rpc.dwellir.com
- wss://rpc-asset-hub-kusama.luckyfriday.io
- wss://statemine-rpc-tn.dwellir.com
- wss://kusama-asset-hub-rpc.polkadot.io
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/statemint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
endpoint:
- wss://statemint-rpc.dwellir.com
- wss://asset-hub-polkadot-rpc.dwellir.com
- wss://rpc-asset-hub-polkadot.luckyfriday.io
- wss://statemint-rpc-tn.dwellir.com
- wss://polkadot-asset-hub-rpc.polkadot.io
Expand Down
6 changes: 3 additions & 3 deletions scripts/interlay-chopsticks-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { InterlayAdapter } from "../src/adapters/interlay";
import { HydraAdapter } from "../src/adapters/hydradx";
import { AcalaAdapter } from "../src/adapters/acala";
import { AstarAdapter } from "../src/adapters/astar";
// import { ParallelAdapter } from "../src/adapters/parallel";
import { BifrostPolkadotAdapter } from "../src/adapters/bifrost";
import { PhalaAdapter } from "../src/adapters/phala";
import { BaseCrossChainAdapter } from "../src/base-chain-adapter";
import { RouterTestCase, runTestCasesAndExit } from "./chopsticks-test";

Expand All @@ -27,9 +27,9 @@ async function main(): Promise<void> {
hydra: { adapter: new HydraAdapter(), endpoints: ['ws://127.0.0.1:8001'] },
acala: { adapter: new AcalaAdapter(), endpoints: ['ws://127.0.0.1:8002'] },
astar: { adapter: new AstarAdapter(), endpoints: ['ws://127.0.0.1:8003'] },
// parallel: { adapter: new ParallelAdapter(), endpoints: ['ws://127.0.0.1:8004'] },
bifrost_polkadot: { adapter: new BifrostPolkadotAdapter(), endpoints: ['ws://127.0.0.1:8004']},
polkadot: { adapter: new PolkadotAdapter(), endpoints: ['ws://127.0.0.1:8005'] },
phala: { adapter: new PhalaAdapter(), endpoints: ['ws://127.0.0.1:8005']},
polkadot: { adapter: new PolkadotAdapter(), endpoints: ['ws://127.0.0.1:8006'] },
};

const skipCases: Partial<RouterTestCase>[] = [
Expand Down
8 changes: 4 additions & 4 deletions scripts/kintsugi-chopsticks-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { KaruraAdapter } from "../src/adapters/acala";
import { BifrostKusamaAdapter } from "../src/adapters/bifrost";
import { KintsugiAdapter } from "../src/adapters/interlay";
import { HeikoAdapter } from "../src/adapters/parallel";
// import { HeikoAdapter } from "../src/adapters/parallel";
import { KusamaAdapter } from "../src/adapters/polkadot";
import { BaseCrossChainAdapter } from "../src/base-chain-adapter";
import { RouterTestCase, runTestCasesAndExit } from "./chopsticks-test";
Expand All @@ -23,9 +23,9 @@ async function main(): Promise<void> {
// relaychain gets its port last after all parachains.
kintsugi: { adapter: new KintsugiAdapter(), endpoints: ['ws://127.0.0.1:8000'] },
karura: { adapter: new KaruraAdapter(), endpoints: ['ws://127.0.0.1:8001'] },
heiko: { adapter: new HeikoAdapter(), endpoints: ['ws://127.0.0.1:8002'] },
bifrost: { adapter: new BifrostKusamaAdapter(), endpoints: ['ws://127.0.0.1:8003'] },
kusama: { adapter: new KusamaAdapter(), endpoints: ['ws://127.0.0.1:8004'] },
// heiko: { adapter: new HeikoAdapter(), endpoints: ['ws://127.0.0.1:8002'] },
bifrost: { adapter: new BifrostKusamaAdapter(), endpoints: ['ws://127.0.0.1:8002'] },
kusama: { adapter: new KusamaAdapter(), endpoints: ['ws://127.0.0.1:8003'] },
};

const skipCases: Partial<RouterTestCase>[] = [
Expand Down
29 changes: 29 additions & 0 deletions src/adapters/interlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,33 @@ export const interlayRoutersConfig: Omit<CrossChainRouterConfigs, "from">[] = [
// during chopsticks test: fee = 103 Add 10x margin
xcm: { fee: { token: "IBTC", amount: "1030" }, weightLimit: DEST_WEIGHT },
},
{
to: "phala",
token: "PHA",
xcm: {
// chopsticks test data: 64_296_000_000, use ~2.5x buffer
fee: { token: "PHA", amount: "150000000000" },
weightLimit: DEST_WEIGHT,
},
},
{
to: "phala",
token: "INTR",
xcm: {
// chopsticks test data: fee = 642_960_000, use ~10x buffer
fee: { token: "INTR", amount: "6400000000" },
weightLimit: DEST_WEIGHT,
},
},
{
to: "phala",
token: "IBTC",
xcm: {
// chopsticks test: fee = 6429600. Use ~3x buffer
fee: { token: "IBTC", amount: "20000000" },
weightLimit: DEST_WEIGHT,
},
},
{
to: "polkadot",
token: "DOT",
Expand Down Expand Up @@ -232,6 +259,7 @@ export const interlayTokensConfig: Record<
VDOT: { name: "VDOT", symbol: "VDOT", decimals: 10, ed: "0" },
BNC: { name: "BNC", symbol: "BNC", decimals: 12, ed: "0" },
HDX: { name: "HDX", symbol: "HDX", decimals: 12, ed: "0" },
PHA: { name: "PHA", symbol: "PHA", decimals: 12, ed: "10000000000" },
},
kintsugi: {
KBTC: { name: "KBTC", symbol: "KBTC", decimals: 8, ed: "0" },
Expand Down Expand Up @@ -261,6 +289,7 @@ const INTERLAY_SUPPORTED_TOKENS: Record<string, unknown> = {
BNC: { ForeignAsset: 11 },
USDC: { ForeignAsset: 12 },
HDX: { ForeignAsset: 13 },
PHA: { ForeignAsset: 14 },
};

const getSupportedTokens = (chainname: string): Record<string, unknown> => {
Expand Down
Loading

0 comments on commit 57d6d72

Please sign in to comment.