Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Region AssetTransactor #100

Merged
merged 33 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
91d4c15
Region AssetTransactor
Szegoo Apr 26, 2024
bd86a62
workaround
Szegoo May 4, 2024
15903e5
Merge branch 'main' into region-asset-transactor
Szegoo May 4, 2024
fab2cc8
fix merge
Szegoo May 4, 2024
16e45eb
init tests
Szegoo May 4, 2024
171773a
progress
Szegoo May 4, 2024
48d8c48
sending xcm works | receving fails
Szegoo May 5, 2024
919f7b4
cross-chain region transfer works
Szegoo May 6, 2024
453c5da
regionx region receival test
Szegoo May 6, 2024
4f5b133
switch to typescript
Szegoo May 6, 2024
e4c4b1e
update readme
cuteolaf May 6, 2024
875cbd7
update package name
cuteolaf May 6, 2024
fab9192
remove unused file
cuteolaf May 6, 2024
7f1889e
remove unused imports
cuteolaf May 6, 2024
498a77b
cargo fmt
cuteolaf May 6, 2024
968dd74
Merge remote-tracking branch 'origin/main' into region-asset-transactor
Szegoo May 6, 2024
ae57546
move region-transfer test
Szegoo May 7, 2024
17abd97
transfering to coretime chain
Szegoo May 7, 2024
94c56ea
progress
Szegoo May 7, 2024
a6870bd
Merge branch 'main' into region-asset-transactor
Szegoo May 7, 2024
7c35a49
all good but unpaid execution?
Szegoo May 7, 2024
e8c6d92
works :)) but messy
Szegoo May 7, 2024
3fabf0b
Merge branch 'main' into region-asset-transactor
Szegoo May 8, 2024
b64963e
merge fixes
Szegoo May 8, 2024
8e0375e
fixes
Szegoo May 8, 2024
ac4ff0e
small fixes
Szegoo May 8, 2024
bcb7a34
format & refactor
cuteolaf May 8, 2024
a3b61d1
Update e2e_tests/xc-transfer/asset-transfer.ts
Szegoo May 8, 2024
65de1ac
Update e2e_tests/common.ts
Szegoo May 8, 2024
f56960b
remove file
Szegoo May 8, 2024
08330c3
trusted reserves
Szegoo May 8, 2024
94c2675
fix asset-transfer test
Szegoo May 9, 2024
258571b
small fixes
Szegoo May 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ bin/
bin/

node_modules
build/
**/package-lock.json
**/build
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
3. Get the polkadot binary:

```sh
zombienet-linux setup polkadot
zombienet-linux setup polkadot polkadot-parachain

Please add the dir to your $PATH by running the command:
export PATH=/home/<username>/RegionX-Node/:$PATH
Expand Down
45 changes: 42 additions & 3 deletions e2e_tests/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApiPromise } from "@polkadot/api";
import { ApiPromise, Keyring } from "@polkadot/api";
import { SubmittableExtrinsic, SignerOptions } from "@polkadot/api/types";
import { KeyringPair } from "@polkadot/keyring/types";

Expand Down Expand Up @@ -58,8 +58,47 @@ async function setupRelayAsset(
await submitExtrinsic(signer, sudoCall, {});
}

async function transferRelayAssetToPara(amount: bigint, paraId: number, relayApi: ApiPromise, signer: KeyringPair) {
Szegoo marked this conversation as resolved.
Show resolved Hide resolved
const receiverKeypair = new Keyring();
receiverKeypair.addFromAddress(signer.address);

const feeAssetItem = 0;
const weightLimit = "Unlimited";
const reserveTransfer = relayApi.tx.xcmPallet.limitedReserveTransferAssets(
{ V3: { parents: 0, interior: { X1: { Parachain: paraId } } } }, //dest
{
V3: {
parents: 0,
interior: {
X1: {
AccountId32: {
chain: "Any",
id: receiverKeypair.pairs[0].publicKey,
},
},
},
},
}, //beneficiary
{
V3: [
{
id: {
Concrete: { parents: 0, interior: "Here" },
},
fun: {
Fungible: amount,
},
},
],
}, //asset
feeAssetItem,
weightLimit,
);
await submitExtrinsic(signer, reserveTransfer, {});
}

async function sleep(milliseconds: number) {
return new Promise((resolve) => setTimeout(resolve, milliseconds));
return new Promise(resolve => setTimeout(resolve, milliseconds));
}

export { submitExtrinsic, setupRelayAsset, sleep, RELAY_ASSET_ID };
export { submitExtrinsic, setupRelayAsset, transferRelayAssetToPara, sleep, RELAY_ASSET_ID }
19 changes: 19 additions & 0 deletions e2e_tests/consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const UNIT = 10 ** 12; // ROC has 12 decimals

const INITIAL_PRICE = 50 * UNIT;
const CORE_COUNT = 10;
const TIMESLICE_PERIOD = 80;
const IDEAL_CORES_SOLD = 5;

const CONFIG = {
advance_notice: 20,
interlude_length: 0,
leadin_length: 10,
ideal_bulk_proportion: 0,
limit_cores_offered: 50,
region_length: 30,
renewal_bump: 10,
contribution_timeout: 5,
};

export {UNIT, INITIAL_PRICE, CORE_COUNT, TIMESLICE_PERIOD, IDEAL_CORES_SOLD, CONFIG};
1 change: 1 addition & 0 deletions e2e_tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@polkadot/api": "^11.0.2",
"@polkadot/keyring": "^12.6.2",
"coretime-utils": "^0.3.2",
"typescript": "^5.4.5"
}
}
10 changes: 10 additions & 0 deletions e2e_tests/test.js
Szegoo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { ApiPromise, WsProvider } = require("@polkadot/api");
const {Id, getEncodedRegionId, CoreMask} = require("coretime-utils");

const run = async() => {
const regionXApi = await ApiPromise.create({ provider: new WsProvider("ws://127.0.0.1:33247"), types: {Id} });

console.log(getEncodedRegionId({begin: 34, core: 0, mask: new CoreMask("0xffffffffffffffffffff")}, regionXApi).toString());
}

run();
28 changes: 14 additions & 14 deletions e2e_tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"compilerOptions": {
"module": "commonjs",
"outDir": "build",
"target": "ES2020",
"strict": true,
"esModuleInterop": true
},
"include": [
"**/*.ts"
],
"exclude": [
"node_modules"
]
}
"compilerOptions": {
"module": "commonjs",
"outDir": "build",
"target": "ES2020",
"strict": true,
"esModuleInterop": true
},
"include": [
"**/*.ts"
],
"exclude": [
"node_modules"
]
}
41 changes: 4 additions & 37 deletions e2e_tests/xc-transfer/asset-transfer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiPromise, WsProvider, Keyring } from "@polkadot/api";
import { RELAY_ASSET_ID, setupRelayAsset, sleep, submitExtrinsic } from "../common";
import { RELAY_ASSET_ID, setupRelayAsset, sleep, submitExtrinsic, transferRelayAssetToPara } from "../common";

import assert from "node:assert";

Expand Down Expand Up @@ -45,40 +45,7 @@ async function run(nodeName: string, networkInfo: any, _jsArgs: any) {
await assertRegionXBalance(alice.address, 10n ** 12n);
await assertRococoBalance(alice.address, 10n ** 18n);

const feeAssetItem = 0;
const weightLimit = "Unlimited";
const rococoReserveTransfer = rococoApi.tx.xcmPallet.limitedReserveTransferAssets(
{ V3: { parents: 0, interior: { X1: { Parachain: 2000 } } } }, //dest
{
V3: {
parents: 0,
interior: {
X1: {
AccountId32: {
chain: "Any",
id: receiverKeypair.pairs[0].publicKey,
},
},
},
},
}, //beneficiary
{
V3: [
{
id: {
Concrete: { parents: 0, interior: "Here" },
},
fun: {
Fungible: 3n * 10n ** 12n,
},
},
],
}, //asset
feeAssetItem,
weightLimit
);
await submitExtrinsic(alice, rococoReserveTransfer, {});

transferRelayAssetToPara(3n * 10n ** 12n, 2000, rococoApi, alice);
Szegoo marked this conversation as resolved.
Show resolved Hide resolved
await sleep(5 * 1000);

await assertRegionXBalance(alice.address, 4n * 10n ** 12n);
Expand Down Expand Up @@ -111,8 +78,8 @@ async function run(nodeName: string, networkInfo: any, _jsArgs: any) {
},
],
}, //asset
feeAssetItem,
weightLimit
0,
"Unlimited"
);

await submitExtrinsic(alice, regionXReserveTransfer, {});
Expand Down
Loading