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

feat: get transfer status function #309

Merged
merged 27 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
98191b6
feat: get transfer status function
wainola Nov 3, 2023
e218cf8
chore: small correction on url
wainola Nov 3, 2023
1045243
chore: jsdocs with description
wainola Nov 3, 2023
fe0c188
chore: updating function implementation, adding explorer urls as cons…
wainola Nov 4, 2023
aa97ee0
chore: update evm to evm example
wainola Nov 4, 2023
69731a9
fix: revert back on ethers version
wainola Nov 4, 2023
f05d0ac
chore: update ethers version and lock file
wainola Nov 4, 2023
99c4ba4
chore: changes on yarnrc file to deal with checksum error
wainola Nov 6, 2023
d320aa4
chore: reset checksum behaviour
wainola Nov 6, 2023
f7a85a8
chore: checksum behaviour update
wainola Nov 6, 2023
9ee9ef2
chore: remove checksum behaviour from yarnrc file
wainola Nov 6, 2023
ff94afa
chore: revert
wainola Nov 6, 2023
4623039
chore: update lock file and remove update on checksum
wainola Nov 6, 2023
4ebd33d
chore: revert removal of checksum
wainola Nov 6, 2023
934ed7c
chore: use stable yarn version on ci
wainola Nov 6, 2023
1836f8d
chore: update on checksum using stable version of yarn
wainola Nov 6, 2023
dece930
chore: test removal of node version 16
wainola Nov 6, 2023
d8c5525
chore: remove duplicated entry
wainola Nov 6, 2023
e682cd2
chore: update examples with get transfer status call
wainola Nov 7, 2023
7397513
chore: minor update to gmp example
wainola Nov 7, 2023
91913cf
chore: using testnet and not devnet for GMP
wainola Nov 7, 2023
67d1b3b
chore: rebase with main
wainola Nov 7, 2023
a9c72c2
chore: removing eslint disable comment
wainola Nov 7, 2023
5e153b2
chore: using node version 18 and 20 on workflows, and using node vers…
wainola Nov 7, 2023
d1b39a6
chore: positioning end of the script inside the interval
wainola Nov 8, 2023
b01ee11
chore: small changes for PR review
wainola Nov 13, 2023
0c643fa
Merge branch 'main' into feat/transfer-status
wainola Nov 13, 2023
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
3 changes: 2 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node: [16, 18]
node: [18, 20]
fail-fast: true
steps:
- uses: actions/checkout@v3
Expand All @@ -22,6 +22,7 @@ jobs:
cache: 'yarn' # cache node modules
node-version: ${{ matrix.node }}
- run: corepack enable
- run: yarn set version stable
- run: yarn
- run: yarn run sdk:lint # lint code
- run: yarn run sdk:build # compile typescript into javascript
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: 16
node-version: 18
registry-url: 'https://registry.npmjs.org'
scope: '@buildwithsygma'
env:
Expand Down
541 changes: 0 additions & 541 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

This file was deleted.

9 changes: 0 additions & 9 deletions .yarn/plugins/@yarnpkg/plugin-typescript.cjs

This file was deleted.

28 changes: 0 additions & 28 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

This file was deleted.

873 changes: 0 additions & 873 deletions .yarn/releases/yarn-3.4.1.cjs

This file was deleted.

893 changes: 893 additions & 0 deletions .yarn/releases/yarn-4.0.1.cjs

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ nmMode: hardlinks-local
nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: "@yarnpkg/plugin-typescript"
- path: .yarn/plugins/@yarnpkg/plugin-engines.cjs
spec: "https://raw.githubusercontent.com/devoto13/yarn-plugin-engines/main/bundles/%40yarnpkg/plugin-engines.js"

yarnPath: .yarn/releases/yarn-3.4.1.cjs
yarnPath: .yarn/releases/yarn-4.0.1.cjs

checksumBehavior: update
44 changes: 42 additions & 2 deletions examples/evm-to-evm-fungible-transfer/src/transfer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { EVMAssetTransfer, Environment } from "@buildwithsygma/sygma-sdk-core";
import {
EVMAssetTransfer,
Environment,
getTransferStatusData,
} from "@buildwithsygma/sygma-sdk-core";
import { Wallet, providers } from "ethers";
import dotenv from "dotenv";

Expand All @@ -14,12 +18,26 @@ const SEPOLIA_CHAIN_ID = 11155111;
const RESOURCE_ID =
"0x0000000000000000000000000000000000000000000000000000000000000300";

const getStatus = async (
txHash: string
): Promise<{ status: string; explorerUrl: string } | void> => {
try {
const data = await getTransferStatusData(Environment.TESTNET, txHash);

return data as { status: string; explorerUrl: string };
} catch (e) {
console.log("error", e);
console.log("indexing and retrying");
wainola marked this conversation as resolved.
Show resolved Hide resolved
}
wainola marked this conversation as resolved.
Show resolved Hide resolved
};

export async function erc20Transfer(): Promise<void> {
const provider = new providers.JsonRpcProvider(
"https://rpc.goerli.eth.gateway.fm/"
);
const wallet = new Wallet(privateKey ?? "", provider);
const assetTransfer = new EVMAssetTransfer();
// @ts-ignore-next-line
await assetTransfer.init(provider, Environment.TESTNET);

const transfer = await assetTransfer.createFungibleTransfer(
Expand All @@ -46,6 +64,28 @@ export async function erc20Transfer(): Promise<void> {
transferTx as providers.TransactionRequest
);
console.log("Sent transfer with hash: ", response.hash);

let dataResponse: undefined | { status: string; explorerUrl: string };

const id = setInterval(() => {
getStatus(response.hash)
.then((data) => {
if (data) {
dataResponse = data;
console.log("Status of the transfer", data.status);
}
})
.catch((e) => {
console.log(e);
console.log("Transfer still not indexed, retrying...");
});

if (dataResponse && dataResponse.status === "executed") {
console.log("Transfer executed successfully");
clearInterval(id);
process.exit(0);
}
}, 5000);
}

erc20Transfer().finally(() => { });
erc20Transfer().finally(() => {});
43 changes: 39 additions & 4 deletions examples/evm-to-evm-generic-mesage-passing/src/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import dotenv from "dotenv";
import {
EVMGenericMessageTransfer,
Environment,
getTransferStatusData,
} from "@buildwithsygma/sygma-sdk-core";
import { BigNumber, Wallet, providers, utils } from "ethers";
import { Storage__factory } from "./Contracts";
Expand All @@ -14,6 +15,19 @@ if (!privateKey) {
throw new Error("Missing environment variable: PRIVATE_KEY");
}

const getStatus = async (
txHash: string
): Promise<{ status: string; explorerUrl: string } | void> => {
try {
const data = await getTransferStatusData(Environment.TESTNET, txHash);

return data as { status: string; explorerUrl: string };
} catch (e) {
console.log("error", e);
console.log("indexing and retrying");
}
};

const DESTINATION_CHAIN_ID = 5; // Goerli
const RESOURCE_ID =
"0x0000000000000000000000000000000000000000000000000000000000000500"; // Generic Message Handler
Expand Down Expand Up @@ -41,11 +55,11 @@ const sleep = (ms: number): Promise<void> =>
const waitUntilBridged = async (
valueBefore: BigNumber,
intervalDuration: number = 15000,
attempts: number = 8,
attempts: number = 8
): Promise<void> => {
let i = 0;
let contractValueAfter: BigNumber;
for (; ;) {
for (;;) {
await sleep(intervalDuration);
contractValueAfter = await fetchAfterValue();
if (!contractValueAfter.eq(valueBefore)) {
Expand Down Expand Up @@ -76,7 +90,7 @@ export async function genericMessage(): Promise<void> {
).toString()}`
);
const messageTransfer = new EVMGenericMessageTransfer();
await messageTransfer.init(sourceProvider, Environment.DEVNET);
await messageTransfer.init(sourceProvider, Environment.TESTNET);

const EXECUTION_DATA = utils.defaultAbiCoder.encode(["uint"], [Date.now()]);

Expand Down Expand Up @@ -104,6 +118,27 @@ export async function genericMessage(): Promise<void> {
console.log("Waiting for relayers to bridge transaction...");

await waitUntilBridged(contractValueBefore);

let dataResponse: undefined | { status: string; explorerUrl: string };

const id = setInterval(() => {
getStatus(response.hash)
.then((data) => {
if (data) {
dataResponse = data;
console.log("Status of the transfer", data.status);
}
})
.catch(() => {
console.log("Transfer still not indexed, retrying...");
});

if (dataResponse && dataResponse.status === "executed") {
console.log("Transfer executed successfully");
clearInterval(id);
process.exit(0);
}
}, 5000);
}

genericMessage().finally(() => { });
genericMessage().finally(() => {});
42 changes: 40 additions & 2 deletions examples/evm-to-substrate-fungible-transfer/src/transfer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { EVMAssetTransfer, Environment } from "@buildwithsygma/sygma-sdk-core";
import {
EVMAssetTransfer,
Environment,
getTransferStatusData,
} from "@buildwithsygma/sygma-sdk-core";
import { Wallet, providers } from "ethers";
import dotenv from "dotenv";

Expand All @@ -14,6 +18,19 @@ const DESTINATION_ADDRESS = "5CDQJk6kxvBcjauhrogUc9B8vhbdXhRscp1tGEUmniryF1Vt";
const RESOURCE_ID =
"0x0000000000000000000000000000000000000000000000000000000000001000";

const getStatus = async (
txHash: string
): Promise<{ status: string; explorerUrl: string } | void> => {
try {
const data = await getTransferStatusData(Environment.TESTNET, txHash);

return data as { status: string; explorerUrl: string };
} catch (e) {
console.log("error", e);
console.log("indexing and retrying");
}
};

export async function erc20Transfer(): Promise<void> {
const provider = new providers.JsonRpcProvider(
"https://rpc.goerli.eth.gateway.fm/"
Expand Down Expand Up @@ -47,6 +64,27 @@ export async function erc20Transfer(): Promise<void> {
transferTx as providers.TransactionRequest
);
console.log("Sent transfer with hash: ", response.hash);

let dataResponse: undefined | { status: string; explorerUrl: string };

const id = setInterval(() => {
getStatus(response.hash)
.then((data) => {
if (data) {
dataResponse = data;
console.log(data);
}
})
.catch(() => {
console.log("Transfer still not indexed, retrying...");
});

if (dataResponse && dataResponse.status === "executed") {
console.log("Transfer executed successfully");
clearInterval(id);
process.exit(0);
}
}, 5000);
}

erc20Transfer().finally(() => { });
erc20Transfer().finally(() => {});
40 changes: 39 additions & 1 deletion examples/substrate-to-evm-fungible-transfer/src/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { Keyring } from "@polkadot/keyring";
import { ApiPromise, WsProvider } from "@polkadot/api";
import { cryptoWaitReady } from "@polkadot/util-crypto";
import dotenv from "dotenv";
import { Environment, Substrate } from "@buildwithsygma/sygma-sdk-core";
import {
Environment,
Substrate,
getTransferStatusData,
} from "@buildwithsygma/sygma-sdk-core";

dotenv.config();

Expand All @@ -18,6 +22,19 @@ if (!MNEMONIC) {
throw new Error("Missing environment variable: PRIVATE_MNEMONIC");
}

const getStatus = async (
txHash: string
): Promise<{ status: string; explorerUrl: string } | void> => {
try {
const data = await getTransferStatusData(Environment.TESTNET, txHash);

return data as { status: string; explorerUrl: string };
} catch (e) {
console.log("error", e);
console.log("indexing and retrying");
}
};

const substrateTransfer = async (): Promise<void> => {
const keyring = new Keyring({ type: "sr25519" });
// Make sure to fund this account with native tokens
Expand Down Expand Up @@ -61,6 +78,27 @@ const substrateTransfer = async (): Promise<void> => {
);
unsub();
}

let dataResponse: undefined | { status: string; explorerUrl: string };

const id = setInterval(() => {
getStatus(transferTx)
.then((data) => {
if (data) {
dataResponse = data;
console.log(data);
}
})
.catch(() => {
console.log("Transfer still not indexed, retrying...");
});
}, 5000);

if (dataResponse && dataResponse.status === "executed") {
console.log("Transfer executed successfully");
clearInterval(id);
process.exit(0);
}
});
};

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "git",
"url": "https://github.com/sygmaprotocol/sygma-sdk"
},
"packageManager": "yarn@3.4.1",
"packageManager": "yarn@4.0.1",
"engines": {
"node": ">=16.0.0"
},
Expand All @@ -35,7 +35,7 @@
},
"dependencies": {
"@changesets/cli": "^2.14.1",
"ethers": "5.4.5"
"ethers": "5.6.2"
},
"devDependencies": {
"@chainsafe/eslint-config": "^1.1.0",
Expand Down
10 changes: 10 additions & 0 deletions packages/sdk/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@ export enum ConfigUrl {
TESTNET = 'https://chainbridge-assets-stage.s3.us-east-2.amazonaws.com/shared-config-test.json',
MAINNET = 'https://sygma-assets-mainnet.s3.us-east-2.amazonaws.com/shared-config-mainnet.json',
}

export enum IndexerUrl {
MAINNET = 'https://api.buildwithsygma.com',
TESTNET = 'https://api.test.buildwithsygma.com',
}

export enum ExplorerUrl {
MAINNET = 'https://scan.buildwithsygma.com',
TESTNET = 'https://scan.test.buildwithsygma.com',
}
1 change: 1 addition & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './chains/index.js';
export * from './config.js';
export * from './constants.js';
export * from './types/index.js';
export { getTransferStatusData } from './utils.js';
7 changes: 7 additions & 0 deletions packages/sdk/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,10 @@ export type Transfer<TransferType> = {
};

export type LiquidityError = Error & { maximumTransferAmount: bigint };

export type TransferStatus = 'pending' | 'executed' | 'failed';

export type TransferStatusResponse = {
status: TransferStatus;
explorerUrl: string;
};
Loading
Loading