├── .cspell.json ├── .czrc ├── .editorconfig ├── .firebaserc ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── config.yml │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── allbridge-core-sdk.yml │ ├── firebase-hosting-merge.yml │ └── firebase-hosting-pull-request.yml ├── .gitignore ├── .npmignore ├── .prettierrc.json ├── .releaserc.json ├── .vscode ├── extensions.json ├── launch.json └── settings.json ├── README.md ├── docs └── 404.html ├── documentation ├── README.md ├── browser │ ├── evm.md │ ├── solana.md │ ├── stellar.md │ └── tron.md ├── core-sdk-configure.md └── core-sdk-install.md ├── esbuild-hook.js ├── eslint.config.mjs ├── examples ├── .env.example ├── .eslintrc.js ├── .gitignore ├── package.json ├── pnpm-lock.yaml ├── src │ ├── examples │ │ ├── bridge │ │ │ ├── calculate-amounts.ts │ │ │ ├── evm │ │ │ │ ├── evm-build-send-tx-gas-fee-with-stables.ts │ │ │ │ ├── evm-build-send-tx.ts │ │ │ │ └── evm-build-swap-tx.ts │ │ │ ├── get-average-transfer-time.ts │ │ │ ├── get-extra-gas-max-limits.ts │ │ │ ├── get-transfer-status.ts │ │ │ ├── send-by-cctp.ts │ │ │ ├── solana │ │ │ │ ├── sol-build-send-tx.ts │ │ │ │ └── sol-build-swap-tx.ts │ │ │ ├── srb │ │ │ │ └── srb-send-full-example.ts │ │ │ ├── sui │ │ │ │ ├── sui-build-send-tx.ts │ │ │ │ └── sui-build-swap-tx.ts │ │ │ └── trx │ │ │ │ ├── trx-build-send-tx-gas-fee-with-stables.ts │ │ │ │ ├── trx-build-send-tx.ts │ │ │ │ └── trx-build-swap-tx.ts │ │ ├── general │ │ │ ├── evm │ │ │ │ ├── evm-approve-tokens.ts │ │ │ │ └── evm-get-token-balance.ts │ │ │ ├── solana │ │ │ │ └── sol-get-token-balance.ts │ │ │ └── sui │ │ │ │ └── sui-get-token-balance.ts │ │ ├── get-tokens-info.ts │ │ └── liquidity-pool │ │ │ ├── evm │ │ │ ├── evm-build-claim-rewards-tx.ts │ │ │ ├── evm-build-deposit-tx.ts │ │ │ ├── evm-build-withdraw-tx.ts │ │ │ ├── get-amount-to-be-withdrawn.ts │ │ │ ├── get-liquidity-balance.ts │ │ │ └── get-lp-amount-on-deposit.ts │ │ │ ├── solana │ │ │ ├── get-amount-to-be-withdrawn.ts │ │ │ ├── get-liquidity-balance.ts │ │ │ ├── get-lp-amount-on-deposit.ts │ │ │ ├── sol-build-claim-rewards-tx.ts │ │ │ ├── sol-build-deposit-tx.ts │ │ │ └── sol-build-withdraw-tx.ts │ │ │ ├── sui │ │ │ ├── get-amount-to-be-withdrawn.ts │ │ │ ├── get-liquidity-balance.ts │ │ │ ├── get-lp-amount-on-deposit.ts │ │ │ ├── sui-build-claim-rewards-tx.ts │ │ │ ├── sui-build-deposit-tx.ts │ │ │ └── sui-build-withdraw-tx.ts │ │ │ └── trx │ │ │ ├── get-amount-to-be-withdrawn.ts │ │ │ ├── get-liquidity-balance.ts │ │ │ ├── get-lp-amount-on-deposit.ts │ │ │ ├── trx-build-claim-rewards-tx.ts │ │ │ ├── trx-build-deposit-tx.ts │ │ │ └── trx-build-withdraw-tx.ts │ └── utils │ │ ├── env.ts │ │ ├── sui.ts │ │ ├── tronWeb.ts │ │ ├── utils.ts │ │ └── web3.ts └── tsconfig.json ├── firebase.json ├── package.json ├── pnpm-lock.yaml ├── scripts ├── build.ts └── clean.ts ├── src ├── __tests__ │ ├── client │ │ └── core-api │ │ │ ├── caching-core-client.test.ts │ │ │ ├── core-api-mapper.test.ts │ │ │ └── index.test.ts │ ├── data │ │ ├── pool-info │ │ │ ├── pool-info-GRL.json │ │ │ └── pool-info-map.json │ │ ├── tokens-info │ │ │ ├── ChainDetails-GRL.json │ │ │ ├── ChainDetailsMap-ETH-USDT.json │ │ │ ├── ChainDetailsMap.json │ │ │ ├── ChainDetailsMapWithFlags.json │ │ │ ├── TokenInfoWithChainDetails-GRL.json │ │ │ ├── TokenInfoWithChainDetails-SOL.json │ │ │ ├── TokenInfoWithChainDetails-TRX.json │ │ │ └── TokenInfoWithChainDetails.json │ │ └── transfer-status │ │ │ └── TransferStatus.json │ ├── index.test.ts │ ├── mock │ │ ├── bridge │ │ │ ├── evm │ │ │ │ └── evm-bridge.ts │ │ │ ├── index.ts │ │ │ ├── models │ │ │ │ └── bridge.ts │ │ │ ├── trx │ │ │ │ └── trx-bridge.ts │ │ │ └── utils.ts │ │ ├── core-api │ │ │ ├── pool-info.json │ │ │ ├── send-status.json │ │ │ └── token-info.json │ │ ├── polygon-api │ │ │ └── polygon-api.json │ │ ├── token │ │ │ ├── evm │ │ │ │ └── evm-token.ts │ │ │ ├── index.ts │ │ │ └── trx │ │ │ │ └── trx-token.ts │ │ ├── tron-web │ │ │ ├── trigger-smart-contract-approve.json │ │ │ ├── trigger-smart-contract-claim-rewards.json │ │ │ ├── trigger-smart-contract-deposit.json │ │ │ ├── trigger-smart-contract-send.json │ │ │ └── trigger-smart-contract-withdraw.json │ │ └── utils.ts │ ├── services │ │ ├── bridge │ │ │ ├── evm │ │ │ │ └── index.test.ts │ │ │ ├── raw-bridge-transaction-builder.test.ts │ │ │ ├── trx │ │ │ │ └── index.test.ts │ │ │ └── utils.test.ts │ │ └── liquidity-pool │ │ │ ├── evm │ │ │ └── index.test.ts │ │ │ ├── raw-pool-transaction-builder.test.ts │ │ │ ├── sol │ │ │ ├── data │ │ │ │ ├── expected.ts │ │ │ │ └── nock │ │ │ │ │ ├── claim-rewards-rec.json │ │ │ │ │ ├── deposit-rec.json │ │ │ │ │ ├── user-balance-info-rec.json │ │ │ │ │ └── withdraw-rec.json │ │ │ └── index.test.ts │ │ │ └── trx │ │ │ ├── data │ │ │ └── nock │ │ │ │ └── user-balance-info-rec.json │ │ │ └── index.test.ts │ ├── tokens-info │ │ └── index.test.ts │ └── utils │ │ └── calculation │ │ └── index.test.ts ├── chains │ ├── chain.enums.ts │ ├── index.ts │ └── models.ts ├── client │ └── core-api │ │ ├── api-client-caching.ts │ │ ├── api-client.ts │ │ ├── core-api-mapper.ts │ │ ├── core-api.model.ts │ │ ├── core-client-base.ts │ │ ├── core-client-filtered.ts │ │ └── core-client-pool-info-caching.ts ├── configs │ ├── index.ts │ └── mainnet.ts ├── exceptions │ ├── exceptions.ts │ └── index.ts ├── index.ts ├── models │ └── index.ts ├── services │ ├── bridge │ │ ├── evm │ │ │ └── index.ts │ │ ├── get-cctp-sol-token-recipient-address.ts │ │ ├── index.ts │ │ ├── models │ │ │ ├── bridge.model.ts │ │ │ ├── bridge.ts │ │ │ └── index.ts │ │ ├── raw-bridge-transaction-builder.ts │ │ ├── sol │ │ │ ├── index.ts │ │ │ └── jupiter.ts │ │ ├── srb │ │ │ └── index.ts │ │ ├── sui │ │ │ └── index.ts │ │ ├── trx │ │ │ └── index.ts │ │ └── utils.ts │ ├── index.ts │ ├── liquidity-pool │ │ ├── evm │ │ │ └── index.ts │ │ ├── index.ts │ │ ├── models │ │ │ ├── index.ts │ │ │ ├── pool.model.ts │ │ │ └── pool.ts │ │ ├── raw-pool-transaction-builder.ts │ │ ├── sol │ │ │ └── index.ts │ │ ├── srb │ │ │ └── index.ts │ │ ├── sui │ │ │ └── index.ts │ │ └── trx │ │ │ └── index.ts │ ├── models │ │ ├── abi │ │ │ ├── Bridge.ts │ │ │ ├── CctpBridge.ts │ │ │ ├── ERC20.ts │ │ │ └── Pool.ts │ │ ├── index.ts │ │ ├── sol │ │ │ ├── index.ts │ │ │ └── types │ │ │ │ ├── bridge.ts │ │ │ │ ├── cctp_bridge.ts │ │ │ │ └── gas_oracle.ts │ │ ├── srb │ │ │ ├── bridge-contract.ts │ │ │ ├── gas-oracle-contract.ts │ │ │ ├── messenger-contract.ts │ │ │ ├── pool-contract.ts │ │ │ ├── token-contract.ts │ │ │ └── utils.ts │ │ └── sui │ │ │ ├── .eslintrc.json │ │ │ ├── _dependencies │ │ │ └── source │ │ │ │ ├── 0x1 │ │ │ │ ├── ascii │ │ │ │ │ └── structs.ts │ │ │ │ ├── bit-vector │ │ │ │ │ └── structs.ts │ │ │ │ ├── fixed-point32 │ │ │ │ │ └── structs.ts │ │ │ │ ├── index.ts │ │ │ │ ├── init.ts │ │ │ │ ├── option │ │ │ │ │ └── structs.ts │ │ │ │ ├── string │ │ │ │ │ └── structs.ts │ │ │ │ ├── type-name │ │ │ │ │ └── structs.ts │ │ │ │ ├── uq32-32 │ │ │ │ │ └── structs.ts │ │ │ │ └── uq64-64 │ │ │ │ │ └── structs.ts │ │ │ │ ├── 0x31cc14d80c175ae39777c0238f20594c6d4869cfab199f40b69f3319956b8beb │ │ │ │ ├── burn-message │ │ │ │ │ └── structs.ts │ │ │ │ ├── deposit-for-burn │ │ │ │ │ └── structs.ts │ │ │ │ ├── handle-receive-message │ │ │ │ │ └── structs.ts │ │ │ │ ├── index.ts │ │ │ │ ├── init.ts │ │ │ │ ├── message-transmitter-authenticator │ │ │ │ │ └── structs.ts │ │ │ │ └── state │ │ │ │ │ └── structs.ts │ │ │ │ ├── 0x346e3233f61eb0055713417bfaddda7dc3bf26816faad1f7606994a368b92917 │ │ │ │ ├── index.ts │ │ │ │ ├── init.ts │ │ │ │ ├── mint-allowance │ │ │ │ │ └── structs.ts │ │ │ │ └── treasury │ │ │ │ │ └── structs.ts │ │ │ │ ├── 0x4931e06dce648b3931f890035bd196920770e913e43e45990b383f6486fdd0a5 │ │ │ │ ├── index.ts │ │ │ │ ├── init.ts │ │ │ │ ├── message │ │ │ │ │ └── structs.ts │ │ │ │ ├── receive-message │ │ │ │ │ └── structs.ts │ │ │ │ └── state │ │ │ │ │ └── structs.ts │ │ │ │ └── 0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94 │ │ │ │ ├── bytes20 │ │ │ │ └── structs.ts │ │ │ │ ├── bytes32 │ │ │ │ └── structs.ts │ │ │ │ ├── consumed-vaas │ │ │ │ └── structs.ts │ │ │ │ ├── cursor │ │ │ │ └── structs.ts │ │ │ │ ├── emitter │ │ │ │ └── structs.ts │ │ │ │ ├── external-address │ │ │ │ └── structs.ts │ │ │ │ ├── fee-collector │ │ │ │ └── structs.ts │ │ │ │ ├── guardian-set │ │ │ │ └── structs.ts │ │ │ │ ├── guardian │ │ │ │ └── structs.ts │ │ │ │ ├── index.ts │ │ │ │ ├── init.ts │ │ │ │ ├── publish-message │ │ │ │ └── structs.ts │ │ │ │ ├── set │ │ │ │ └── structs.ts │ │ │ │ ├── state │ │ │ │ └── structs.ts │ │ │ │ └── vaa │ │ │ │ └── structs.ts │ │ │ ├── _framework │ │ │ ├── init-loader.ts │ │ │ ├── loader.ts │ │ │ ├── reified.ts │ │ │ ├── util.ts │ │ │ └── vector.ts │ │ │ ├── bridge │ │ │ ├── another-bridge │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── bridge-interface │ │ │ │ └── functions.ts │ │ │ ├── bridge │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── events │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── index.ts │ │ │ ├── init.ts │ │ │ ├── pool-rewards │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── pool-state │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── pool │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ └── user-deposit │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── cctp-bridge │ │ │ ├── cctp-bridge-interface │ │ │ │ └── functions.ts │ │ │ ├── cctp-bridge │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── events │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── index.ts │ │ │ ├── init.ts │ │ │ └── message-transmitter-authenticator │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── gas-oracle │ │ │ ├── gas-oracle-interface │ │ │ │ └── functions.ts │ │ │ ├── gas-oracle │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── index.ts │ │ │ └── init.ts │ │ │ ├── messenger │ │ │ ├── events │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── index.ts │ │ │ ├── init.ts │ │ │ ├── messenger-interface │ │ │ │ └── functions.ts │ │ │ └── messenger │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── sui │ │ │ ├── address │ │ │ │ └── functions.ts │ │ │ ├── authenticator-state │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── bag │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── balance │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── bcs │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── bls12381 │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── borrow │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── clock │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── coin │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── config │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── deny-list │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── display │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── dynamic-field │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── dynamic-object-field │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── ecdsa-k1 │ │ │ │ └── functions.ts │ │ │ ├── ecdsa-r1 │ │ │ │ └── functions.ts │ │ │ ├── ecvrf │ │ │ │ └── functions.ts │ │ │ ├── ed25519 │ │ │ │ └── functions.ts │ │ │ ├── event │ │ │ │ └── functions.ts │ │ │ ├── groth16 │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── group-ops │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── hash │ │ │ │ └── functions.ts │ │ │ ├── hex │ │ │ │ └── functions.ts │ │ │ ├── hmac │ │ │ │ └── functions.ts │ │ │ ├── index.ts │ │ │ ├── init.ts │ │ │ ├── kiosk-extension │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── kiosk │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── linked-table │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── math │ │ │ │ └── functions.ts │ │ │ ├── object-bag │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── object-table │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── object │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── package │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── pay │ │ │ │ └── functions.ts │ │ │ ├── poseidon │ │ │ │ └── functions.ts │ │ │ ├── priority-queue │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── random │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── sui │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── table-vec │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── table │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── token │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── transfer-policy │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── transfer │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── tx-context │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── types │ │ │ │ └── functions.ts │ │ │ ├── url │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── vdf │ │ │ │ └── functions.ts │ │ │ ├── vec-map │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── vec-set │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── versioned │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── zklogin-verified-id │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ └── zklogin-verified-issuer │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── utils │ │ │ ├── bytes32 │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── fee-collector │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── index.ts │ │ │ ├── init.ts │ │ │ ├── message │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── messenger-protocol │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ ├── set │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ └── version │ │ │ │ ├── functions.ts │ │ │ │ └── structs.ts │ │ │ └── wormhole-messenger │ │ │ ├── events │ │ │ ├── functions.ts │ │ │ └── structs.ts │ │ │ ├── index.ts │ │ │ ├── init.ts │ │ │ ├── wh-messenger-interface │ │ │ └── functions.ts │ │ │ └── wormhole-messenger │ │ │ ├── functions.ts │ │ │ └── structs.ts │ ├── token │ │ ├── evm │ │ │ └── index.ts │ │ ├── index.ts │ │ ├── models │ │ │ ├── index.ts │ │ │ ├── token.model.ts │ │ │ └── token.ts │ │ ├── sol │ │ │ └── index.ts │ │ ├── srb │ │ │ └── index.ts │ │ ├── sui │ │ │ └── index.ts │ │ └── trx │ │ │ └── index.ts │ └── utils │ │ ├── calculation │ │ └── index.ts │ │ ├── index.ts │ │ ├── sol │ │ ├── accounts.ts │ │ ├── anchor-provider.ts │ │ ├── compute-budget.ts │ │ └── index.ts │ │ ├── sui │ │ ├── coins.ts │ │ ├── paginated.ts │ │ └── view.ts │ │ └── trx │ │ └── index.ts ├── tokens-info │ ├── index.ts │ └── tokens-info.model.ts ├── utils │ ├── calculation │ │ ├── constants.ts │ │ ├── index.ts │ │ ├── swap-and-bridge-details.ts │ │ └── swap-and-bridge-fee-calc.ts │ ├── index.ts │ ├── sol │ │ ├── index.ts │ │ └── utils.ts │ ├── srb │ │ └── index.ts │ └── utils.ts └── version.ts ├── tsconfig.json └── tsconfig.lint.json /.cspell.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1", 3 | "language": "en", 4 | "words": [ 5 | "degit", 6 | "esbuild", 7 | "octocat", 8 | "rmrf", 9 | "Yhax", 10 | "shrn", 11 | "socio", 12 | "allbridge", 13 | "Solana", 14 | "solana", 15 | "Promi", 16 | "tronweb", 17 | "certusone", 18 | "Keypair", 19 | "vusd", 20 | "Vusd", 21 | "SYSVAR", 22 | "keccak", 23 | "Gwei", 24 | "stablecoins", 25 | "Sepolia", 26 | "Rebalancer", 27 | "rebalancer", 28 | "blockhash", 29 | "Blockhash", 30 | "Lamports", 31 | "lamports", 32 | "Seegxrqiu", 33 | "Arbitrum", 34 | "decompile", 35 | "txid", 36 | "CCTP", 37 | "cctp", 38 | "Soroban", 39 | "Holešky", 40 | "STLR", 41 | "alphanum", 42 | "retval", 43 | "typeahead", 44 | "Timepoint", 45 | "Typepoint", 46 | "futurenet", 47 | "Vals", 48 | "Amoy", 49 | "Celo", 50 | "crossrate", 51 | "mysten" 52 | ], 53 | "flagWords": [], 54 | "ignorePaths": [ 55 | "package.json", 56 | "package-lock.json", 57 | "yarn.lock", 58 | "tsconfig.json", 59 | "node_modules/**", 60 | "src/configs/", 61 | "src/__tests__/services/liquidity-pool/sol/data/", 62 | "src/services/models/abi/", 63 | "src/services/models/srb/", 64 | "src/services/models/sui/", 65 | "src/services/utils/srb/assembled-tx.ts" 66 | ] 67 | } 68 | -------------------------------------------------------------------------------- /.czrc: -------------------------------------------------------------------------------- 1 | { 2 | "path": "./node_modules/@ryansonshine/cz-conventional-changelog" 3 | } 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | # trim_trailing_whitespace = true 10 | # max_line_length = off 11 | max_line_length = 120 12 | 13 | -------------------------------------------------------------------------------- /.firebaserc: -------------------------------------------------------------------------------- 1 | { 2 | "projects": { 3 | "default": "bridge-core-sdk" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "" 5 | labels: "" 6 | assignees: "" 7 | --- 8 | 9 | **Describe the bug** 10 | A clear and concise description of what the bug is. 11 | 12 | **To Reproduce** 13 | Steps to reproduce the behavior: 14 | 15 | 1. 16 | 2. 17 | 3. 18 | 19 | **Expected behavior** 20 | A clear and concise description of what you expected to happen. 21 | 22 | **Screenshots** 23 | If applicable, add screenshots to help explain your problem. 24 | 25 | **Desktop (please complete the following information):** 26 | 27 | - OS: [e.g. Ubuntu 22.04, macOS 11.4] 28 | - Node version [e.g 16.4.2] 29 | - Code Version [e.g. 1.1.0] 30 | 31 | **Additional context** 32 | Add any other context about the problem here. 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: GitHub Discussions 4 | url: https://github.com/allbridge-io/allbridge-core-js-sdk/discussions 5 | about: Please discuss non bug-related topics there 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "" 5 | labels: "" 6 | assignees: "" 7 | --- 8 | 9 | **Is your feature request related to a problem? Please describe.** 10 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 11 | 12 | **Describe the solution you'd like** 13 | A clear and concise description of what you want to happen. 14 | 15 | **Describe alternatives you've considered** 16 | A clear and concise description of any alternative solutions or features you've considered. 17 | 18 | **Additional context** 19 | Add any other context or screenshots about the feature request here. 20 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Fixes # 2 | 3 | ## Description of the changes 4 | 5 | - 6 | - 7 | - 8 | -------------------------------------------------------------------------------- /.github/workflows/allbridge-core-sdk.yml: -------------------------------------------------------------------------------- 1 | name: allbridge-core-sdk 2 | 3 | on: [push] 4 | 5 | env: 6 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 7 | 8 | jobs: 9 | allbridge-core-sdk: 10 | runs-on: ubuntu-latest 11 | 12 | concurrency: 13 | group: ${{ github.ref }} 14 | cancel-in-progress: true 15 | 16 | steps: 17 | - uses: actions/checkout@v4 18 | - uses: volta-cli/action@v4 19 | - name: Install Node.js 20 | uses: actions/setup-node@v4 21 | with: 22 | node-version: 20 23 | 24 | - uses: pnpm/action-setup@v4 25 | name: Install pnpm 26 | id: pnpm-install 27 | with: 28 | run_install: false 29 | 30 | - name: Get pnpm store directory 31 | id: pnpm-cache 32 | run: | 33 | echo "::set-output name=pnpm_cache_dir::$(pnpm store path)" 34 | 35 | - uses: actions/cache@v4 36 | name: Setup pnpm cache 37 | with: 38 | path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} 39 | key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} 40 | restore-keys: | 41 | ${{ runner.os }}-pnpm-store- 42 | 43 | - name: Install dependencies 44 | run: pnpm install 45 | 46 | # - name: Dependencies audit 47 | # run: pnpm audit 48 | 49 | - name: Build 50 | run: pnpm run build 51 | 52 | - name: Format check 53 | run: pnpm run format:check 54 | 55 | - name: Lint check 56 | run: pnpm run lint:check 57 | 58 | - name: Spell check 59 | run: pnpm run spell:check 60 | 61 | - name: Test 62 | run: pnpm run test 63 | 64 | - name: Docs 65 | run: pnpm run tsdoc 66 | 67 | - name: Release 68 | env: 69 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 70 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 71 | run: pnpm run semantic-release 72 | -------------------------------------------------------------------------------- /.github/workflows/firebase-hosting-merge.yml: -------------------------------------------------------------------------------- 1 | # This file was auto-generated by the Firebase CLI 2 | # https://github.com/firebase/firebase-tools 3 | 4 | name: Deploy to Firebase Hosting on merge 5 | 'on': 6 | push: 7 | branches: 8 | - main 9 | jobs: 10 | build_and_deploy: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v4 14 | - uses: volta-cli/action@v4 15 | - name: Install Node.js 16 | uses: actions/setup-node@v4 17 | with: 18 | node-version: 20 19 | 20 | - uses: pnpm/action-setup@v4 21 | name: Install pnpm 22 | id: pnpm-install 23 | with: 24 | run_install: false 25 | 26 | - name: Get pnpm store directory 27 | id: pnpm-cache 28 | run: | 29 | echo "::set-output name=pnpm_cache_dir::$(pnpm store path)" 30 | 31 | - uses: actions/cache@v4 32 | name: Setup pnpm cache 33 | with: 34 | path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} 35 | key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} 36 | restore-keys: | 37 | ${{ runner.os }}-pnpm-store- 38 | 39 | - name: Install dependencies 40 | run: pnpm install 41 | 42 | - run: pnpm tsdoc 43 | - uses: FirebaseExtended/action-hosting-deploy@v0 44 | with: 45 | repoToken: '${{ secrets.GITHUB_TOKEN }}' 46 | firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_BRIDGE_CORE_SDK }}' 47 | channelId: live 48 | projectId: bridge-core-sdk 49 | -------------------------------------------------------------------------------- /.github/workflows/firebase-hosting-pull-request.yml: -------------------------------------------------------------------------------- 1 | # This file was auto-generated by the Firebase CLI 2 | # https://github.com/firebase/firebase-tools 3 | 4 | name: Deploy to Firebase Hosting on PR 5 | 'on': pull_request 6 | jobs: 7 | build_and_preview: 8 | if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}' 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v4 12 | - uses: volta-cli/action@v4 13 | - name: Install Node.js 14 | uses: actions/setup-node@v4 15 | with: 16 | node-version: 20 17 | 18 | - uses: pnpm/action-setup@v4 19 | name: Install pnpm 20 | id: pnpm-install 21 | with: 22 | run_install: false 23 | 24 | - name: Get pnpm store directory 25 | id: pnpm-cache 26 | run: | 27 | echo "::set-output name=pnpm_cache_dir::$(pnpm store path)" 28 | 29 | - uses: actions/cache@v4 30 | name: Setup pnpm cache 31 | with: 32 | path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} 33 | key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} 34 | restore-keys: | 35 | ${{ runner.os }}-pnpm-store- 36 | 37 | - name: Install dependencies 38 | run: pnpm install 39 | 40 | - run: pnpm tsdoc 41 | - uses: FirebaseExtended/action-hosting-deploy@v0 42 | with: 43 | repoToken: '${{ secrets.GITHUB_TOKEN }}' 44 | firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_BRIDGE_CORE_SDK }}' 45 | projectId: bridge-core-sdk 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | examples/build/ 3 | node_modules/ 4 | .nyc_output/ 5 | coverage/ 6 | .DS_Store 7 | .idea 8 | **/*.iml 9 | .env 10 | docs/* 11 | !docs/404.html 12 | /out/ 13 | .firebase 14 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .github/ 2 | .vscode/ 3 | examples/ 4 | scripts/ 5 | .cspell.json 6 | .czrc 7 | .editorconfig 8 | .eslintrc.json 9 | .releaserc.json 10 | CHANGELOG.md 11 | esbuild-hook.js 12 | tsconfig.json 13 | tsconfig.lint.json 14 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma" : "es5" 3 | } -------------------------------------------------------------------------------- /.releaserc.json: -------------------------------------------------------------------------------- 1 | { 2 | "branches": [ 3 | "+([0-9])?(.{+([0-9]),x}).x", 4 | "main", 5 | "master", 6 | "next", 7 | "next-major", 8 | { 9 | "name": "beta", 10 | "prerelease": true 11 | }, 12 | { 13 | "name": "alpha", 14 | "prerelease": true 15 | } 16 | ], 17 | "repositoryUrl": "https://github.com/allbridge-io/allbridge-core-js-sdk.git", 18 | "plugins": [ 19 | "@semantic-release/commit-analyzer", 20 | "@semantic-release/release-notes-generator", 21 | "@semantic-release/changelog", 22 | "@semantic-release/npm", 23 | "@semantic-release/github" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "dbaeumer.vscode-eslint", 4 | "esbenp.prettier-vscode", 5 | "eamodio.gitlens", 6 | "streetsidesoftware.code-spell-checker" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 3 | "version": "0.2.0", 4 | "configurations": [ 5 | { 6 | "type": "pwa-node", 7 | "request": "launch", 8 | "name": "Debug Current Test File", 9 | "autoAttachChildProcesses": true, 10 | "skipFiles": ["/**", "**/node_modules/**"], 11 | "program": "${workspaceRoot}/node_modules/vitest/vitest.mjs", 12 | "args": ["run", "${relativeFile}"], 13 | "smartStep": true, 14 | "console": "integratedTerminal" 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | // only use words from .cspell.json 3 | "cSpell.userWords": [], 4 | "cSpell.enabled": true, 5 | "editor.formatOnSave": true, 6 | "typescript.tsdk": "node_modules/typescript/lib", 7 | "typescript.enablePromptUseWorkspaceTsdk": true 8 | } 9 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Page Not Found 7 | 8 | 23 | 24 | 25 |
26 |

404

27 |

Page Not Found

28 |

The specified file was not found on this website. Please check the URL for mistakes and try again.

29 |

Why am I seeing this?

30 |

This page was generated by the Firebase Command-Line Interface. To modify it, edit the 404.html file in your project's configured public directory.

31 |
32 | 33 | 34 | -------------------------------------------------------------------------------- /documentation/README.md: -------------------------------------------------------------------------------- 1 | # Allbridge Core SDK 2 | 3 | ## Setup 4 | 5 | ### 1. [Install Allbridge Core SDK](core-sdk-install.md) 6 | 7 | ### 2. [Configure SDK instance](core-sdk-configure.md) 8 | 9 | 10 | -------------------------------------------------------------------------------- /documentation/browser/solana.md: -------------------------------------------------------------------------------- 1 | 2 | # Integrating Allbridge Core SDK and Browser Extension Wallet with TypeScript 3 | 4 | ## Introduction 5 | This documentation provides a step-by-step guide on integrating the Allbridge Core SDK and a browser extension wallet (Phantom Wallet) using TypeScript in a web project. 6 | 7 | ## Prerequisites 8 | - TypeScript 9 | - Node.js 10 | - npm or yarn 11 | - Allbridge Core SDK package installed ([`@allbridge/bridge-core-sdk`](https://www.npmjs.com/package/@allbridge/bridge-core-sdk)) 12 | - Web3.js library (`@solana/web3.js`) 13 | - Phantom Wallet extension installed in the browser. [Docs](https://docs.phantom.app/) 14 | 15 | ## Installation 16 | First, install the necessary packages: 17 | 18 | ```bash 19 | npm install @allbridge/bridge-core-sdk @solana/web3.js 20 | ``` 21 | 22 | ## Step-by-Step Integration 23 | 24 | ### Step 1: Import Necessary Modules 25 | 26 | Import the required modules and initialize the Allbridge Core SDK: 27 | 28 | ```typescript 29 | import { 30 | AllbridgeCoreSdk, 31 | ChainSymbol, 32 | NodeRpcUrls, 33 | SendParams, 34 | } from '@allbridge/bridge-core-sdk'; 35 | import { VersionedTransaction } from '@solana/web3.js'; 36 | ``` 37 | 38 | ### Step 2: Define Node URLs and initialize SDK 39 | 40 | Set up the node URLs for the different chains and initialize the Allbridge Core SDK. 41 | 42 | ```typescript 43 | const SDK_NODE_URLS: NodeRpcUrls = { 44 | [ChainSymbol.SOL]: 'https://rpc.ankr.com/solana', 45 | }; 46 | const sdk = new AllbridgeCoreSdk(SDK_NODE_URLS); 47 | ``` 48 | 49 | ### Step 3: Create, sign and send Allbridge raw transaction: 50 | 51 | ```typescript 52 | const rawTransaction = (await sdk.bridge.rawTxBuilder.send(params)) as VersionedTransaction; 53 | const { signature } = await window.solana.signAndSendTransaction(rawTransaction); 54 | console.log('txId', signature); 55 | ``` 56 | 57 | ## Conclusion 58 | 59 | With this guide, you have set up the Allbridge Core SDK and Phantom wallet integration on your web application using TypeScript. You can now securely send transactions and check their status on the Solana blockchain. For further customization and advanced usage, refer to the official documentation of the respective SDKs. 60 | -------------------------------------------------------------------------------- /documentation/browser/tron.md: -------------------------------------------------------------------------------- 1 | 2 | # Integrating Allbridge Core SDK and Browser Extension Wallet with TypeScript 3 | 4 | ## Introduction 5 | This documentation provides a step-by-step guide on integrating the Allbridge Core SDK and a browser extension wallet (TronLink) using TypeScript in a web project. 6 | 7 | ## Prerequisites 8 | - TypeScript 9 | - Node.js 10 | - npm or yarn 11 | - Allbridge Core SDK package installed ([`@allbridge/bridge-core-sdk`](https://www.npmjs.com/package/@allbridge/bridge-core-sdk)) 12 | - TronLink extension installed in the browser. [Docs](https://docs.tronlink.org/) 13 | 14 | ## Installation 15 | First, install the necessary packages: 16 | 17 | ```bash 18 | npm install @allbridge/bridge-core-sdk 19 | ``` 20 | 21 | ## Step-by-Step Integration 22 | 23 | ### Step 1: Import Necessary Modules 24 | Import the required modules: 25 | 26 | ```typescript 27 | import { 28 | AllbridgeCoreSdk, 29 | ChainSymbol, 30 | NodeRpcUrls, 31 | SendParams, 32 | } from '@allbridge/bridge-core-sdk'; 33 | ``` 34 | ### Step 2: Define Node URLs, SDK and tronWeb wallet 35 | Set up the node URLs for the different chains. Initialize the Allbridge Core SDK and the tronWeb instance: 36 | 37 | ```typescript 38 | const SDK_NODE_URLS: NodeRpcUrls = { 39 | [ChainSymbol.TRX]: 'https://api.trongrid.io', 40 | }; 41 | const sdk = new AllbridgeCoreSdk(SDK_NODE_URLS); 42 | const tronWeb = window.tronLink.tronWeb; 43 | ``` 44 | 45 | ### Step 3: Create, sign and send Allbridge raw transaction: 46 | 47 | ```typescript 48 | const rawTransaction = await sdk.bridge.rawTxBuilder.send(params, tronWeb); 49 | const signedTx = await tronWeb.trx.sign(rawTransaction); 50 | const txId = await tronWeb.trx.sendRawTransaction(signedTx); 51 | console.log('txId', txId); 52 | ``` 53 | 54 | ## Conclusion 55 | With this guide, you have set up the Allbridge Core SDK and TronLink wallet integration on your web application using TypeScript. You can now securely send transactions and check their status on the Tron blockchain. For further customization and advanced usage, refer to the official documentation of the respective SDKs. 56 | -------------------------------------------------------------------------------- /documentation/core-sdk-configure.md: -------------------------------------------------------------------------------- 1 | # Allbridge Core SDK 2 | 3 | ### Configure headers for requests to Core API 4 | 5 | If needed, SDK can be configured to always add headers when making requests to Core API: 6 | ```ts 7 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault, mainnet } from "@allbridge/bridge-core-sdk"; 8 | const sdk = new AllbridgeCoreSdk( 9 | nodeRpcUrlsDefault, 10 | { 11 | ...mainnet, 12 | coreApiHeaders: { 13 | "secret-waf-header": "value" 14 | } 15 | }); 16 | ``` 17 | -------------------------------------------------------------------------------- /documentation/core-sdk-install.md: -------------------------------------------------------------------------------- 1 | # Allbridge Core SDK: Install 2 | 3 | ### Install instructions 4 | 5 | Using npm: 6 | 7 | ```bash 8 | $ npm install @allbridge/bridge-core-sdk 9 | ``` 10 | 11 | Using yarn: 12 | 13 | ```bash 14 | $ yarn add @allbridge/bridge-core-sdk 15 | ``` 16 | 17 | Using pnpm: 18 | 19 | ```bash 20 | $ pnpm add @allbridge/bridge-core-sdk 21 | ``` 22 | 23 | --- 24 | #### Next: [Configure SDK instance](core-sdk-configure.md) 25 | -------------------------------------------------------------------------------- /esbuild-hook.js: -------------------------------------------------------------------------------- 1 | const Module = require("module"); 2 | const { transformSync } = require("esbuild"); 3 | const sourceMapSupport = require("source-map-support"); 4 | 5 | const cache = {}; 6 | 7 | function esbuildHook(code, filepath) { 8 | const result = transformSync(code, { 9 | target: "node22", 10 | sourcemap: "both", 11 | loader: "ts", 12 | format: "cjs", 13 | sourcefile: filepath, 14 | }); 15 | 16 | cache[filepath] = { 17 | url: filepath, 18 | code: result.code, 19 | map: result.map, 20 | }; 21 | 22 | return result.code; 23 | } 24 | 25 | sourceMapSupport.install({ 26 | environment: "node", 27 | retrieveFile(pathOrUrl) { 28 | const file = cache[pathOrUrl]; 29 | if (file) { 30 | return file.code; 31 | } else { 32 | return ""; 33 | } 34 | }, 35 | }); 36 | 37 | const defaultLoader = Module._extensions[".js"]; 38 | 39 | Module._extensions[".ts"] = function (mod, filename) { 40 | if (filename.includes("node_modules")) { 41 | return defaultLoader(mod, filename); 42 | } 43 | 44 | const defaultCompile = mod._compile; 45 | mod._compile = function (code) { 46 | mod._compile = defaultCompile; 47 | return mod._compile(esbuildHook(code, filename), filename); 48 | }; 49 | 50 | defaultLoader(mod, filename); 51 | }; 52 | -------------------------------------------------------------------------------- /examples/.env.example: -------------------------------------------------------------------------------- 1 | WEB3_PROVIDER_URL= 2 | ETH_PRIVATE_KEY= 3 | ETH_ACCOUNT_ADDRESS= 4 | ETH_POOL_ADDRESS= 5 | ETH_TOKEN_ADDRESS= 6 | 7 | POL_WEB3_PROVIDER_URL= 8 | POL_PRIVATE_KEY= 9 | POL_ACCOUNT_ADDRESS= 10 | POL_POOL_ADDRESS= 11 | POL_TOKEN_ADDRESS= 12 | 13 | TRONWEB_PROVIDER_URL= 14 | TRX_PRIVATE_KEY= 15 | TRX_ACCOUNT_ADDRESS= 16 | TRX_POOL_ADDRESS= 17 | TRX_TOKEN_ADDRESS= 18 | SENT_TX_ID= 19 | 20 | SOL_ACCOUNT_ADDRESS= 21 | SOL_PRIVATE_KEY= 22 | SOL_TOKEN_ADDRESS= 23 | -------------------------------------------------------------------------------- /examples/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: "@typescript-eslint/parser", 3 | parserOptions: { 4 | project: "tsconfig.json", 5 | tsconfigRootDir: __dirname, 6 | sourceType: "module", 7 | }, 8 | plugins: ["@typescript-eslint/eslint-plugin"], 9 | extends: ["plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"], 10 | root: true, 11 | env: { 12 | node: true, 13 | jest: true, 14 | }, 15 | ignorePatterns: [".eslintrc.js"], 16 | rules: { 17 | "prettier/prettier": 0, 18 | "@typescript-eslint/interface-name-prefix": "off", 19 | "@typescript-eslint/explicit-function-return-type": "off", 20 | "@typescript-eslint/explicit-module-boundary-types": "off", 21 | "@typescript-eslint/no-explicit-any": "off", 22 | "@typescript-eslint/ban-ts-comment": "warn", 23 | "@typescript-eslint/no-floating-promises": "error", 24 | }, 25 | }; 26 | -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | src/examples/testnet.ts 2 | -------------------------------------------------------------------------------- /examples/src/examples/bridge/evm/evm-build-send-tx.ts: -------------------------------------------------------------------------------- 1 | import { 2 | AllbridgeCoreSdk, 3 | ChainSymbol, 4 | Messenger, 5 | nodeRpcUrlsDefault, 6 | RawEvmTransaction, 7 | } from "@allbridge/bridge-core-sdk"; 8 | import * as dotenv from "dotenv"; 9 | import { getEnvVar } from "../../../utils/env"; 10 | import { sendEvmRawTransaction } from "../../../utils/web3"; 11 | import { ensure } from "../../../utils/utils"; 12 | 13 | dotenv.config({ path: ".env" }); 14 | 15 | const main = async () => { 16 | const fromAddress = getEnvVar("ETH_ACCOUNT_ADDRESS"); // sender address 17 | const toAddress = getEnvVar("TRX_ACCOUNT_ADDRESS"); // recipient address 18 | 19 | const sdk = new AllbridgeCoreSdk({ ...nodeRpcUrlsDefault, ETH: getEnvVar("WEB3_PROVIDER_URL") }); 20 | 21 | const chains = await sdk.chainDetailsMap(); 22 | 23 | const sourceChain = chains[ChainSymbol.ETH]; 24 | const sourceToken = ensure(sourceChain.tokens.find((tokenInfo) => tokenInfo.symbol === "USDC")); 25 | 26 | const destinationChain = chains[ChainSymbol.POL]; 27 | const destinationToken = ensure(destinationChain.tokens.find((tokenInfo) => tokenInfo.symbol === "USDC")); 28 | 29 | const amount = "1.01"; 30 | 31 | //check if sending tokens already approved 32 | if (!(await sdk.bridge.checkAllowance({ token: sourceToken, owner: fromAddress, amount: amount }))) { 33 | // authorize the bridge to transfer tokens from sender's address 34 | const rawTransactionApprove = (await sdk.bridge.rawTxBuilder.approve({ 35 | token: sourceToken, 36 | owner: fromAddress, 37 | })) as RawEvmTransaction; 38 | const approveTxReceipt = await sendEvmRawTransaction(rawTransactionApprove); 39 | console.log("Approve tx id:", approveTxReceipt.transactionHash); 40 | } 41 | 42 | // initiate transfer 43 | const rawTransactionTransfer = (await sdk.bridge.rawTxBuilder.send({ 44 | amount: amount, 45 | fromAccountAddress: fromAddress, 46 | toAccountAddress: toAddress, 47 | sourceToken: sourceToken, 48 | destinationToken: destinationToken, 49 | messenger: Messenger.ALLBRIDGE, 50 | })) as RawEvmTransaction; 51 | console.log(`Sending ${amount} ${sourceToken.symbol}`); 52 | const txReceipt = await sendEvmRawTransaction(rawTransactionTransfer); 53 | console.log("tx id:", txReceipt.transactionHash); 54 | }; 55 | 56 | main() 57 | .then(() => { 58 | console.log("Done"); 59 | }) 60 | .catch((e) => { 61 | console.error(e); 62 | }); 63 | -------------------------------------------------------------------------------- /examples/src/examples/bridge/evm/evm-build-swap-tx.ts: -------------------------------------------------------------------------------- 1 | import { 2 | AllbridgeCoreSdk, 3 | ChainSymbol, 4 | nodeRpcUrlsDefault, 5 | RawEvmTransaction, 6 | SwapParams, 7 | } from "@allbridge/bridge-core-sdk"; 8 | import * as dotenv from "dotenv"; 9 | import { getEnvVar } from "../../../utils/env"; 10 | import { sendEvmRawTransaction } from "../../../utils/web3"; 11 | import { ensure } from "../../../utils/utils"; 12 | 13 | dotenv.config({ path: ".env" }); 14 | 15 | const main = async () => { 16 | const fromAddress = getEnvVar("ETH_ACCOUNT_ADDRESS"); // sender address 17 | const toAddress = getEnvVar("ETH_ACCOUNT_ADDRESS"); // recipient address 18 | 19 | const sdk = new AllbridgeCoreSdk({ ...nodeRpcUrlsDefault, ETH: getEnvVar("WEB3_PROVIDER_URL") }); 20 | 21 | const chains = await sdk.chainDetailsMap(); 22 | 23 | const sourceChain = chains[ChainSymbol.ETH]; 24 | const sourceToken = ensure(sourceChain.tokens.find((tokenInfo) => tokenInfo.symbol === "USDC")); 25 | 26 | const destinationChain = chains[ChainSymbol.ETH]; 27 | const destinationToken = ensure(destinationChain.tokens.find((tokenInfo) => tokenInfo.symbol === "USDC")); 28 | 29 | const amount = "10"; 30 | 31 | //check if sending tokens already approved 32 | if (!(await sdk.bridge.checkAllowance({ token: sourceToken, owner: fromAddress, amount: amount }))) { 33 | // authorize the bridge to transfer tokens from sender's address 34 | const rawTransactionApprove = (await sdk.bridge.rawTxBuilder.approve({ 35 | token: sourceToken, 36 | owner: fromAddress, 37 | })) as RawEvmTransaction; 38 | const approveTxReceipt = await sendEvmRawTransaction(rawTransactionApprove); 39 | console.log("approve tx id:", approveTxReceipt.transactionHash); 40 | } 41 | 42 | // initiate transfer 43 | const swapParams: SwapParams = { 44 | amount: amount, 45 | fromAccountAddress: fromAddress, 46 | toAccountAddress: toAddress, 47 | sourceToken: sourceToken, 48 | destinationToken: destinationToken, 49 | minimumReceiveAmount: await sdk.getAmountToBeReceived(amount, sourceToken, destinationToken), 50 | }; 51 | const rawTransactionTransfer = (await sdk.bridge.rawTxBuilder.send(swapParams)) as RawEvmTransaction; 52 | 53 | console.log(`Swaping ${amount} ${sourceToken.symbol}`); 54 | const txReceipt = await sendEvmRawTransaction(rawTransactionTransfer); 55 | console.log("tx id:", txReceipt.transactionHash); 56 | }; 57 | 58 | main() 59 | .then(() => { 60 | console.log("Done"); 61 | }) 62 | .catch((e) => { 63 | console.error(e); 64 | }); 65 | -------------------------------------------------------------------------------- /examples/src/examples/bridge/get-average-transfer-time.ts: -------------------------------------------------------------------------------- 1 | import { AllbridgeCoreSdk, Messenger, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 2 | import { ensure } from "../../utils/utils"; 3 | 4 | function msToTime(ms: number) { 5 | const milliseconds = ms % 1000; 6 | const seconds = Math.floor((ms / 1000) % 60); 7 | const minutes = Math.floor((ms / (60 * 1000)) % 60); 8 | const hours = Math.floor((ms / (3600 * 1000)) % 3600); 9 | return `${hours === 0 ? "" : hours + ":"}${minutes < 10 ? "0" + minutes : minutes}:${ 10 | seconds < 10 ? "0" + seconds : seconds 11 | }.${milliseconds}`; 12 | } 13 | 14 | const main = async () => { 15 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 16 | 17 | const tokens = await sdk.tokens(); 18 | const sourceToken = ensure(tokens.find((token) => token.chainSymbol === "ETH" && token.symbol === "USDT")); 19 | const destinationToken = ensure(tokens.find((token) => token.chainSymbol === "TRX" && token.symbol === "USDT")); 20 | 21 | const transferTimeMs = ensure(sdk.getAverageTransferTime(sourceToken, destinationToken, Messenger.ALLBRIDGE)); 22 | 23 | console.log( 24 | "Average transfer time from %s to %s is %s", 25 | sourceToken.chainSymbol, 26 | destinationToken.chainSymbol, 27 | msToTime(transferTimeMs) 28 | ); 29 | }; 30 | 31 | main() 32 | .then(() => { 33 | console.log("Done"); 34 | }) 35 | .catch((e) => { 36 | console.error(e); 37 | }); 38 | -------------------------------------------------------------------------------- /examples/src/examples/bridge/get-extra-gas-max-limits.ts: -------------------------------------------------------------------------------- 1 | import { AllbridgeCoreSdk, ChainSymbol, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 2 | import { ensure } from "../../utils/utils"; 3 | 4 | const main = async () => { 5 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 6 | 7 | const chainDetailsMap = await sdk.chainDetailsMap(); 8 | 9 | const sourceToken = ensure(chainDetailsMap[ChainSymbol.POL].tokens.find((token) => token.symbol === "USDC")); 10 | const destToken = ensure(chainDetailsMap[ChainSymbol.TRX].tokens.find((token) => token.symbol === "USDT")); 11 | 12 | const extraGasMax = await sdk.getExtraGasMaxLimits(sourceToken, destToken); 13 | console.log("extraGas Limits =", JSON.stringify(extraGasMax, null, 2)); 14 | }; 15 | 16 | main() 17 | .then(() => { 18 | console.log("Done"); 19 | }) 20 | .catch((e) => { 21 | console.error(e); 22 | }); 23 | -------------------------------------------------------------------------------- /examples/src/examples/bridge/get-transfer-status.ts: -------------------------------------------------------------------------------- 1 | import { AllbridgeCoreSdk, ChainSymbol, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 2 | import { getEnvVar } from "../../utils/env"; 3 | import * as dotenv from "dotenv"; 4 | dotenv.config({ path: ".env" }); 5 | 6 | const main = async () => { 7 | const txId = getEnvVar("SENT_TX_ID"); 8 | const chainSymbol = ChainSymbol.TRX; // example, must correspond to SENT_TX_ID blockchain 9 | 10 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 11 | 12 | const sendStatus = await sdk.getTransferStatus(chainSymbol, txId); 13 | 14 | console.log("Send Status: ", sendStatus); 15 | }; 16 | 17 | main() 18 | .then(() => { 19 | console.log("Done"); 20 | }) 21 | .catch((e) => { 22 | console.error(e); 23 | }); 24 | -------------------------------------------------------------------------------- /examples/src/examples/bridge/send-by-cctp.ts: -------------------------------------------------------------------------------- 1 | import { 2 | AllbridgeCoreSdk, 3 | ChainSymbol, 4 | Messenger, 5 | nodeRpcUrlsDefault, 6 | RawEvmTransaction, 7 | SendParams, 8 | } from "@allbridge/bridge-core-sdk"; 9 | import { sendEvmRawTransaction } from "../../utils/web3"; 10 | import { ensure } from "../../utils/utils"; 11 | import { getEnvVar } from "../../utils/env"; 12 | 13 | const ETH_NODE_RPC_URL = getEnvVar("ETH_NODE_RPC_URL"); 14 | const fromAccountAddress = getEnvVar("ETH_ACCOUNT_ADDRESS"); 15 | const toAccountAddress = getEnvVar("ARB_ACCOUNT_ADDRESS"); 16 | 17 | const main = async () => { 18 | const sdk = new AllbridgeCoreSdk({ ...nodeRpcUrlsDefault, ETH: ETH_NODE_RPC_URL }); 19 | const chainDetailsMap = await sdk.chainDetailsMap(); 20 | const sourceToken = ensure(chainDetailsMap[ChainSymbol.ETH].tokens.find((t) => t.symbol == "USDC")); 21 | const destinationToken = ensure(chainDetailsMap[ChainSymbol.ARB].tokens.find((t) => t.symbol == "USDC")); 22 | //check if tokens support cctp 23 | if (sourceToken.cctpAddress && destinationToken.cctpAddress) { 24 | //send by cctp 25 | const amount = "1"; 26 | const checkAllowance = await sdk.bridge.checkAllowance({ 27 | amount, 28 | token: sourceToken, 29 | owner: fromAccountAddress, 30 | messenger: Messenger.CCTP, 31 | }); 32 | console.log("checkAllowance", checkAllowance); 33 | if (!checkAllowance) { 34 | const approveParams = { 35 | token: sourceToken, 36 | owner: fromAccountAddress, 37 | messenger: Messenger.CCTP, 38 | }; 39 | const tx = (await sdk.bridge.rawTxBuilder.approve(approveParams)) as RawEvmTransaction; 40 | const txReceipt = await sendEvmRawTransaction(tx); 41 | console.log("approve tx id:", txReceipt.transactionHash); 42 | } 43 | const willBeReceived = await sdk.getAmountToBeReceived(amount, destinationToken, sourceToken, Messenger.CCTP); 44 | console.log("willBeReceived", willBeReceived); 45 | const sendParams: SendParams = { 46 | amount, 47 | fromAccountAddress, 48 | toAccountAddress, 49 | destinationToken, 50 | sourceToken, 51 | messenger: Messenger.CCTP, 52 | }; 53 | const tx = (await sdk.bridge.rawTxBuilder.send(sendParams)) as RawEvmTransaction; 54 | //sign and send raw Tx 55 | const txReceipt = await sendEvmRawTransaction(tx); 56 | console.log("tx id:", txReceipt.transactionHash); 57 | } 58 | }; 59 | 60 | main() 61 | .then(() => { 62 | console.log("Done"); 63 | }) 64 | .catch((e) => { 65 | console.error(e); 66 | }); 67 | -------------------------------------------------------------------------------- /examples/src/examples/bridge/solana/sol-build-swap-tx.ts: -------------------------------------------------------------------------------- 1 | import { 2 | AllbridgeCoreSdk, 3 | ChainSymbol, 4 | nodeRpcUrlsDefault, 5 | RawBridgeSolanaTransaction, 6 | } from "@allbridge/bridge-core-sdk"; 7 | import * as dotenv from "dotenv"; 8 | import { getEnvVar } from "../../../utils/env"; 9 | import { ensure } from "../../../utils/utils"; 10 | import solanaWeb3 from "@solana/web3.js"; 11 | import bs58 from "bs58"; 12 | 13 | dotenv.config({ path: ".env" }); 14 | 15 | const accountAddress = getEnvVar("SOL_ACCOUNT_ADDRESS"); 16 | const privateKey = getEnvVar("SOL_PRIVATE_KEY"); 17 | 18 | const example = async () => { 19 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 20 | 21 | const chains = await sdk.chainDetailsMap(); 22 | 23 | const sourceChain = chains[ChainSymbol.SOL]; 24 | const sourceToken = ensure(sourceChain.tokens.find((tokenInfo) => tokenInfo.symbol === "USDC")); 25 | 26 | const destinationChain = chains[ChainSymbol.SOL]; 27 | const destinationToken = ensure(destinationChain.tokens.find((tokenInfo) => tokenInfo.symbol === "USDC")); 28 | 29 | // initiate transfer using Messenger.WORMHOLE 30 | const amount = "10"; 31 | const transaction = (await sdk.bridge.rawTxBuilder.send({ 32 | amount: amount, 33 | fromAccountAddress: accountAddress, 34 | toAccountAddress: accountAddress, 35 | sourceToken: sourceToken, 36 | destinationToken: destinationToken, 37 | minimumReceiveAmount: await sdk.getAmountToBeReceived(amount, sourceToken, destinationToken), 38 | })) as RawBridgeSolanaTransaction; 39 | 40 | const keypair = solanaWeb3.Keypair.fromSecretKey(bs58.decode(privateKey)); 41 | transaction.sign([keypair]); 42 | 43 | const connection = new solanaWeb3.Connection(ensure(nodeRpcUrlsDefault.SOL), "confirmed"); 44 | const txid = await connection.sendTransaction(transaction); 45 | console.log(`https://explorer.solana.com/tx/${txid}`); 46 | }; 47 | 48 | example() 49 | .then(() => { 50 | console.log("Done"); 51 | }) 52 | .catch((e) => { 53 | console.error(e); 54 | }); 55 | -------------------------------------------------------------------------------- /examples/src/examples/bridge/sui/sui-build-send-tx.ts: -------------------------------------------------------------------------------- 1 | import { 2 | AllbridgeCoreSdk, 3 | ChainSymbol, 4 | Messenger, 5 | nodeRpcUrlsDefault, 6 | RawSuiTransaction, 7 | } from "@allbridge/bridge-core-sdk"; 8 | import * as dotenv from "dotenv"; 9 | import { getEnvVar } from "../../../utils/env"; 10 | import { ensure } from "../../../utils/utils"; 11 | import { sendSuiRawTransaction } from "../../../utils/sui"; 12 | 13 | dotenv.config({ path: ".env" }); 14 | 15 | const main = async () => { 16 | // sender address 17 | const accountAddress = getEnvVar("SUI_ACCOUNT_ADDRESS"); 18 | const toAddress = getEnvVar("ETH_ACCOUNT_ADDRESS"); // recipient address 19 | 20 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 21 | 22 | const chains = await sdk.chainDetailsMap(); 23 | 24 | const sourceChain = chains[ChainSymbol.SUI]; 25 | const sourceToken = ensure(sourceChain.tokens.find((tokenInfo) => tokenInfo.symbol === "USDC")); 26 | 27 | const destinationChain = chains[ChainSymbol.ETH]; 28 | const destinationToken = ensure(destinationChain.tokens.find((tokenInfo) => tokenInfo.symbol === "USDC")); 29 | 30 | const amount = "100"; 31 | 32 | // initiate transfer 33 | const xdr = (await sdk.bridge.rawTxBuilder.send({ 34 | amount: amount, 35 | fromAccountAddress: accountAddress, 36 | toAccountAddress: toAddress, 37 | sourceToken: sourceToken, 38 | destinationToken: destinationToken, 39 | messenger: Messenger.ALLBRIDGE, 40 | // gasFeePaymentMethod: FeePaymentMethod.WITH_STABLECOIN, 41 | })) as RawSuiTransaction; 42 | 43 | const txReceipt = await sendSuiRawTransaction(xdr); 44 | console.log("tx id:", txReceipt); 45 | }; 46 | 47 | main() 48 | .then(() => { 49 | console.log("Done"); 50 | }) 51 | .catch((e) => { 52 | console.error(e); 53 | }); 54 | -------------------------------------------------------------------------------- /examples/src/examples/bridge/sui/sui-build-swap-tx.ts: -------------------------------------------------------------------------------- 1 | import { 2 | AllbridgeCoreSdk, 3 | ChainSymbol, 4 | nodeRpcUrlsDefault, 5 | RawSuiTransaction, 6 | SwapParams, 7 | } from "@allbridge/bridge-core-sdk"; 8 | import * as dotenv from "dotenv"; 9 | import { getEnvVar } from "../../../utils/env"; 10 | import { ensure } from "../../../utils/utils"; 11 | import { sendSuiRawTransaction } from "../../../utils/sui"; 12 | 13 | dotenv.config({ path: ".env" }); 14 | 15 | const main = async () => { 16 | // sender address 17 | const accountAddress = getEnvVar("SUI_ACCOUNT_ADDRESS"); 18 | const tokenAddress = getEnvVar("SUI_TOKEN_ADDRESS"); 19 | const tokenAddress2 = getEnvVar("SUI_TOKEN2_ADDRESS"); 20 | 21 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 22 | 23 | const chains = await sdk.chainDetailsMap(); 24 | 25 | const sourceToken = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.originTokenAddress === tokenAddress)); 26 | 27 | const destinationToken = ensure( 28 | (await sdk.tokens()).find((tokenInfo) => tokenInfo.originTokenAddress === tokenAddress2) 29 | ); 30 | 31 | const amount = "10"; 32 | 33 | // initiate transfer 34 | const swapParams: SwapParams = { 35 | amount: amount, 36 | fromAccountAddress: accountAddress, 37 | toAccountAddress: accountAddress, 38 | sourceToken: sourceToken, 39 | destinationToken: destinationToken, 40 | minimumReceiveAmount: await sdk.getAmountToBeReceived(amount, sourceToken, destinationToken), 41 | }; 42 | const xdr = (await sdk.bridge.rawTxBuilder.send(swapParams)) as RawSuiTransaction; 43 | 44 | const txReceipt = await sendSuiRawTransaction(xdr); 45 | console.log("tx id:", txReceipt); 46 | }; 47 | 48 | main() 49 | .then(() => { 50 | console.log("Done"); 51 | }) 52 | .catch((e) => { 53 | console.error(e); 54 | }); 55 | -------------------------------------------------------------------------------- /examples/src/examples/bridge/trx/trx-build-send-tx.ts: -------------------------------------------------------------------------------- 1 | import { 2 | AllbridgeCoreSdk, 3 | ChainSymbol, 4 | Messenger, 5 | nodeRpcUrlsDefault, 6 | RawTronTransaction, 7 | } from "@allbridge/bridge-core-sdk"; 8 | import * as dotenv from "dotenv"; 9 | import { getEnvVar } from "../../../utils/env"; 10 | import { ensure } from "../../../utils/utils"; 11 | import { sendTrxRawTransaction } from "../../../utils/tronWeb"; 12 | 13 | dotenv.config({ path: ".env" }); 14 | 15 | const main = async () => { 16 | const fromAddress = getEnvVar("TRX_ACCOUNT_ADDRESS"); 17 | const toAddress = getEnvVar("ETH_ACCOUNT_ADDRESS"); 18 | 19 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 20 | 21 | const chains = await sdk.chainDetailsMap(); 22 | 23 | const sourceChain = chains[ChainSymbol.TRX]; 24 | const sourceToken = ensure(sourceChain.tokens.find((tokenInfo) => tokenInfo.symbol === "USDT")); 25 | 26 | const destinationChain = chains[ChainSymbol.ETH]; 27 | const destinationToken = ensure(destinationChain.tokens.find((tokenInfo) => tokenInfo.symbol === "USDC")); 28 | 29 | const amount = "17.17"; 30 | 31 | //check if sending tokens already approved 32 | if (!(await sdk.bridge.checkAllowance({ token: sourceToken, owner: fromAddress, amount: amount }))) { 33 | // authorize the bridge to transfer tokens from sender's address 34 | const rawTransactionApprove = (await sdk.bridge.rawTxBuilder.approve({ 35 | token: sourceToken, 36 | owner: fromAddress, 37 | })) as RawTronTransaction; 38 | const approveReceipt = await sendTrxRawTransaction(rawTransactionApprove); 39 | console.log("Approve transaction receipt", JSON.stringify(approveReceipt, null, 2)); 40 | } 41 | 42 | // initiate transfer 43 | const rawTransactionTransfer = (await sdk.bridge.rawTxBuilder.send({ 44 | amount: amount, 45 | fromAccountAddress: fromAddress, 46 | toAccountAddress: toAddress, 47 | sourceToken: sourceToken, 48 | destinationToken: destinationToken, 49 | messenger: Messenger.ALLBRIDGE, 50 | })) as RawTronTransaction; 51 | 52 | const transferReceipt = await sendTrxRawTransaction(rawTransactionTransfer); 53 | console.log("Transfer tokens transaction receipt:", transferReceipt); 54 | }; 55 | 56 | main() 57 | .then(() => { 58 | console.log("Done"); 59 | }) 60 | .catch((e) => { 61 | console.error(e); 62 | }); 63 | -------------------------------------------------------------------------------- /examples/src/examples/bridge/trx/trx-build-swap-tx.ts: -------------------------------------------------------------------------------- 1 | import { 2 | AllbridgeCoreSdk, 3 | ChainSymbol, 4 | SwapParams, 5 | nodeRpcUrlsDefault, 6 | RawTronTransaction, 7 | } from "@allbridge/bridge-core-sdk"; 8 | import * as dotenv from "dotenv"; 9 | import { getEnvVar } from "../../../utils/env"; 10 | import { ensure } from "../../../utils/utils"; 11 | import { sendTrxRawTransaction } from "../../../utils/tronWeb"; 12 | 13 | dotenv.config({ path: ".env" }); 14 | 15 | const main = async () => { 16 | const fromAddress = getEnvVar("TRX_ACCOUNT_ADDRESS"); 17 | const toAddress = getEnvVar("TRX_ACCOUNT_ADDRESS"); 18 | 19 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 20 | 21 | const chains = await sdk.chainDetailsMap(); 22 | 23 | const sourceChain = chains[ChainSymbol.TRX]; 24 | const sourceToken = ensure(sourceChain.tokens.find((tokenInfo) => tokenInfo.symbol === "USDC")); 25 | 26 | const destinationChain = chains[ChainSymbol.TRX]; 27 | const destinationToken = ensure(destinationChain.tokens.find((tokenInfo) => tokenInfo.symbol === "USDC")); 28 | 29 | const amount = "10"; 30 | 31 | //check if sending tokens already approved 32 | if (!(await sdk.bridge.checkAllowance({ token: sourceToken, owner: fromAddress, amount: amount }))) { 33 | // authorize the bridge to transfer tokens from sender's address 34 | const rawTransactionApprove = (await sdk.bridge.rawTxBuilder.approve({ 35 | token: sourceToken, 36 | owner: fromAddress, 37 | })) as RawTronTransaction; 38 | const approveReceipt = await sendTrxRawTransaction(rawTransactionApprove); 39 | console.log("Approve transaction receipt", JSON.stringify(approveReceipt, null, 2)); 40 | } 41 | 42 | // initiate transfer 43 | const swapParams: SwapParams = { 44 | amount: amount, 45 | fromAccountAddress: fromAddress, 46 | toAccountAddress: toAddress, 47 | sourceToken: sourceToken, 48 | destinationToken: destinationToken, 49 | minimumReceiveAmount: await sdk.getAmountToBeReceived(amount, sourceToken, destinationToken), 50 | }; 51 | const rawTransactionTransfer = (await sdk.bridge.rawTxBuilder.send(swapParams)) as RawTronTransaction; 52 | 53 | console.log(`Sending ${amount} ${sourceToken.symbol}`); 54 | const txReceipt = await sendTrxRawTransaction(rawTransactionTransfer); 55 | console.log("txReceipt:", txReceipt); 56 | }; 57 | 58 | main() 59 | .then(() => { 60 | console.log("Done"); 61 | }) 62 | .catch((e) => { 63 | console.error(e); 64 | }); 65 | -------------------------------------------------------------------------------- /examples/src/examples/general/evm/evm-approve-tokens.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault, RawEvmTransaction } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | import { sendEvmRawTransaction } from "../../../utils/web3"; 6 | dotenv.config({ path: ".env" }); 7 | 8 | const main = async () => { 9 | const tokenAddress = getEnvVar("ETH_TOKEN_ADDRESS"); 10 | const accountAddress = getEnvVar("ETH_ACCOUNT_ADDRESS"); 11 | 12 | const sdk = new AllbridgeCoreSdk({ ...nodeRpcUrlsDefault, ETH: getEnvVar("WEB3_PROVIDER_URL") }); 13 | const tokenInfo = ensure((await sdk.tokens()).find((t) => t.tokenAddress === tokenAddress)); 14 | 15 | // authorize the bridge to transfer tokens from sender's address 16 | const rawTransactionApprove = (await sdk.bridge.rawTxBuilder.approve({ 17 | token: tokenInfo, 18 | owner: accountAddress, 19 | })) as RawEvmTransaction; 20 | const approveTxReceipt = await sendEvmRawTransaction(rawTransactionApprove); 21 | console.log("approve tx id:", approveTxReceipt.transactionHash); 22 | }; 23 | 24 | main() 25 | .then(() => { 26 | console.log("Done"); 27 | }) 28 | .catch((e) => { 29 | console.error(e); 30 | }); 31 | -------------------------------------------------------------------------------- /examples/src/examples/general/evm/evm-get-token-balance.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | dotenv.config({ path: ".env" }); 6 | 7 | const main = async () => { 8 | const tokenAddress = getEnvVar("ETH_TOKEN_ADDRESS"); 9 | const accountAddress = getEnvVar("ETH_ACCOUNT_ADDRESS"); 10 | 11 | const sdk = new AllbridgeCoreSdk({ ...nodeRpcUrlsDefault, ETH: getEnvVar("WEB3_PROVIDER_URL") }); 12 | 13 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 14 | 15 | const tokenBalanceData = { 16 | account: accountAddress, 17 | token: tokenInfo, 18 | }; 19 | const tokenBalance = await sdk.getTokenBalance(tokenBalanceData); 20 | console.log("Token Balance: ", tokenBalance); 21 | 22 | const tokenBalanceWithPrecisionData = { 23 | account: accountAddress, 24 | token: tokenInfo, 25 | }; 26 | const tokenBalanceWithPrecision = await sdk.getTokenBalance(tokenBalanceWithPrecisionData); 27 | console.log("With precision:", tokenBalanceWithPrecision); 28 | }; 29 | 30 | main() 31 | .then(() => { 32 | console.log("Done"); 33 | }) 34 | .catch((e) => { 35 | console.error(e); 36 | }); 37 | -------------------------------------------------------------------------------- /examples/src/examples/general/solana/sol-get-token-balance.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | dotenv.config({ path: ".env" }); 6 | 7 | const main = async () => { 8 | const tokenAddress = getEnvVar("SOL_TOKEN_ADDRESS"); 9 | const accountAddress = getEnvVar("SOL_ACCOUNT_ADDRESS"); 10 | 11 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 12 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 13 | 14 | const tokenBalanceData = { 15 | account: accountAddress, 16 | token: tokenInfo, 17 | }; 18 | const tokenBalance = await sdk.getTokenBalance(tokenBalanceData); 19 | console.log("Token Balance: ", tokenBalance); 20 | 21 | const tokenBalanceWithPrecisionData = { 22 | account: accountAddress, 23 | token: tokenInfo, 24 | }; 25 | const tokenBalanceWithPrecision = await sdk.getTokenBalance(tokenBalanceWithPrecisionData); 26 | console.log("With precision:", tokenBalanceWithPrecision); 27 | }; 28 | 29 | main() 30 | .then(() => { 31 | console.log("Done"); 32 | }) 33 | .catch((e) => { 34 | console.error(e); 35 | }); 36 | -------------------------------------------------------------------------------- /examples/src/examples/general/sui/sui-get-token-balance.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, ChainSymbol, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | 6 | dotenv.config({ path: ".env" }); 7 | 8 | const main = async () => { 9 | const tokenAddress = getEnvVar("SUI_TOKEN_ADDRESS"); 10 | const accountAddress = getEnvVar("SUI_ACCOUNT_ADDRESS"); 11 | 12 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 13 | 14 | const nativeTokenBalance = await sdk.getNativeTokenBalance({ account: accountAddress, chainSymbol: ChainSymbol.SUI }); 15 | console.log("Native Token Balance: ", nativeTokenBalance); 16 | 17 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.originTokenAddress === tokenAddress)); 18 | 19 | const tokenBalanceData = { 20 | account: accountAddress, 21 | token: tokenInfo, 22 | }; 23 | 24 | const tokenBalance = await sdk.getTokenBalance(tokenBalanceData); 25 | console.log("Token Balance: ", tokenBalance); 26 | }; 27 | 28 | main() 29 | .then(() => { 30 | console.log("Done"); 31 | }) 32 | .catch((e) => { 33 | console.error(e); 34 | }); 35 | -------------------------------------------------------------------------------- /examples/src/examples/get-tokens-info.ts: -------------------------------------------------------------------------------- 1 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 2 | 3 | const main = async () => { 4 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 5 | 6 | const chainDetailsMap = await sdk.chainDetailsMap(); 7 | console.log("Chain details map =", JSON.stringify(chainDetailsMap, null, 2)); 8 | 9 | const tokens = await sdk.tokens(); 10 | console.log("Tokens =", JSON.stringify(tokens, null, 2)); 11 | }; 12 | 13 | main() 14 | .then(() => { 15 | console.log("Done"); 16 | }) 17 | .catch((e) => { 18 | console.error(e); 19 | }); 20 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/evm/evm-build-claim-rewards-tx.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault, RawEvmTransaction } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | import { sendEvmRawTransaction } from "../../../utils/web3"; 6 | 7 | dotenv.config({ path: ".env" }); 8 | 9 | const main = async () => { 10 | // sender address 11 | const accountAddress = getEnvVar("ETH_ACCOUNT_ADDRESS"); 12 | const tokenAddress = getEnvVar("ETH_TOKEN_ADDRESS"); 13 | 14 | const sdk = new AllbridgeCoreSdk({ ...nodeRpcUrlsDefault, ETH: getEnvVar("WEB3_PROVIDER_URL") }); 15 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 16 | 17 | // create claim rewards raw transaction 18 | const rawTransactionDeposit = (await sdk.pool.rawTxBuilder.claimRewards({ 19 | accountAddress: accountAddress, 20 | token: tokenInfo, 21 | })) as RawEvmTransaction; 22 | 23 | const txReceipt = await sendEvmRawTransaction(rawTransactionDeposit); 24 | console.log("Token claim rewards:", txReceipt.transactionHash); 25 | }; 26 | 27 | main() 28 | .then(() => { 29 | console.log("Done"); 30 | }) 31 | .catch((e) => { 32 | console.error(e); 33 | }); 34 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/evm/evm-build-deposit-tx.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault, RawEvmTransaction } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | import { sendEvmRawTransaction } from "../../../utils/web3"; 6 | 7 | dotenv.config({ path: ".env" }); 8 | 9 | const main = async () => { 10 | // sender address 11 | const accountAddress = getEnvVar("ETH_ACCOUNT_ADDRESS"); 12 | const tokenAddress = getEnvVar("ETH_TOKEN_ADDRESS"); 13 | 14 | const sdk = new AllbridgeCoreSdk({ ...nodeRpcUrlsDefault, ETH: getEnvVar("WEB3_PROVIDER_URL") }); 15 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 16 | 17 | const oneToken = "1"; 18 | // create deposit raw transaction 19 | const rawTransactionDeposit = (await sdk.pool.rawTxBuilder.deposit({ 20 | amount: oneToken, 21 | accountAddress: accountAddress, 22 | token: tokenInfo, 23 | })) as RawEvmTransaction; 24 | 25 | const txReceipt = await sendEvmRawTransaction(rawTransactionDeposit); 26 | console.log("Token deposit:", txReceipt.transactionHash); 27 | }; 28 | 29 | main() 30 | .then(() => { 31 | console.log("Done"); 32 | }) 33 | .catch((e) => { 34 | console.error(e); 35 | }); 36 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/evm/evm-build-withdraw-tx.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault, RawEvmTransaction } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | import { sendEvmRawTransaction } from "../../../utils/web3"; 6 | 7 | dotenv.config({ path: ".env" }); 8 | 9 | const main = async () => { 10 | // sender address 11 | const accountAddress = getEnvVar("ETH_ACCOUNT_ADDRESS"); 12 | const tokenAddress = getEnvVar("ETH_TOKEN_ADDRESS"); 13 | 14 | const sdk = new AllbridgeCoreSdk({ ...nodeRpcUrlsDefault, ETH: getEnvVar("WEB3_PROVIDER_URL") }); 15 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 16 | 17 | const halfToken = "0.5"; 18 | // create withdraw raw transaction 19 | const rawTransactionDeposit = (await sdk.pool.rawTxBuilder.withdraw({ 20 | amount: halfToken, 21 | accountAddress: accountAddress, 22 | token: tokenInfo, 23 | })) as RawEvmTransaction; 24 | 25 | const txReceipt = await sendEvmRawTransaction(rawTransactionDeposit); 26 | console.log("Token withdraw:", txReceipt.transactionHash); 27 | }; 28 | 29 | main() 30 | .then(() => { 31 | console.log("Done"); 32 | }) 33 | .catch((e) => { 34 | console.error(e); 35 | }); 36 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/evm/get-amount-to-be-withdrawn.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | dotenv.config({ path: ".env" }); 6 | 7 | const main = async () => { 8 | const tokenAddress = getEnvVar("ETH_TOKEN_ADDRESS"); 9 | const accountAddress = getEnvVar("ETH_ACCOUNT_ADDRESS"); 10 | 11 | const sdk = new AllbridgeCoreSdk({ ...nodeRpcUrlsDefault, ETH: getEnvVar("WEB3_PROVIDER_URL") }); 12 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 13 | 14 | const halfToken = "0.5"; 15 | const estimatedAmount = await sdk.pool.getAmountToBeWithdrawn(halfToken, accountAddress, tokenInfo); 16 | console.log("If you withdraw %d LP tokens, then %d will be received", halfToken, estimatedAmount); 17 | }; 18 | 19 | main() 20 | .then(() => { 21 | console.log("Done"); 22 | }) 23 | .catch((e) => { 24 | console.error(e); 25 | }); 26 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/evm/get-liquidity-balance.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | dotenv.config({ path: ".env" }); 6 | 7 | const main = async () => { 8 | const tokenAddress = getEnvVar("ETH_TOKEN_ADDRESS"); 9 | const accountAddress = getEnvVar("ETH_ACCOUNT_ADDRESS"); 10 | 11 | const sdk = new AllbridgeCoreSdk({ ...nodeRpcUrlsDefault, ETH: getEnvVar("WEB3_PROVIDER_URL") }); 12 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 13 | 14 | const userBalanceInfo = await sdk.pool.getUserBalanceInfo(accountAddress, tokenInfo); 15 | const poolInfo = await sdk.pool.getPoolInfoFromChain(tokenInfo); 16 | 17 | console.log("Evm User balance: ", userBalanceInfo.userLiquidity); 18 | console.log("Evm User rewards: ", userBalanceInfo.earned(poolInfo, tokenInfo.decimals)); 19 | console.log("Evm PoolInfo APR: ", sdk.aprInPercents(tokenInfo.apr7d)); 20 | }; 21 | 22 | main() 23 | .then(() => { 24 | console.log("Done"); 25 | }) 26 | .catch((e) => { 27 | console.error(e); 28 | }); 29 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/evm/get-lp-amount-on-deposit.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | 6 | dotenv.config({ path: ".env" }); 7 | 8 | const main = async () => { 9 | const tokenAddress = getEnvVar("ETH_TOKEN_ADDRESS"); 10 | 11 | const sdk = new AllbridgeCoreSdk({ ...nodeRpcUrlsDefault, ETH: getEnvVar("WEB3_PROVIDER_URL") }); 12 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 13 | 14 | const oneToken = "1"; 15 | const estimatedAmount = await sdk.pool.getAmountToBeDeposited(oneToken, tokenInfo); 16 | console.log("If you send %d , then %d of LP tokens will be deposited", oneToken, estimatedAmount); 17 | }; 18 | 19 | main() 20 | .then(() => { 21 | console.log("Done"); 22 | }) 23 | .catch((e) => { 24 | console.error(e); 25 | }); 26 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/solana/get-amount-to-be-withdrawn.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | dotenv.config({ path: ".env" }); 6 | 7 | const main = async () => { 8 | const tokenAddress = getEnvVar("SOL_TOKEN_ADDRESS"); 9 | const accountAddress = getEnvVar("SOL_ACCOUNT_ADDRESS"); 10 | 11 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 12 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 13 | 14 | const halfToken = "0.5"; 15 | const estimatedAmount = await sdk.pool.getAmountToBeWithdrawn(halfToken, accountAddress, tokenInfo); 16 | 17 | console.log("If you withdraw %d LP tokens, then %d will be received", halfToken, estimatedAmount); 18 | }; 19 | 20 | main() 21 | .then(() => { 22 | console.log("Done"); 23 | }) 24 | .catch((e) => { 25 | console.error(e); 26 | }); 27 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/solana/get-liquidity-balance.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | dotenv.config({ path: ".env" }); 6 | 7 | const main = async () => { 8 | const tokenAddress = getEnvVar("SOL_TOKEN_ADDRESS"); 9 | const accountAddress = getEnvVar("SOL_ACCOUNT_ADDRESS"); 10 | 11 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 12 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 13 | const userBalanceInfo = await sdk.pool.getUserBalanceInfo(accountAddress, tokenInfo); 14 | const poolInfo = await sdk.pool.getPoolInfoFromChain(tokenInfo); 15 | 16 | console.log("Solana User balance: ", userBalanceInfo.userLiquidity); 17 | console.log("Solana User rewards: ", userBalanceInfo.earned(poolInfo, tokenInfo.decimals)); 18 | console.log("Solana PoolInfo APR: ", sdk.aprInPercents(tokenInfo.apr7d)); 19 | }; 20 | 21 | main() 22 | .then(() => { 23 | console.log("Done"); 24 | }) 25 | .catch((e) => { 26 | console.error(e); 27 | }); 28 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/solana/get-lp-amount-on-deposit.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | dotenv.config({ path: ".env" }); 6 | 7 | const main = async () => { 8 | const tokenAddress = getEnvVar("SOL_TOKEN_ADDRESS"); 9 | 10 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 11 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 12 | 13 | const oneToken = "1"; 14 | const estimatedAmount = await sdk.pool.getAmountToBeDeposited(oneToken, tokenInfo); 15 | 16 | console.log("If you send %d , then %d of LP tokens will be deposited", oneToken, estimatedAmount); 17 | }; 18 | 19 | main() 20 | .then(() => { 21 | console.log("Done"); 22 | }) 23 | .catch((e) => { 24 | console.error(e); 25 | }); 26 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/solana/sol-build-claim-rewards-tx.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault, RawPoolSolanaTransaction } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | import solanaWeb3, { sendAndConfirmTransaction, Transaction } from "@solana/web3.js"; 6 | import bs58 from "bs58"; 7 | 8 | dotenv.config({ path: ".env" }); 9 | 10 | const main = async () => { 11 | // sender address 12 | const accountAddress = getEnvVar("SOL_ACCOUNT_ADDRESS"); 13 | const privateKey = getEnvVar("SOL_PRIVATE_KEY"); 14 | const tokenAddress = getEnvVar("SOL_TOKEN_ADDRESS"); 15 | 16 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 17 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 18 | 19 | // create claim rewards raw transaction 20 | const transaction = (await sdk.pool.rawTxBuilder.claimRewards({ 21 | accountAddress: accountAddress, 22 | token: tokenInfo, 23 | })) as RawPoolSolanaTransaction; 24 | 25 | const tx = await sendRawTransaction(transaction, privateKey, ensure(nodeRpcUrlsDefault.SOL)); 26 | 27 | console.log("Token claim rewards:", tx); 28 | }; 29 | 30 | async function sendRawTransaction(transaction: Transaction, privateKey: string, solanaRpcUrl: string) { 31 | const keypair = solanaWeb3.Keypair.fromSecretKey(bs58.decode(privateKey)); 32 | const connection = new solanaWeb3.Connection(solanaRpcUrl, "confirmed"); 33 | return await sendAndConfirmTransaction(connection, transaction, [keypair]); 34 | } 35 | 36 | main() 37 | .then(() => { 38 | console.log("Done"); 39 | }) 40 | .catch((e) => { 41 | console.error(e); 42 | }); 43 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/solana/sol-build-deposit-tx.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault, RawPoolSolanaTransaction } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | import solanaWeb3, { sendAndConfirmTransaction, Transaction } from "@solana/web3.js"; 6 | import bs58 from "bs58"; 7 | 8 | dotenv.config({ path: ".env" }); 9 | 10 | const main = async () => { 11 | // sender address 12 | const accountAddress = getEnvVar("SOL_ACCOUNT_ADDRESS"); 13 | const privateKey = getEnvVar("SOL_PRIVATE_KEY"); 14 | const tokenAddress = getEnvVar("SOL_TOKEN_ADDRESS"); 15 | 16 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 17 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 18 | 19 | const oneToken = "1"; 20 | // create deposit raw transaction 21 | const transaction = (await sdk.pool.rawTxBuilder.deposit({ 22 | amount: oneToken, 23 | accountAddress: accountAddress, 24 | token: tokenInfo, 25 | })) as RawPoolSolanaTransaction; 26 | 27 | const tx = await sendRawTransaction(transaction, privateKey, ensure(nodeRpcUrlsDefault.SOL)); 28 | 29 | console.log("Token deposit:", tx); 30 | }; 31 | 32 | async function sendRawTransaction(transaction: Transaction, privateKey: string, solanaRpcUrl: string) { 33 | const keypair = solanaWeb3.Keypair.fromSecretKey(bs58.decode(privateKey)); 34 | const connection = new solanaWeb3.Connection(solanaRpcUrl, "confirmed"); 35 | return await sendAndConfirmTransaction(connection, transaction, [keypair]); 36 | } 37 | 38 | main() 39 | .then(() => { 40 | console.log("Done"); 41 | }) 42 | .catch((e) => { 43 | console.error(e); 44 | }); 45 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/solana/sol-build-withdraw-tx.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault, RawPoolSolanaTransaction } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | import solanaWeb3, { sendAndConfirmTransaction, Transaction } from "@solana/web3.js"; 6 | import bs58 from "bs58"; 7 | dotenv.config({ path: ".env" }); 8 | 9 | const main = async () => { 10 | // sender address 11 | const accountAddress = getEnvVar("SOL_ACCOUNT_ADDRESS"); 12 | const privateKey = getEnvVar("SOL_PRIVATE_KEY"); 13 | const tokenAddress = getEnvVar("SOL_TOKEN_ADDRESS"); 14 | 15 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 16 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 17 | 18 | const halfToken = "0.5"; 19 | // create withdraw raw transaction 20 | const transaction = (await sdk.pool.rawTxBuilder.withdraw({ 21 | amount: halfToken, 22 | accountAddress: accountAddress, 23 | token: tokenInfo, 24 | })) as RawPoolSolanaTransaction; 25 | 26 | const tx = await sendRawTransaction(transaction, privateKey, ensure(nodeRpcUrlsDefault.SOL)); 27 | 28 | console.log("Token withdraw:", tx); 29 | }; 30 | 31 | async function sendRawTransaction(transaction: Transaction, privateKey: string, solanaRpcUrl: string) { 32 | const keypair = solanaWeb3.Keypair.fromSecretKey(bs58.decode(privateKey)); 33 | const connection = new solanaWeb3.Connection(solanaRpcUrl, "confirmed"); 34 | return await sendAndConfirmTransaction(connection, transaction, [keypair]); 35 | } 36 | 37 | main() 38 | .then(() => { 39 | console.log("Done"); 40 | }) 41 | .catch((e) => { 42 | console.error(e); 43 | }); 44 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/sui/get-amount-to-be-withdrawn.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | dotenv.config({ path: ".env" }); 6 | 7 | const main = async () => { 8 | const tokenAddress = getEnvVar("SUI_TOKEN_ADDRESS"); 9 | const accountAddress = getEnvVar("SUI_ACCOUNT_ADDRESS"); 10 | 11 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 12 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.originTokenAddress === tokenAddress)); 13 | 14 | const halfToken = "0.5"; 15 | const estimatedAmount = await sdk.pool.getAmountToBeWithdrawn(halfToken, accountAddress, tokenInfo); 16 | console.log("If you withdraw %d LP tokens, then %d will be received", halfToken, estimatedAmount); 17 | }; 18 | 19 | main() 20 | .then(() => { 21 | console.log("Done"); 22 | }) 23 | .catch((e) => { 24 | console.error(e); 25 | }); 26 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/sui/get-liquidity-balance.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | 6 | dotenv.config({ path: ".env" }); 7 | 8 | const main = async () => { 9 | const tokenAddress = getEnvVar("SUI_TOKEN_ADDRESS"); 10 | const accountAddress = getEnvVar("SUI_ACCOUNT_ADDRESS"); 11 | 12 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 13 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.originTokenAddress === tokenAddress)); 14 | 15 | const userBalanceInfo = await sdk.pool.getUserBalanceInfo(accountAddress, tokenInfo); 16 | const poolInfo = await sdk.pool.getPoolInfoFromChain(tokenInfo); 17 | 18 | console.log("User balance: ", userBalanceInfo.userLiquidity); 19 | console.log("User rewards: ", userBalanceInfo.earned(poolInfo, tokenInfo.decimals)); 20 | console.log("PoolInfo APR: ", sdk.aprInPercents(tokenInfo.apr7d)); 21 | }; 22 | 23 | main() 24 | .then(() => { 25 | console.log("Done"); 26 | }) 27 | .catch((e) => { 28 | console.error(e); 29 | }); 30 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/sui/get-lp-amount-on-deposit.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | 6 | dotenv.config({ path: ".env" }); 7 | 8 | const main = async () => { 9 | const tokenAddress = getEnvVar("SUI_TOKEN_ADDRESS"); 10 | 11 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 12 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.originTokenAddress === tokenAddress)); 13 | 14 | const oneToken = "1"; 15 | const estimatedAmount = await sdk.pool.getAmountToBeDeposited(oneToken, tokenInfo); 16 | console.log("If you send %d , then %d of LP tokens will be deposited", oneToken, estimatedAmount); 17 | }; 18 | 19 | main() 20 | .then(() => { 21 | console.log("Done"); 22 | }) 23 | .catch((e) => { 24 | console.error(e); 25 | }); 26 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/sui/sui-build-claim-rewards-tx.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault, RawSuiTransaction } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | import { sendSuiRawTransaction } from "../../../utils/sui"; 6 | 7 | dotenv.config({ path: ".env" }); 8 | 9 | const main = async () => { 10 | // sender address 11 | const accountAddress = getEnvVar("SUI_ACCOUNT_ADDRESS"); 12 | const tokenAddress = getEnvVar("SUI_TOKEN_ADDRESS"); 13 | 14 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 15 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.originTokenAddress === tokenAddress)); 16 | 17 | // create claim rewards raw transaction 18 | const xdr = (await sdk.pool.rawTxBuilder.claimRewards({ 19 | accountAddress: accountAddress, 20 | token: tokenInfo, 21 | })) as RawSuiTransaction; 22 | 23 | const txReceipt = await sendSuiRawTransaction(xdr); 24 | console.log("Token claimRewards:", txReceipt); 25 | }; 26 | 27 | main() 28 | .then(() => { 29 | console.log("Done"); 30 | }) 31 | .catch((e) => { 32 | console.error(e); 33 | }); 34 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/sui/sui-build-deposit-tx.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault, RawSuiTransaction } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | import { sendSuiRawTransaction } from "../../../utils/sui"; 6 | 7 | dotenv.config({ path: ".env" }); 8 | 9 | const main = async () => { 10 | // sender address 11 | const accountAddress = getEnvVar("SUI_ACCOUNT_ADDRESS"); 12 | const tokenAddress = getEnvVar("SUI_TOKEN_ADDRESS"); 13 | 14 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 15 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.originTokenAddress === tokenAddress)); 16 | 17 | const oneToken = "1"; 18 | // create deposit raw transaction 19 | const xdr = (await sdk.pool.rawTxBuilder.deposit({ 20 | amount: oneToken, 21 | accountAddress: accountAddress, 22 | token: tokenInfo, 23 | })) as RawSuiTransaction; 24 | 25 | const txReceipt = await sendSuiRawTransaction(xdr); 26 | console.log("Token deposit:", txReceipt); 27 | }; 28 | 29 | main() 30 | .then(() => { 31 | console.log("Done"); 32 | }) 33 | .catch((e) => { 34 | console.error(e); 35 | }); 36 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/sui/sui-build-withdraw-tx.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault, RawSuiTransaction } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | import { sendSuiRawTransaction } from "../../../utils/sui"; 6 | 7 | dotenv.config({ path: ".env" }); 8 | 9 | const main = async () => { 10 | // sender address 11 | const accountAddress = getEnvVar("SUI_ACCOUNT_ADDRESS"); 12 | const tokenAddress = getEnvVar("SUI_TOKEN_ADDRESS"); 13 | 14 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 15 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.originTokenAddress === tokenAddress)); 16 | 17 | const halfToken = "0.5"; 18 | // create withdraw raw transaction 19 | const xdr = (await sdk.pool.rawTxBuilder.withdraw({ 20 | amount: halfToken, 21 | accountAddress: accountAddress, 22 | token: tokenInfo, 23 | })) as RawSuiTransaction; 24 | 25 | const txReceipt = await sendSuiRawTransaction(xdr); 26 | console.log("Token withdraw:", txReceipt); 27 | }; 28 | 29 | main() 30 | .then(() => { 31 | console.log("Done"); 32 | }) 33 | .catch((e) => { 34 | console.error(e); 35 | }); 36 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/trx/get-amount-to-be-withdrawn.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | dotenv.config({ path: ".env" }); 6 | 7 | const main = async () => { 8 | const tokenAddress = getEnvVar("TRX_TOKEN_ADDRESS"); 9 | const accountAddress = getEnvVar("TRX_ACCOUNT_ADDRESS"); 10 | 11 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 12 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 13 | 14 | const halfToken = "0.5"; 15 | const estimatedAmount = await sdk.pool.getAmountToBeWithdrawn(halfToken, accountAddress, tokenInfo); 16 | console.log("If you withdraw %d LP tokens, then %d will be received", halfToken, estimatedAmount); 17 | }; 18 | 19 | main() 20 | .then(() => { 21 | console.log("Done"); 22 | }) 23 | .catch((e) => { 24 | console.error(e); 25 | }); 26 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/trx/get-liquidity-balance.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | 4 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 5 | import { ensure } from "../../../utils/utils"; 6 | dotenv.config({ path: ".env" }); 7 | 8 | const main = async () => { 9 | const tokenAddress = getEnvVar("TRX_TOKEN_ADDRESS"); 10 | const accountAddress = getEnvVar("TRX_ACCOUNT_ADDRESS"); 11 | 12 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 13 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 14 | 15 | const userBalanceInfo = await sdk.pool.getUserBalanceInfo(accountAddress, tokenInfo); 16 | const poolInfo = await sdk.pool.getPoolInfoFromChain(tokenInfo); 17 | 18 | console.log("Tron User balance: ", userBalanceInfo.userLiquidity); 19 | console.log("Tron User rewards: ", userBalanceInfo.earned(poolInfo, tokenInfo.decimals)); 20 | console.log("Tron PoolInfo APR: ", sdk.aprInPercents(tokenInfo.apr7d)); 21 | }; 22 | 23 | main() 24 | .then(() => { 25 | console.log("Done"); 26 | }) 27 | .catch((e) => { 28 | console.error(e); 29 | }); 30 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/trx/get-lp-amount-on-deposit.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | dotenv.config({ path: ".env" }); 6 | 7 | const main = async () => { 8 | const tokenAddress = getEnvVar("TRX_TOKEN_ADDRESS"); 9 | 10 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 11 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 12 | 13 | const oneToken = "1"; 14 | const estimatedAmount = await sdk.pool.getAmountToBeDeposited(oneToken, tokenInfo); 15 | 16 | console.log("If you send %d , then %d of LP tokens will be deposited", oneToken, estimatedAmount); 17 | }; 18 | 19 | main() 20 | .then(() => { 21 | console.log("Done"); 22 | }) 23 | .catch((e) => { 24 | console.error(e); 25 | }); 26 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/trx/trx-build-claim-rewards-tx.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault, RawTronTransaction } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | import { sendTrxRawTransaction } from "../../../utils/tronWeb"; 6 | 7 | dotenv.config({ path: ".env" }); 8 | 9 | const main = async () => { 10 | // sender address 11 | const accountAddress = getEnvVar("TRX_ACCOUNT_ADDRESS"); 12 | const tokenAddress = getEnvVar("TRX_TOKEN_ADDRESS"); 13 | 14 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 15 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 16 | 17 | // create claim rewards raw transaction 18 | const rawTransactionDeposit = (await sdk.pool.rawTxBuilder.claimRewards({ 19 | accountAddress: accountAddress, 20 | token: tokenInfo, 21 | })) as RawTronTransaction; 22 | 23 | const txReceipt = await sendTrxRawTransaction(rawTransactionDeposit); 24 | console.log("Token claim rewards txReceipt:", txReceipt); 25 | }; 26 | 27 | main() 28 | .then(() => { 29 | console.log("Done"); 30 | }) 31 | .catch((e) => { 32 | console.error(e); 33 | }); 34 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/trx/trx-build-deposit-tx.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault, RawTronTransaction } from "@allbridge/bridge-core-sdk"; 4 | import { ensure } from "../../../utils/utils"; 5 | import { sendTrxRawTransaction } from "../../../utils/tronWeb"; 6 | 7 | dotenv.config({ path: ".env" }); 8 | 9 | const main = async () => { 10 | // sender address 11 | const accountAddress = getEnvVar("TRX_ACCOUNT_ADDRESS"); 12 | const tokenAddress = getEnvVar("TRX_TOKEN_ADDRESS"); 13 | 14 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 15 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 16 | 17 | const oneToken = "1"; 18 | // create deposit raw transaction 19 | const rawTransactionDeposit = (await sdk.pool.rawTxBuilder.deposit({ 20 | amount: oneToken, 21 | accountAddress: accountAddress, 22 | token: tokenInfo, 23 | })) as RawTronTransaction; 24 | 25 | const txReceipt = await sendTrxRawTransaction(rawTransactionDeposit); 26 | console.log("Token deposit txReceipt:", txReceipt); 27 | }; 28 | 29 | main() 30 | .then(() => { 31 | console.log("Done"); 32 | }) 33 | .catch((e) => { 34 | console.error(e); 35 | }); 36 | -------------------------------------------------------------------------------- /examples/src/examples/liquidity-pool/trx/trx-build-withdraw-tx.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | import { getEnvVar } from "../../../utils/env"; 3 | import { ensure } from "../../../utils/utils"; 4 | import { AllbridgeCoreSdk, nodeRpcUrlsDefault, RawTronTransaction } from "@allbridge/bridge-core-sdk"; 5 | import { sendTrxRawTransaction } from "../../../utils/tronWeb"; 6 | 7 | dotenv.config({ path: ".env" }); 8 | 9 | const main = async () => { 10 | // sender address 11 | const accountAddress = getEnvVar("TRX_ACCOUNT_ADDRESS"); 12 | const tokenAddress = getEnvVar("TRX_TOKEN_ADDRESS"); 13 | 14 | const sdk = new AllbridgeCoreSdk(nodeRpcUrlsDefault); 15 | const tokenInfo = ensure((await sdk.tokens()).find((tokenInfo) => tokenInfo.tokenAddress === tokenAddress)); 16 | 17 | const halfToken = "0.5"; 18 | // create withdraw raw transaction 19 | const rawTransactionDeposit = (await sdk.pool.rawTxBuilder.withdraw({ 20 | amount: halfToken, 21 | accountAddress: accountAddress, 22 | token: tokenInfo, 23 | })) as RawTronTransaction; 24 | 25 | const txReceipt = await sendTrxRawTransaction(rawTransactionDeposit); 26 | console.log("Token withdraw txReceipt:", txReceipt); 27 | }; 28 | 29 | main() 30 | .then(() => { 31 | console.log("Done"); 32 | }) 33 | .catch((e) => { 34 | console.error(e); 35 | }); 36 | -------------------------------------------------------------------------------- /examples/src/utils/env.ts: -------------------------------------------------------------------------------- 1 | export function getEnvVar(name: string, defaultValue?: string): string { 2 | const value = process.env[name]; 3 | if (!value) { 4 | if (defaultValue) { 5 | return defaultValue; 6 | } else { 7 | throw Error(`Environment variable ${name} is not defined!`); 8 | } 9 | } 10 | return value; 11 | } 12 | -------------------------------------------------------------------------------- /examples/src/utils/sui.ts: -------------------------------------------------------------------------------- 1 | import { SuiClient, SuiTransactionBlockResponse } from "@mysten/sui/client"; 2 | import { getEnvVar } from "./env"; 3 | import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"; 4 | import { Transaction } from "@mysten/sui/transactions"; 5 | 6 | export async function sendSuiRawTransaction(xdr: string): Promise { 7 | const tx = Transaction.from(xdr); 8 | 9 | const client = new SuiClient({ 10 | url: getEnvVar("SUI_PROVIDER_URL"), 11 | }); 12 | const signer = Ed25519Keypair.fromSecretKey(getEnvVar("SUI_PRIVATE_KEY")); 13 | const txBlockResponse = await client.signAndExecuteTransaction({ 14 | signer: signer, 15 | transaction: tx, 16 | }); 17 | 18 | return await client.waitForTransaction({ 19 | digest: txBlockResponse.digest, 20 | pollInterval: 100, 21 | options: { 22 | showEffects: true, 23 | showEvents: true, 24 | }, 25 | }); 26 | } 27 | -------------------------------------------------------------------------------- /examples/src/utils/tronWeb.ts: -------------------------------------------------------------------------------- 1 | import { RawTronTransaction } from "@allbridge/bridge-core-sdk"; 2 | import { getEnvVar } from "./env"; 3 | // @ts-expect-error import tron 4 | import TronWeb from "tronweb"; 5 | 6 | export async function sendTrxRawTransaction(rawTransaction: RawTronTransaction) { 7 | // configure TronWeb 8 | const tronWeb = new TronWeb( 9 | getEnvVar("TRONWEB_PROVIDER_URL"), 10 | getEnvVar("TRONWEB_PROVIDER_URL"), 11 | getEnvVar("TRONWEB_PROVIDER_URL"), 12 | getEnvVar("TRX_PRIVATE_KEY") 13 | ); 14 | 15 | const signedTx = await tronWeb.trx.sign(rawTransaction); 16 | if (!signedTx.signature) { 17 | throw Error("Transaction was not signed properly"); 18 | } 19 | // Broadcasting the transaction 20 | return tronWeb.trx.sendRawTransaction(signedTx); 21 | } 22 | -------------------------------------------------------------------------------- /examples/src/utils/utils.ts: -------------------------------------------------------------------------------- 1 | export function ensure(argument: T | undefined | null): T { 2 | if (argument === undefined || argument === null) { 3 | throw new TypeError("This value was promised to be there."); 4 | } 5 | 6 | return argument; 7 | } 8 | -------------------------------------------------------------------------------- /examples/src/utils/web3.ts: -------------------------------------------------------------------------------- 1 | import Web3 from "web3"; 2 | import { TransactionConfig } from "web3-core"; 3 | import { getEnvVar } from "./env"; 4 | 5 | export async function sendEvmRawTransaction(rawTransaction: TransactionConfig) { 6 | // configure web3 7 | const web3 = new Web3(getEnvVar("WEB3_PROVIDER_URL")); 8 | const account = web3.eth.accounts.privateKeyToAccount(getEnvVar("ETH_PRIVATE_KEY")); 9 | web3.eth.accounts.wallet.add(account); 10 | 11 | if (rawTransaction.from === undefined) { 12 | throw Error("rawTransaction.from is undefined"); 13 | } 14 | const gasLimit = await web3.eth.estimateGas(rawTransaction); 15 | 16 | const signedTx = await account.signTransaction({ 17 | ...rawTransaction, 18 | gas: gasLimit, 19 | }); 20 | if (signedTx.rawTransaction === undefined) { 21 | throw Error("signedTx.rawTransaction is undefined"); 22 | } 23 | console.log("Sending transaction", signedTx.transactionHash); 24 | return web3.eth.sendSignedTransaction(signedTx.rawTransaction); 25 | } 26 | -------------------------------------------------------------------------------- /examples/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2023", 4 | "module": "commonjs", 5 | "lib": [ 6 | "es6" 7 | ], 8 | "allowJs": true, 9 | "outDir": "build", 10 | "rootDir": "src", 11 | "strict": true, 12 | "esModuleInterop": true, 13 | "types": [ 14 | "node" 15 | ], 16 | "skipLibCheck": true, 17 | "resolveJsonModule": true 18 | }, 19 | "include": ["./src/**/*.ts"], 20 | "exclude": ["./src/**/__tests__"] 21 | } 22 | -------------------------------------------------------------------------------- /firebase.json: -------------------------------------------------------------------------------- 1 | { 2 | "hosting": { 3 | "public": "docs", 4 | "ignore": [ 5 | "firebase.json", 6 | "**/.*", 7 | "**/node_modules/**" 8 | ] 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /scripts/build.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import { build as esbuild, BuildOptions } from "esbuild"; 3 | import {polyfillNode} from "esbuild-plugin-polyfill-node"; 4 | import externalizeAllPackagesExcept from 'esbuild-plugin-noexternal'; 5 | 6 | const baseConfig: BuildOptions = { 7 | nodePaths: [path.join(__dirname, "../src")], 8 | sourcemap: true, 9 | bundle: true, 10 | minify: true, 11 | }; 12 | 13 | async function main() { 14 | await esbuild({ 15 | ...baseConfig, 16 | platform: "node", 17 | target: "esnext", 18 | format: "cjs", 19 | plugins: [externalizeAllPackagesExcept(['timed-cache'])], 20 | outdir: path.join(__dirname, "../dist/cjs"), 21 | entryPoints: [path.join(__dirname, "../src/index.ts")], 22 | }); 23 | 24 | await esbuild({ 25 | ...baseConfig, 26 | platform: "node", 27 | target: "esnext", 28 | format: "esm", 29 | packages: 'external', 30 | outdir: path.join(__dirname, "../dist/esm"), 31 | entryPoints: [path.join(__dirname, "../src/index.ts")], 32 | }); 33 | 34 | // browser 35 | await esbuild({ 36 | ...baseConfig, 37 | format: "esm", 38 | outdir: path.join(__dirname, "../dist/browser"), 39 | entryPoints: [path.join(__dirname, "../src/index.ts")], 40 | packages: 'external', 41 | plugins: [ 42 | polyfillNode({ 43 | // Options (optional) 44 | }), 45 | ], 46 | }); 47 | } 48 | 49 | if (require.main === module) { 50 | main(); 51 | } 52 | -------------------------------------------------------------------------------- /scripts/clean.ts: -------------------------------------------------------------------------------- 1 | import fs from "fs/promises"; 2 | import path from "path"; 3 | 4 | async function main() { 5 | await Promise.all([rmrf("dist"), rmrf("coverage"), rmrf(".nyc_output")]); 6 | } 7 | 8 | async function rmrf(pathFromRoot: string): Promise { 9 | await fs.rm(path.join(__dirname, "../", pathFromRoot), { 10 | recursive: true, 11 | force: true, 12 | }); 13 | } 14 | 15 | if (require.main === module) { 16 | main(); 17 | } 18 | -------------------------------------------------------------------------------- /src/__tests__/client/core-api/core-api-mapper.test.ts: -------------------------------------------------------------------------------- 1 | import { mapChainDetailsResponseToChainDetailsMap } from "../../../client/core-api/core-api-mapper"; 2 | import { ChainDetailsResponse } from "../../../client/core-api/core-api.model"; 3 | import { ChainDetailsWithTokens, ChainDetailsMapWithFlags } from "../../../tokens-info"; 4 | import chainDetailsGRL from "../../data/tokens-info/ChainDetails-GRL.json"; 5 | import tokensGroupedByChain from "../../data/tokens-info/ChainDetailsMapWithFlags.json"; 6 | import tokensInfo from "../../mock/core-api/token-info.json"; 7 | import { initChainsWithTestnet } from "../../mock/utils"; 8 | 9 | const expectedTokensGroupedByChain = tokensGroupedByChain as unknown as ChainDetailsMapWithFlags; 10 | 11 | initChainsWithTestnet(); 12 | 13 | describe("Core API Mapper", () => { 14 | describe("given ChainDetailsMapDTO", () => { 15 | const dto: ChainDetailsResponse = tokensInfo as unknown as ChainDetailsResponse; 16 | 17 | describe("mapChainDetailsMapFromDTO", () => { 18 | it("returns ChainDetailsMap object", () => { 19 | const actual = mapChainDetailsResponseToChainDetailsMap(dto); 20 | expect(actual).toEqual(expectedTokensGroupedByChain); 21 | }); 22 | }); 23 | }); 24 | 25 | describe("given ChainDetailsMapDTO with unknown chain", () => { 26 | describe("mapChainDetailsMapFromDTO", () => { 27 | it("returns empty ChainDetailsMap object", () => { 28 | const chainDetails = chainDetailsGRL as unknown as ChainDetailsWithTokens; 29 | const dto = { 30 | UNKNOWN: chainDetails, 31 | } as unknown as ChainDetailsResponse; 32 | const actual = mapChainDetailsResponseToChainDetailsMap(dto); 33 | expect(actual).toEqual({}); 34 | }); 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /src/__tests__/data/pool-info/pool-info-GRL.json: -------------------------------------------------------------------------------- 1 | { 2 | "aValue": "20", 3 | "dValue": "200000001", 4 | "imbalance": "469.7485", 5 | "tokenBalance": "100469776", 6 | "vUsdBalance": "99530279", 7 | "totalLpAmount": "100000000", 8 | "accRewardPerShareP": "61452639838135255812251932", 9 | "p": 52 10 | } 11 | -------------------------------------------------------------------------------- /src/__tests__/data/pool-info/pool-info-map.json: -------------------------------------------------------------------------------- 1 | { 2 | "GRL_0x727e10f9E750C922bf9dee7620B58033F566b34F": { 3 | "aValue": "20", 4 | "dValue": "200000001", 5 | "imbalance": "469.7485", 6 | "tokenBalance": "100469776", 7 | "vUsdBalance": "99530279", 8 | "totalLpAmount": "100000000", 9 | "accRewardPerShareP": "61452639838135255812251932", 10 | "p": 52 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/__tests__/data/tokens-info/ChainDetails-GRL.json: -------------------------------------------------------------------------------- 1 | { 2 | "chainSymbol": "GRL", 3 | "chainType": "EVM", 4 | "chainId": "0x5", 5 | "name": "Goerli", 6 | "allbridgeChainId": 2, 7 | "bridgeAddress": "0xba285A8F52601EabCc769706FcBDe2645aa0AF18", 8 | "confirmations": 5, 9 | "tokens": [ 10 | { 11 | "name": "Yaroslav Stable Token", 12 | "poolAddress": "0xEc46d2b11e68A31026673D63B345B889AB37C0Bc", 13 | "tokenAddress": "0xDdaC3cb57DEa3fBEFF4997d78215535Eb5787117", 14 | "decimals": 18, 15 | "symbol": "YUSD", 16 | "feeShare": "0.003", 17 | "apr": "0.1", 18 | "lpRate": "1.000000275", 19 | "chainSymbol": "GRL", 20 | "chainId": "0x5", 21 | "allbridgeChainId": 2, 22 | "bridgeAddress": "0xba285A8F52601EabCc769706FcBDe2645aa0AF18", 23 | "confirmations": 5, 24 | "chainName": "Goerli" 25 | }, 26 | { 27 | "name": "YARO Stable", 28 | "poolAddress": "0x727e10f9E750C922bf9dee7620B58033F566b34F", 29 | "tokenAddress": "0xC7DBC4A896b34B7a10ddA2ef72052145A9122F43", 30 | "decimals": 18, 31 | "symbol": "YARO", 32 | "feeShare": "0.003", 33 | "apr": "0.1", 34 | "lpRate": "1.00000003", 35 | "chainSymbol": "GRL", 36 | "chainId": "0x5", 37 | "allbridgeChainId": 2, 38 | "bridgeAddress": "0xba285A8F52601EabCc769706FcBDe2645aa0AF18", 39 | "confirmations": 5, 40 | "chainName": "Goerli" 41 | } 42 | ] 43 | } 44 | -------------------------------------------------------------------------------- /src/__tests__/data/tokens-info/ChainDetailsMap-ETH-USDT.json: -------------------------------------------------------------------------------- 1 | { 2 | "ETH": { 3 | "chainSymbol": "ETH", 4 | "chainId": "0x1", 5 | "name": "Ethereum", 6 | "chainType": "EVM", 7 | "allbridgeChainId": 1, 8 | "bridgeAddress": "0xA314330482f325D38A83B492EF6B006224a3bea9", 9 | "transferTime": { 10 | "BSC": { 11 | "1": 1020000, 12 | "2": 780000 13 | }, 14 | "POL": { 15 | "1": 1080000, 16 | "2": 600000 17 | }, 18 | "TRX": { 19 | "1": 1020000, 20 | "2": null 21 | }, 22 | "SOL": { 23 | "1": 1020000, 24 | "2": 27900000 25 | } 26 | }, 27 | "confirmations": 80, 28 | "tokens": [ 29 | { 30 | "name": "Tether USD", 31 | "poolAddress": "0xB827b15adA62D78F5cb90243bc4755cf4B9d1B0e", 32 | "tokenAddress": "0xdAC17F958D2ee523a2206206994597C13D831ec7", 33 | "decimals": 6, 34 | "symbol": "USDT", 35 | "feeShare": "0.0015", 36 | "apr": "0.08042120433199476518", 37 | "lpRate": "1.00005909444514774664", 38 | "chainSymbol": "ETH", 39 | "chainId": "0x1", 40 | "chainType": "EVM", 41 | "allbridgeChainId": 1, 42 | "bridgeAddress": "0xA314330482f325D38A83B492EF6B006224a3bea9", 43 | "transferTime": { 44 | "BSC": { 45 | "1": 1020000, 46 | "2": 780000 47 | }, 48 | "POL": { 49 | "1": 1080000, 50 | "2": 600000 51 | }, 52 | "TRX": { 53 | "1": 1020000, 54 | "2": null 55 | }, 56 | "SOL": { 57 | "1": 1020000, 58 | "2": 27900000 59 | } 60 | }, 61 | "confirmations": 80, 62 | "chainName": "Ethereum", 63 | "flags": { 64 | "swap": true, 65 | "pool": true 66 | } 67 | } 68 | ] 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/__tests__/data/tokens-info/TokenInfoWithChainDetails-GRL.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "Yaroslav Stable Token", 4 | "poolAddress": "0xEc46d2b11e68A31026673D63B345B889AB37C0Bc", 5 | "tokenAddress": "0xDdaC3cb57DEa3fBEFF4997d78215535Eb5787117", 6 | "decimals": 18, 7 | "symbol": "YUSD", 8 | "feeShare": "0.003", 9 | "apr": "0.1", 10 | "lpRate": "1.000000275", 11 | "chainSymbol": "GRL", 12 | "chainType": "EVM", 13 | "chainId": "0x5", 14 | "allbridgeChainId": 2, 15 | "bridgeAddress": "0xba285A8F52601EabCc769706FcBDe2645aa0AF18", 16 | "transferTime": { 17 | "ETH": { 18 | "1": 120000, 19 | "2": 120000 20 | }, 21 | "POL": { 22 | "1": 120000, 23 | "2": 600000 24 | }, 25 | "SOL": { 26 | "1": 120000, 27 | "2": 40140000 28 | }, 29 | "TRX": { 30 | "1": 120000, 31 | "2": null 32 | } 33 | }, 34 | "txCostAmount": { 35 | "maxAmount": "9996610826601000", 36 | "swap": "2697498159559000", 37 | "transfer": "3332203608867000" 38 | }, 39 | "confirmations": 5, 40 | "chainName": "Goerli" 41 | }, 42 | { 43 | "name": "YARO Stable", 44 | "poolAddress": "0x727e10f9E750C922bf9dee7620B58033F566b34F", 45 | "tokenAddress": "0xC7DBC4A896b34B7a10ddA2ef72052145A9122F43", 46 | "decimals": 18, 47 | "symbol": "YARO", 48 | "feeShare": "0.003", 49 | "apr": "0.1", 50 | "lpRate": "1.00000003", 51 | "chainSymbol": "GRL", 52 | "chainType": "EVM", 53 | "chainId": "0x5", 54 | "allbridgeChainId": 2, 55 | "bridgeAddress": "0xba285A8F52601EabCc769706FcBDe2645aa0AF18", 56 | "transferTime": { 57 | "ETH": { 58 | "1": 120000, 59 | "2": 120000 60 | }, 61 | "POL": { 62 | "1": 120000, 63 | "2": 600000 64 | }, 65 | "SOL": { 66 | "1": 120000, 67 | "2": 40140000 68 | }, 69 | "TRX": { 70 | "1": 120000, 71 | "2": null 72 | } 73 | }, 74 | "txCostAmount": { 75 | "maxAmount": "9996610826601000", 76 | "swap": "2697498159559000", 77 | "transfer": "3332203608867000" 78 | }, 79 | "confirmations": 5, 80 | "chainName": "Goerli" 81 | } 82 | ] 83 | -------------------------------------------------------------------------------- /src/__tests__/data/tokens-info/TokenInfoWithChainDetails-SOL.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "Yaroslav token", 4 | "poolAddress": "6J9DNoMFciheb28kRbrtHjuKUgrfcAeq6AbSKNAJZJpE", 5 | "tokenAddress": "f4yhod6Y7jzVwFfy3iHDg49GAerFTrtp1Ac1ubdWx7L", 6 | "decimals": 9, 7 | "symbol": "YARO", 8 | "feeShare": "0.003", 9 | "apr": "51.739745973369194549", 10 | "lpRate": "0.99883244162470286635", 11 | "chainSymbol": "SOL", 12 | "chainType": "SOLANA", 13 | "allbridgeChainId": 5, 14 | "bridgeAddress": "DYUD8BuYGmtBeYbuWpEomGk9A6H2amyakSUw46vmQf8r", 15 | "transferTime": { 16 | "BSC": { 17 | "1": 120000, 18 | "2": 120000 19 | }, 20 | "ETH": { 21 | "1": 120000, 22 | "2": 120000 23 | }, 24 | "POL": { 25 | "1": 120000, 26 | "2": 120000 27 | }, 28 | "TRX": { 29 | "1": 120000, 30 | "2": null 31 | } 32 | }, 33 | "txCostAmount": { 34 | "maxAmount": "4731000", 35 | "swap": "1877000", 36 | "transfer": "1577000" 37 | }, 38 | "confirmations": 32, 39 | "chainName": "Solana" 40 | } 41 | ] 42 | -------------------------------------------------------------------------------- /src/__tests__/data/tokens-info/TokenInfoWithChainDetails-TRX.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "Yaro Stable", 4 | "poolAddress": "TT3oijZeGEjKYg4UNYhaxLdh76YVyMcjHd", 5 | "tokenAddress": "TS7Aqd75LprBKkPPxVLuZ8WWEyULEQFF1U", 6 | "decimals": 18, 7 | "symbol": "YARO", 8 | "feeShare": "0.003", 9 | "apr": "0", 10 | "lpRate": "1.00000007", 11 | "chainSymbol": "TRX", 12 | "chainType": "TRX", 13 | "allbridgeChainId": 4, 14 | "bridgeAddress": "TWU3j4etqPT4zSwABPrgmak3uXFSkxpPwM", 15 | "transferTime": { 16 | "BSC": { 17 | "1": 180000 18 | }, 19 | "ETH": { 20 | "1": 180000 21 | }, 22 | "POL": { 23 | "1": 180000 24 | }, 25 | "SOL": { 26 | "1": 180000 27 | } 28 | }, 29 | "confirmations": 20, 30 | "chainName": "Tron" 31 | } 32 | ] 33 | -------------------------------------------------------------------------------- /src/__tests__/data/transfer-status/TransferStatus.json: -------------------------------------------------------------------------------- 1 | { 2 | "txId": "dc634ffb1ed65e4e7d698f6f2a7713d09b185425c85d56175d28a408e54dd94f", 3 | "sourceChainSymbol": "TRX", 4 | "destinationChainSymbol": "GRL", 5 | "sendAmount": "5000000000000000", 6 | "sourceTokenAddress": "TS7Aqd75LprBKkPPxVLuZ8WWEyULEQFF1U", 7 | "destinationTokenAddress": "0xc7dbc4a896b34b7a10dda2ef72052145a9122f43", 8 | "senderAddress": "TSmGVvbW7jsZ26cJwfQHJWaDgCHnGax7SN", 9 | "recipientAddress": "0x68d7ed9cf9881427f1db299b90fd63ef805dd10d", 10 | "send": { 11 | "txId": "dc634ffb1ed65e4e7d698f6f2a7713d09b185425c85d56175d28a408e54dd94f", 12 | "sourceChainId": 4, 13 | "fee": "1000000000000000", 14 | "amount": "5000000000000000", 15 | "virtualAmount": "4", 16 | "bridgeContract": "TWU3j4etqPT4zSwABPrgmak3uXFSkxpPwM", 17 | "sender": "TSmGVvbW7jsZ26cJwfQHJWaDgCHnGax7SN", 18 | "recipient": "0x68d7ed9cf9881427f1db299b90fd63ef805dd10d", 19 | "destinationChainId": 2, 20 | "sourceTokenAddress": "TS7Aqd75LprBKkPPxVLuZ8WWEyULEQFF1U", 21 | "destinationTokenAddress": "0xc7dbc4a896b34b7a10dda2ef72052145a9122f43", 22 | "messenger": 1, 23 | "blockTime": 1666787397000.0, 24 | "blockId": "28606103", 25 | "hash": "0x04028f771a02cf60e091421192a3588eb692c551110a028a5dff9fe5988daa42", 26 | "confirmations": 10, 27 | "confirmationsNeeded": 10 28 | }, 29 | "signaturesCount": 2, 30 | "signaturesNeeded": 2, 31 | "receive": { 32 | "txId": "0x66f2f6d442cd4766448b4be5c323c31887ebdd12970fbc6266151ea0fee05cf9", 33 | "sourceChainId": 4, 34 | "fee": "12000000000000", 35 | "amount": "3988000000000000", 36 | "virtualAmount": "4", 37 | "bridgeContract": "0xba285A8F52601EabCc769706FcBDe2645aa0AF18", 38 | "sender": "TSmGVvbW7jsZ26cJwfQHJWaDgCHnGax7SN", 39 | "recipient": "0x68d7ed9cf9881427f1db299b90fd63ef805dd10d", 40 | "destinationChainId": 2, 41 | "sourceTokenAddress": "TS7Aqd75LprBKkPPxVLuZ8WWEyULEQFF1U", 42 | "destinationTokenAddress": "0xc7dbc4a896b34b7a10dda2ef72052145a9122f43", 43 | "messenger": 1, 44 | "blockTime": 1666787592000.0, 45 | "blockId": "7837413", 46 | "hash": "0x04028f771a02cf60e091421192a3588eb692c551110a028a5dff9fe5988daa42", 47 | "confirmations": 5, 48 | "confirmationsNeeded": 5 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/__tests__/mock/bridge/evm/evm-bridge.ts: -------------------------------------------------------------------------------- 1 | import { EvmBridgeService } from "../../../../services/bridge/evm"; 2 | import { EvmTokenService } from "../../../../services/token/evm"; 3 | 4 | export function mockEvmBridgeContract(methods: any) { 5 | const contractMocked = { 6 | methods: methods, 7 | }; 8 | 9 | const methodGetContract = jest.spyOn(EvmBridgeService.prototype as any, "getBridgeContract"); 10 | methodGetContract.mockImplementation(() => { 11 | return contractMocked; 12 | }); 13 | } 14 | 15 | export function mockEvmCctpBridgeContract(methods: any) { 16 | const contractMocked = { 17 | methods: methods, 18 | }; 19 | 20 | const methodGetContract = jest.spyOn(EvmBridgeService.prototype as any, "getCctpBridgeContract"); 21 | methodGetContract.mockImplementation(() => { 22 | return contractMocked; 23 | }); 24 | } 25 | 26 | export function mockEvmSendRawTransaction(transactionHash: string) { 27 | const methodSendRawTransaction = jest.spyOn(EvmBridgeService.prototype as any, "sendRawTransaction"); 28 | methodSendRawTransaction.mockImplementation(() => { 29 | return { txId: transactionHash }; 30 | }); 31 | return methodSendRawTransaction; 32 | } 33 | 34 | export function mockGetAllowanceByTokenAddress(allowance: string) { 35 | // prettier-ignore 36 | return jest.spyOn(EvmTokenService.prototype, "getAllowanceByTokenAddress") 37 | /* eslint-disable-next-line @typescript-eslint/require-await */ 38 | .mockImplementation(async () => { 39 | return allowance; 40 | }); 41 | } 42 | -------------------------------------------------------------------------------- /src/__tests__/mock/bridge/index.ts: -------------------------------------------------------------------------------- 1 | import { BridgeService } from "../../../services/bridge"; 2 | import { ChainBridgeService } from "../../../services/bridge/models"; 3 | 4 | export function mockBridgeService_getBridge(bridge: ChainBridgeService) { 5 | const getBridge = jest.spyOn(BridgeService.prototype as any, "getBridge"); 6 | getBridge.mockImplementation(() => { 7 | return bridge; 8 | }); 9 | } 10 | -------------------------------------------------------------------------------- /src/__tests__/mock/bridge/models/bridge.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unused-vars */ 2 | import { ChainType } from "../../../../chains/chain.enums"; 3 | import { AllbridgeCoreClient, AllbridgeCoreClientWithPoolInfo } from "../../../../client/core-api/core-client-base"; 4 | import { 5 | ApproveParams, 6 | ChainBridgeService, 7 | GetAllowanceParamsDto, 8 | GetTokenBalanceParams, 9 | SendParams, 10 | SwapParams, 11 | TxSendParams, 12 | } from "../../../../services/bridge/models"; 13 | import { SolanaBridgeParams } from "../../../../services/bridge/sol"; 14 | import { RawTransaction, TransactionResponse } from "../../../../services/models"; 15 | 16 | export class TestBridge extends ChainBridgeService { 17 | constructor( 18 | public params: SolanaBridgeParams, 19 | public api: AllbridgeCoreClient, 20 | public chainType: ChainType 21 | ) { 22 | super(); 23 | } 24 | 25 | approve(approveData: ApproveParams): Promise { 26 | // @ts-expect-error 27 | return Promise.resolve(undefined); 28 | } 29 | 30 | buildRawTransactionApprove(approveData: ApproveParams): Promise { 31 | // @ts-expect-error 32 | return Promise.resolve(undefined); 33 | } 34 | 35 | buildRawTransactionSend(params: SendParams): Promise { 36 | // @ts-expect-error 37 | return Promise.resolve(undefined); 38 | } 39 | 40 | getAllowance(params: GetAllowanceParamsDto): Promise { 41 | return Promise.resolve(""); 42 | } 43 | 44 | getTokenBalance(params: GetTokenBalanceParams): Promise { 45 | return Promise.resolve(""); 46 | } 47 | 48 | sendTx(params: TxSendParams): Promise { 49 | // @ts-expect-error 50 | return Promise.resolve(undefined); 51 | } 52 | 53 | buildRawTransactionSwap(params: SwapParams): Promise { 54 | return Promise.resolve(""); 55 | } 56 | 57 | send(params: SendParams): Promise { 58 | return Promise.resolve({ txId: "txId" }); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/__tests__/mock/bridge/trx/trx-bridge.ts: -------------------------------------------------------------------------------- 1 | import { TronBridgeService } from "../../../../services/bridge/trx"; 2 | export function mockTronBridgeContract(methods: any) { 3 | const bridgeMocked = { 4 | methods: methods, 5 | }; 6 | 7 | const getContract = jest.spyOn(TronBridgeService.prototype as any, "getContract"); 8 | getContract.mockImplementation(() => { 9 | return bridgeMocked; 10 | }); 11 | } 12 | -------------------------------------------------------------------------------- /src/__tests__/mock/bridge/utils.ts: -------------------------------------------------------------------------------- 1 | import * as UtilsModule from "../../../services/bridge/utils"; 2 | 3 | export function mockNonce() { 4 | const nonceSpy = jest.spyOn(UtilsModule, "getNonce"); 5 | const nonceBuffer = Buffer.from("3b1200153e110000001b006132000000000000000000362600611e000000070c", "hex"); 6 | nonceSpy.mockImplementation(() => nonceBuffer); 7 | return nonceBuffer; 8 | } 9 | 10 | export function mockNonceBigInt() { 11 | const nonceSpy = jest.spyOn(UtilsModule, "getNonceBigInt"); 12 | const nonceBigInt = BigInt("8983284342576706806"); 13 | nonceSpy.mockImplementation(() => nonceBigInt); 14 | return nonceBigInt; 15 | } 16 | -------------------------------------------------------------------------------- /src/__tests__/mock/core-api/pool-info.json: -------------------------------------------------------------------------------- 1 | { 2 | "GRL": { 3 | "0x727e10f9E750C922bf9dee7620B58033F566b34F": { 4 | "aValue": "20", 5 | "dValue": "200000001", 6 | "tokenBalance": "100469776", 7 | "vUsdBalance": "99530279", 8 | "totalLpAmount": "100000000", 9 | "accRewardPerShareP": "61452639838135255812251932", 10 | "p": 52 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/__tests__/mock/core-api/send-status.json: -------------------------------------------------------------------------------- 1 | { 2 | "txId": "dc634ffb1ed65e4e7d698f6f2a7713d09b185425c85d56175d28a408e54dd94f", 3 | "sourceChainSymbol": "TRX", 4 | "destinationChainSymbol": "GRL", 5 | "sendAmount": "5000000000000000", 6 | "sourceTokenAddress": "TS7Aqd75LprBKkPPxVLuZ8WWEyULEQFF1U", 7 | "destinationTokenAddress": "0xc7dbc4a896b34b7a10dda2ef72052145a9122f43", 8 | "senderAddress": "TSmGVvbW7jsZ26cJwfQHJWaDgCHnGax7SN", 9 | "recipientAddress": "0x68d7ed9cf9881427f1db299b90fd63ef805dd10d", 10 | "send": { 11 | "txId": "dc634ffb1ed65e4e7d698f6f2a7713d09b185425c85d56175d28a408e54dd94f", 12 | "sourceChainId": 4, 13 | "fee": "1000000000000000", 14 | "amount": "5000000000000000", 15 | "virtualAmount": "4", 16 | "bridgeContract": "TWU3j4etqPT4zSwABPrgmak3uXFSkxpPwM", 17 | "sender": "TSmGVvbW7jsZ26cJwfQHJWaDgCHnGax7SN", 18 | "recipient": "0x68d7ed9cf9881427f1db299b90fd63ef805dd10d", 19 | "destinationChainId": 2, 20 | "sourceTokenAddress": "TS7Aqd75LprBKkPPxVLuZ8WWEyULEQFF1U", 21 | "destinationTokenAddress": "0xc7dbc4a896b34b7a10dda2ef72052145a9122f43", 22 | "messenger": 1, 23 | "blockTime": 1666787397000.0, 24 | "blockId": "28606103", 25 | "hash": "0x04028f771a02cf60e091421192a3588eb692c551110a028a5dff9fe5988daa42", 26 | "confirmations": 10, 27 | "confirmationsNeeded": 10 28 | }, 29 | "signaturesCount": 2, 30 | "signaturesNeeded": 2, 31 | "receive": { 32 | "txId": "0x66f2f6d442cd4766448b4be5c323c31887ebdd12970fbc6266151ea0fee05cf9", 33 | "sourceChainId": 4, 34 | "fee": "12000000000000", 35 | "amount": "3988000000000000", 36 | "virtualAmount": "4", 37 | "bridgeContract": "0xba285A8F52601EabCc769706FcBDe2645aa0AF18", 38 | "sender": "TSmGVvbW7jsZ26cJwfQHJWaDgCHnGax7SN", 39 | "recipient": "0x68d7ed9cf9881427f1db299b90fd63ef805dd10d", 40 | "destinationChainId": 2, 41 | "sourceTokenAddress": "TS7Aqd75LprBKkPPxVLuZ8WWEyULEQFF1U", 42 | "destinationTokenAddress": "0xc7dbc4a896b34b7a10dda2ef72052145a9122f43", 43 | "messenger": 1, 44 | "blockTime": 1666787592000.0, 45 | "blockId": "7837413", 46 | "hash": "0x04028f771a02cf60e091421192a3588eb692c551110a028a5dff9fe5988daa42", 47 | "confirmations": 5, 48 | "confirmationsNeeded": 5 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/__tests__/mock/polygon-api/polygon-api.json: -------------------------------------------------------------------------------- 1 | { 2 | "safeLow": { 3 | "maxPriorityFee": 1.4333333322000001, 4 | "maxFee": 1.4333333482000001 5 | }, 6 | "standard": { 7 | "maxPriorityFee": 1.4333333323333333, 8 | "maxFee": 1.4333333483333333 9 | }, 10 | "fast": { 11 | "maxPriorityFee": 5.152222219, 12 | "maxFee": 5.152222235000001 13 | }, 14 | "estimatedBaseFee": 1.6e-8, 15 | "blockTime": 2, 16 | "blockNumber": 32076702 17 | } 18 | -------------------------------------------------------------------------------- /src/__tests__/mock/token/evm/evm-token.ts: -------------------------------------------------------------------------------- 1 | import { EvmTokenService } from "../../../../services/token/evm"; 2 | 3 | export function mockEvmTokenContract(methods: any) { 4 | const contractMocked = { 5 | methods: methods, 6 | }; 7 | 8 | const methodGetContract = jest.spyOn(EvmTokenService.prototype as any, "getERC20Contract"); 9 | methodGetContract.mockImplementation(() => { 10 | return contractMocked; 11 | }); 12 | } 13 | 14 | export function mockEvmSendRawTransaction(transactionHash: string) { 15 | const methodSendRawTransaction = jest.spyOn(EvmTokenService.prototype as any, "sendRawTransaction"); 16 | methodSendRawTransaction.mockImplementation(() => { 17 | return { txId: transactionHash }; 18 | }); 19 | return methodSendRawTransaction; 20 | } 21 | 22 | export function mockGetAllowanceByTokenAddress(allowance: string) { 23 | // prettier-ignore 24 | return jest.spyOn(EvmTokenService.prototype, "getAllowanceByTokenAddress") 25 | /* eslint-disable-next-line @typescript-eslint/require-await */ 26 | .mockImplementation(async () => { 27 | return allowance; 28 | }); 29 | } 30 | -------------------------------------------------------------------------------- /src/__tests__/mock/token/index.ts: -------------------------------------------------------------------------------- 1 | import { DefaultTokenService } from "../../../services/token"; 2 | 3 | export const mockedTokenBalance = "1234567890"; 4 | 5 | export function mockTokenService_getTokenBalance() { 6 | const tokenBalance = jest.spyOn(DefaultTokenService.prototype as any, "getTokenBalance"); 7 | tokenBalance.mockImplementation(() => { 8 | return mockedTokenBalance; 9 | }); 10 | } 11 | -------------------------------------------------------------------------------- /src/__tests__/mock/token/trx/trx-token.ts: -------------------------------------------------------------------------------- 1 | import { TronTokenService } from "../../../../services/token/trx"; 2 | 3 | export function mockTronTokenContract(methods: any) { 4 | const bridgeMocked = { 5 | methods: methods, 6 | }; 7 | 8 | const getContract = jest.spyOn(TronTokenService.prototype as any, "getContract"); 9 | getContract.mockImplementation(() => { 10 | return bridgeMocked; 11 | }); 12 | } 13 | 14 | export function mockTronVerifyTx() { 15 | const verifyTxMocked = jest.spyOn(TronTokenService.prototype as any, "verifyTx"); 16 | verifyTxMocked.mockImplementation(() => { 17 | return; 18 | }); 19 | return verifyTxMocked; 20 | } 21 | -------------------------------------------------------------------------------- /src/__tests__/mock/tron-web/trigger-smart-contract-approve.json: -------------------------------------------------------------------------------- 1 | { 2 | "result": { 3 | "result": true 4 | }, 5 | "transaction": { 6 | "visible": false, 7 | "txID": "7b0f5ba33c8984cee2068de5b5d2d94a6c1c3a70f702f578e8ab5aaf172aa483", 8 | "raw_data": { 9 | "contract": [ 10 | { 11 | "parameter": { 12 | "value": { 13 | "data": "095ea7b3000000000000000000000000bb58c8a419276287518cfb4c4c2347e25fa76dadffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 14 | "owner_address": "410bef513090bf616bc1a8bdfe81bb8726e2096edf", 15 | "contract_address": "41b10388f04f8331b59a02732cc1b6ac0d7045574b" 16 | }, 17 | "type_url": "type.googleapis.com/protocol.TriggerSmartContract" 18 | }, 19 | "type": "TriggerSmartContract" 20 | } 21 | ], 22 | "ref_block_bytes": "920b", 23 | "ref_block_hash": "c19f7616ec9f09e6", 24 | "expiration": 1667475183000, 25 | "fee_limit": 150000000, 26 | "timestamp": 1667475123693 27 | }, 28 | "raw_data_hex": "0a02920b2208c19f7616ec9f09e64098ab90eac3305aae01081f12a9010a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412740a15410bef513090bf616bc1a8bdfe81bb8726e2096edf121541b10388f04f8331b59a02732cc1b6ac0d7045574b2244095ea7b3000000000000000000000000bb58c8a419276287518cfb4c4c2347e25fa76dadffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff70eddb8ceac330900180a3c347" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/__tests__/mock/tron-web/trigger-smart-contract-claim-rewards.json: -------------------------------------------------------------------------------- 1 | { 2 | "result": { 3 | "result": true 4 | }, 5 | "transaction": { 6 | "visible": false, 7 | "txID": "68fb45f9453a4edee5211233bab57eb7dfbfc395623a55d401484a9ef610f1b5", 8 | "raw_data": { 9 | "contract": [ 10 | { 11 | "parameter": { 12 | "value": { 13 | "data": "372500ab", 14 | "owner_address": "41b83811067ab3a275ece28d3f8ec6875105ef9bae", 15 | "contract_address": "41bb58c8a419276287518cfb4c4c2347e25fa76dad" 16 | }, 17 | "type_url": "type.googleapis.com/protocol.TriggerSmartContract" 18 | }, 19 | "type": "TriggerSmartContract" 20 | } 21 | ], 22 | "ref_block_bytes": "de64", 23 | "ref_block_hash": "2a5656fc7c4f7093", 24 | "expiration": 1676484519000, 25 | "fee_limit": 150000000, 26 | "timestamp": 1676484465492 27 | }, 28 | "raw_data_hex": "0a02de6422082a5656fc7c4f709340d8c88eb2e5305a6d081f12690a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412340a1541b83811067ab3a275ece28d3f8ec6875105ef9bae121541bb58c8a419276287518cfb4c4c2347e25fa76dad2204372500ab70d4a68bb2e530900180a3c347" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/__tests__/mock/tron-web/trigger-smart-contract-deposit.json: -------------------------------------------------------------------------------- 1 | { 2 | "result": { 3 | "result": true 4 | }, 5 | "transaction": { 6 | "visible": false, 7 | "txID": "f9d6b7a64bd5c05fb29a42eda1309a42f5d6f73e5800b0eb604a50781ecbe374", 8 | "raw_data": { 9 | "contract": [ 10 | { 11 | "parameter": { 12 | "value": { 13 | "data": "b6b55f250000000000000000000000000000000000000000000000000de0b6b3a7640000", 14 | "owner_address": "41b83811067ab3a275ece28d3f8ec6875105ef9bae", 15 | "contract_address": "41bb58c8a419276287518cfb4c4c2347e25fa76dad" 16 | }, 17 | "type_url": "type.googleapis.com/protocol.TriggerSmartContract" 18 | }, 19 | "type": "TriggerSmartContract" 20 | } 21 | ], 22 | "ref_block_bytes": "dd99", 23 | "ref_block_hash": "eadc2ce685a0af75", 24 | "expiration": 1676483832000, 25 | "fee_limit": 150000000, 26 | "timestamp": 1676483773207 27 | }, 28 | "raw_data_hex": "0a02dd992208eadc2ce685a0af7540c0d1e4b1e5305a8e01081f1289010a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412540a1541b83811067ab3a275ece28d3f8ec6875105ef9bae121541bb58c8a419276287518cfb4c4c2347e25fa76dad2224b6b55f250000000000000000000000000000000000000000000000000de0b6b3a7640000709786e1b1e530900180a3c347" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/__tests__/mock/tron-web/trigger-smart-contract-send.json: -------------------------------------------------------------------------------- 1 | { 2 | "result": { 3 | "result": true 4 | }, 5 | "transaction": { 6 | "visible": false, 7 | "txID": "f80b0aa6023ef5bc9161b915bc3f06d4546cfd904e3959eb7f11fe282a8cde16", 8 | "raw_data": { 9 | "contract": [ 10 | { 11 | "parameter": { 12 | "value": { 13 | "data": "f35e37d3000000000000000000000000b10388f04f8331b59a02732cc1b6ac0d7045574b0000000000000000000000000000000000000000000000000e043da61725000000000000000000000000000001237296aaf2ba01ac9a819813e260bb4ad6642d0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c7dbc4a896b34b7a10dda2ef72052145a9122f43d38fc44187c1dc4b0ffd3d80ebaf2465d55091811df252727c57d947a66291710000000000000000000000000000000000000000000000000000000000000001", 14 | "owner_address": "410bef513090bf616bc1a8bdfe81bb8726e2096edf", 15 | "contract_address": "41e0d6d5e5bef141007f8d78cdfca214b293a23f83", 16 | "call_value": 59136000 17 | }, 18 | "type_url": "type.googleapis.com/protocol.TriggerSmartContract" 19 | }, 20 | "type": "TriggerSmartContract" 21 | } 22 | ], 23 | "ref_block_bytes": "920b", 24 | "ref_block_hash": "c19f7616ec9f09e6", 25 | "expiration": 1667475183000, 26 | "fee_limit": 150000000, 27 | "timestamp": 1667475125660 28 | }, 29 | "raw_data_hex": "0a02920b2208c19f7616ec9f09e64098ab90eac3305ad502081f12d0020a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e7472616374129a020a15410bef513090bf616bc1a8bdfe81bb8726e2096edf121541e0d6d5e5bef141007f8d78cdfca214b293a23f831880b0991c22e401f35e37d3000000000000000000000000b10388f04f8331b59a02732cc1b6ac0d7045574b0000000000000000000000000000000000000000000000000e043da61725000000000000000000000000000001237296aaf2ba01ac9a819813e260bb4ad6642d0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c7dbc4a896b34b7a10dda2ef72052145a9122f43d38fc44187c1dc4b0ffd3d80ebaf2465d55091811df252727c57d947a66291710000000000000000000000000000000000000000000000000000000000000001709ceb8ceac330900180a3c347" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/__tests__/mock/tron-web/trigger-smart-contract-withdraw.json: -------------------------------------------------------------------------------- 1 | { 2 | "result": { 3 | "result": true 4 | }, 5 | "transaction": { 6 | "visible": false, 7 | "txID": "bcfae762e6a8fe70f8a9221e136cba59463f8d5a3f49738b2ad9c3f1b8dc83dd", 8 | "raw_data": { 9 | "contract": [ 10 | { 11 | "parameter": { 12 | "value": { 13 | "data": "2e1a7d4d00000000000000000000000000000000000000000000000000000000000003e8", 14 | "owner_address": "41b83811067ab3a275ece28d3f8ec6875105ef9bae", 15 | "contract_address": "41bb58c8a419276287518cfb4c4c2347e25fa76dad" 16 | }, 17 | "type_url": "type.googleapis.com/protocol.TriggerSmartContract" 18 | }, 19 | "type": "TriggerSmartContract" 20 | } 21 | ], 22 | "ref_block_bytes": "de41", 23 | "ref_block_hash": "d48eb9dfbc06981f", 24 | "expiration": 1676484405000, 25 | "fee_limit": 150000000, 26 | "timestamp": 1676484347406 27 | }, 28 | "raw_data_hex": "0a02de412208d48eb9dfbc06981f4088ce87b2e5305a8e01081f1289010a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412540a1541b83811067ab3a275ece28d3f8ec6875105ef9bae121541bb58c8a419276287518cfb4c4c2347e25fa76dad22242e1a7d4d00000000000000000000000000000000000000000000000000000000000003e8708e8c84b2e530900180a3c347" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/__tests__/mock/utils.ts: -------------------------------------------------------------------------------- 1 | import nock, { Body, RequestBodyMatcher } from "nock"; 2 | import { Chains } from "../../chains"; 3 | import { ChainSymbol, ChainType } from "../../chains/chain.enums"; 4 | import { PoolInfo, TokenWithChainDetails } from "../../tokens-info"; 5 | 6 | export function getRequestBodyMatcher(expectedBody: any): RequestBodyMatcher { 7 | return (body: Body) => JSON.stringify(body) === JSON.stringify(expectedBody); 8 | } 9 | export function initChainsWithTestnet() { 10 | Chains.addChainsProperties({ 11 | GRL: { 12 | chainSymbol: "GRL" as ChainSymbol, 13 | chainId: "0x5", 14 | name: "Goerli", 15 | chainType: ChainType.EVM, 16 | }, 17 | }); 18 | } 19 | 20 | export function mockTokenInfoEndpoint( 21 | scope: nock.Scope, 22 | pools: { token: TokenWithChainDetails; poolInfo: PoolInfo }[] 23 | ) { 24 | let resultInfo = {}; 25 | for (const pool of pools) { 26 | const infoResponse = { 27 | [pool.token.chainSymbol]: { 28 | tokens: [ 29 | { 30 | name: pool.token.name, 31 | poolAddress: pool.token.poolAddress, 32 | tokenAddress: pool.token.tokenAddress, 33 | decimals: pool.token.decimals, 34 | symbol: pool.token.symbol, 35 | poolInfo: pool.poolInfo, 36 | feeShare: pool.token.feeShare, 37 | apr: pool.token.apr, 38 | lpRate: pool.token.lpRate, 39 | }, 40 | ], 41 | chainId: pool.token.chainId, 42 | bridgeAddress: pool.token.bridgeAddress, 43 | transferTime: pool.token.transferTime, 44 | confirmations: pool.token.confirmations, 45 | txCostAmount: pool.token.txCostAmount, 46 | }, 47 | }; 48 | resultInfo = { 49 | ...resultInfo, 50 | ...infoResponse, 51 | }; 52 | } 53 | scope.get("/token-info?filter=all").reply(200, resultInfo).persist(); 54 | } 55 | 56 | export function rpcReply(result: any): (url: string, body: any) => Record { 57 | return (url, body: any) => ({ 58 | jsonrpc: "2.0", 59 | id: body.id, 60 | result: result, 61 | }); 62 | } 63 | -------------------------------------------------------------------------------- /src/__tests__/services/bridge/raw-bridge-transaction-builder.test.ts: -------------------------------------------------------------------------------- 1 | import { Web3 } from "web3"; 2 | import { 3 | DefaultRawBridgeTransactionBuilder, 4 | RawBridgeTransactionBuilder, 5 | } from "../../../services/bridge/raw-bridge-transaction-builder"; 6 | import { DefaultTokenService } from "../../../services/token"; 7 | import { ApproveParams } from "../../../services/token/models"; 8 | import { TokenWithChainDetails } from "../../../tokens-info"; 9 | import tokenInfoWithChainDetailsGrl from "../../data/tokens-info/TokenInfoWithChainDetails-GRL.json"; 10 | import { initChainsWithTestnet } from "../../mock/utils"; 11 | 12 | initChainsWithTestnet(); 13 | 14 | describe("RawTransactionBuilder", () => { 15 | let rawTransactionBuilder: RawBridgeTransactionBuilder; 16 | let api: any; 17 | let solParams: any; 18 | let nodeRpcUrls: any; 19 | let params: any; 20 | const tokenService = new DefaultTokenService(api, nodeRpcUrls, params); 21 | 22 | beforeEach(() => { 23 | rawTransactionBuilder = new DefaultRawBridgeTransactionBuilder(api, nodeRpcUrls, solParams, tokenService); 24 | }); 25 | 26 | test("approve should call buildRawTransactionApprove", async () => { 27 | const expectedApproveTransaction = { 28 | data: "0x095ea7b3000000000000000000000000ba285a8f52601eabcc769706fcbde2645aa0af18ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 29 | from: "owner", 30 | to: "0xDdaC3cb57DEa3fBEFF4997d78215535Eb5787117", 31 | value: "0", 32 | }; 33 | 34 | const approveData: ApproveParams = { 35 | token: tokenInfoWithChainDetailsGrl[0] as unknown as TokenWithChainDetails, 36 | owner: "owner", 37 | spender: "spender", 38 | }; 39 | const web3 = new Web3("http://localhost/"); 40 | const actual = await rawTransactionBuilder.approve(web3, approveData); 41 | expect(actual).toEqual(expectedApproveTransaction); 42 | }); 43 | }); 44 | -------------------------------------------------------------------------------- /src/__tests__/services/liquidity-pool/raw-pool-transaction-builder.test.ts: -------------------------------------------------------------------------------- 1 | import { Web3 } from "web3"; 2 | import { 3 | DefaultRawPoolTransactionBuilder, 4 | RawPoolTransactionBuilder, 5 | } from "../../../services/liquidity-pool/raw-pool-transaction-builder"; 6 | import { DefaultTokenService } from "../../../services/token"; 7 | import { ApproveParams } from "../../../services/token/models"; 8 | import { TokenWithChainDetails } from "../../../tokens-info"; 9 | import tokenInfoWithChainDetailsGrl from "../../data/tokens-info/TokenInfoWithChainDetails-GRL.json"; 10 | import { initChainsWithTestnet } from "../../mock/utils"; 11 | 12 | initChainsWithTestnet(); 13 | 14 | describe("RawTransactionBuilder", () => { 15 | let rawTransactionBuilder: RawPoolTransactionBuilder; 16 | let api: any; 17 | let nodeRpcUrls: any; 18 | let params: any; 19 | const tokenService = new DefaultTokenService(api, nodeRpcUrls, params); 20 | 21 | beforeEach(() => { 22 | rawTransactionBuilder = new DefaultRawPoolTransactionBuilder(api, nodeRpcUrls, params, tokenService); 23 | }); 24 | 25 | test("approve should call buildRawTransactionApprove", async () => { 26 | const expectedApproveTransaction = { 27 | data: "0x095ea7b3000000000000000000000000ec46d2b11e68a31026673d63b345b889ab37c0bcffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 28 | from: "owner", 29 | to: "0xDdaC3cb57DEa3fBEFF4997d78215535Eb5787117", 30 | value: "0", 31 | }; 32 | 33 | const approveData: ApproveParams = { 34 | token: tokenInfoWithChainDetailsGrl[0] as unknown as TokenWithChainDetails, 35 | owner: "owner", 36 | spender: "spender", 37 | }; 38 | const web3 = new Web3("http://localhost/"); 39 | const actual = await rawTransactionBuilder.approve(web3, approveData); 40 | expect(actual).toEqual(expectedApproveTransaction); 41 | }); 42 | }); 43 | -------------------------------------------------------------------------------- /src/__tests__/tokens-info/index.test.ts: -------------------------------------------------------------------------------- 1 | import { ChainDetailsMap, TokenWithChainDetails, TokensInfo } from "../../tokens-info"; 2 | import tokensGroupedByChain from "../data/tokens-info/ChainDetailsMap.json"; 3 | import tokenInfoWithChainDetailsGRL from "../data/tokens-info/TokenInfoWithChainDetails-GRL.json"; 4 | import tokenInfoWithChainDetails from "../data/tokens-info/TokenInfoWithChainDetails.json"; 5 | 6 | const expectedTokenInfoWithChainDetails = tokenInfoWithChainDetails as unknown as TokenWithChainDetails[]; 7 | const expectedTokenInfoWithChainDetailsGRL = tokenInfoWithChainDetailsGRL as unknown as TokenWithChainDetails[]; 8 | const chainDetailsMap = tokensGroupedByChain as unknown as ChainDetailsMap; 9 | 10 | describe("TokensInfo", () => { 11 | const tokensInfo = new TokensInfo(chainDetailsMap); 12 | 13 | it("☀️ chainDetailsMap() returns ChainDetailsMap", () => { 14 | expect(tokensInfo.chainDetailsMap()).toEqual(chainDetailsMap); 15 | }); 16 | 17 | it("☀️ tokens() returns a list of TokenWithChainDetails", () => { 18 | expect(tokensInfo.tokens()).toEqual(expectedTokenInfoWithChainDetails); 19 | }); 20 | 21 | it("☀️ tokensByChain(GRL) returns a list of TokenWithChainDetails on Goerli chain", () => { 22 | expect(tokensInfo.tokensByChain("GRL")).toEqual(expectedTokenInfoWithChainDetailsGRL); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /src/chains/chain.enums.ts: -------------------------------------------------------------------------------- 1 | export enum ChainSymbol { 2 | /** 3 | * The BNB Smart Chain main network. 4 | */ 5 | BSC = "BSC", 6 | 7 | /** 8 | * The Ethereum main network. 9 | */ 10 | ETH = "ETH", 11 | 12 | /** 13 | * The Base main network. 14 | */ 15 | BAS = "BAS", 16 | 17 | /** 18 | * The Solana network. 19 | */ 20 | SOL = "SOL", 21 | 22 | /** 23 | * The TRON network. 24 | */ 25 | TRX = "TRX", 26 | 27 | /** 28 | * The Polygon network. 29 | */ 30 | POL = "POL", 31 | 32 | /** 33 | * The Arbitrum network. 34 | */ 35 | ARB = "ARB", 36 | 37 | /** 38 | * The Celo network. 39 | */ 40 | CEL = "CEL", 41 | 42 | /** 43 | * The Avalanche main network. 44 | */ 45 | AVA = "AVA", 46 | 47 | /** 48 | * The Soroban network. 49 | */ 50 | SRB = "SRB", 51 | 52 | /** 53 | * The Stellar network. 54 | */ 55 | STLR = "STLR", 56 | 57 | /** 58 | * The OP Mainnet network. 59 | */ 60 | OPT = "OPT", 61 | 62 | /** 63 | * The SUI network. 64 | */ 65 | SUI = "SUI", 66 | } 67 | 68 | export enum ChainType { 69 | EVM = "EVM", 70 | SOLANA = "SOLANA", 71 | TRX = "TRX", 72 | SRB = "SRB", 73 | SUI = "SUI", 74 | } 75 | -------------------------------------------------------------------------------- /src/chains/models.ts: -------------------------------------------------------------------------------- 1 | import { ChainSymbol, ChainType } from "./chain.enums"; 2 | 3 | /** 4 | * Contains blockchain's basic information 5 | */ 6 | export interface BasicChainProperties { 7 | /** 8 | * The symbol of the chain representing one of the supported blockchain networks (e.g., "ETH" for Ethereum). For more details, see: {@link ChainSymbol}. 9 | */ 10 | chainSymbol: ChainSymbol; 11 | /** 12 | * Common Blockchain Id
13 | * A 0x-prefixed hexadecimal string
14 | * Optional. 15 | */ 16 | chainId?: string; // A 0x-prefixed hexadecimal string 17 | /** 18 | * Blockchain name 19 | */ 20 | name: string; 21 | /** 22 | * Blockchain type. For more details, see: {@link ChainType}. 23 | */ 24 | chainType: ChainType; 25 | } 26 | export interface AdditionalBasicChainProperties extends Omit { 27 | /** 28 | * The symbol of the chain representing one of the supported blockchain networks (e.g., "ETH" for Ethereum). For more details, see: {@link ChainSymbol}. 29 | */ 30 | chainSymbol: string; 31 | } 32 | -------------------------------------------------------------------------------- /src/configs/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./mainnet"; 2 | -------------------------------------------------------------------------------- /src/configs/mainnet.ts: -------------------------------------------------------------------------------- 1 | import { AllbridgeCoreSdkOptions, NodeRpcUrls, NodeUrlsConfig } from "../index"; 2 | 3 | export const mainnet: AllbridgeCoreSdkOptions = { 4 | coreApiUrl: "https://core.api.allbridgecoreapi.net", 5 | coreApiQueryParams: {}, 6 | coreApiHeaders: {}, 7 | jupiterUrl: "https://lite-api.jup.ag/swap/v1", 8 | wormholeMessengerProgramId: "worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth", 9 | solanaLookUpTable: "2JcBAEVnAwVo4u8d61iqgHPrzZuugur7cVTjWubsVLHj", 10 | sorobanNetworkPassphrase: "Public Global Stellar Network ; September 2015", 11 | tronJsonRpc: "https://api.trongrid.io/jsonrpc", 12 | cctpParams: { 13 | cctpTransmitterProgramId: "CCTPmbSD7gX1bxKPAmg77w8oFzNFpaQiQUWD43TKaecd", 14 | cctpTokenMessengerMinter: "CCTPiPYPc6AsJuwueEnWgSgucamXDZwBd53dQ11YiKX3", 15 | cctpDomains: { ETH: 0, AVA: 1, OPT: 2, ARB: 3, SOL: 5, BAS: 6, POL: 7, SUI: 8 }, 16 | }, 17 | cachePoolInfoChainSec: 20, 18 | }; 19 | 20 | /** 21 | * This is default rpc urls for Solana and Tron,

Override and use your own for proper and stable work 22 | * @deprecated use {@link nodeRpcUrlsDefault} 23 | */ 24 | export const nodeUrlsDefault: NodeUrlsConfig = { 25 | solanaRpcUrl: "https://api.mainnet-beta.solana.com", 26 | tronRpcUrl: "https://api.trongrid.io", 27 | }; 28 | 29 | /** 30 | * This is default rpc urls for Solana and Tron,

Override and use your own for proper and stable work 31 | */ 32 | export const nodeRpcUrlsDefault: NodeRpcUrls = { 33 | SOL: "https://api.mainnet-beta.solana.com", 34 | TRX: "https://api.trongrid.io", 35 | SRB: "https://rpc.stellar.org:443", 36 | STLR: "https://horizon.stellar.org", 37 | SUI: "https://fullnode.mainnet.sui.io", 38 | }; 39 | -------------------------------------------------------------------------------- /src/exceptions/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./exceptions"; 2 | -------------------------------------------------------------------------------- /src/services/bridge/models/bridge.ts: -------------------------------------------------------------------------------- 1 | import { ChainType } from "../../../chains/chain.enums"; 2 | import { AllbridgeCoreClient } from "../../../client/core-api/core-client-base"; 3 | import { RawTransaction, TransactionResponse } from "../../models"; 4 | import { SendParams, SwapParams } from "./bridge.model"; 5 | 6 | export abstract class ChainBridgeService { 7 | abstract chainType: ChainType; 8 | abstract api: AllbridgeCoreClient; 9 | 10 | /** 11 | * @deprecated Use {@link buildRawTransactionSend} or {@link buildRawTransactionSwap} instead

12 | * Send tokens through the ChainBridgeService 13 | * @param params 14 | */ 15 | abstract send(params: SendParams): Promise; 16 | abstract buildRawTransactionSend(params: SendParams): Promise; 17 | abstract buildRawTransactionSwap(params: SwapParams): Promise; 18 | } 19 | -------------------------------------------------------------------------------- /src/services/bridge/models/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./bridge.model"; 2 | export { ChainBridgeService } from "./bridge"; 3 | -------------------------------------------------------------------------------- /src/services/liquidity-pool/models/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./pool.model"; 2 | export { ChainPoolService } from "./pool"; 3 | -------------------------------------------------------------------------------- /src/services/liquidity-pool/models/pool.model.ts: -------------------------------------------------------------------------------- 1 | import { Big } from "big.js"; 2 | import { FeePaymentMethod, TxFeeParams } from "../../../models"; 3 | import { PoolInfo, TokenWithChainDetails } from "../../../tokens-info"; 4 | import { convertIntAmountToFloat, getEarned } from "../../../utils/calculation"; 5 | import { SYSTEM_PRECISION } from "../../../utils/calculation/constants"; 6 | 7 | export interface ApproveParams { 8 | /** 9 | * The token info 10 | */ 11 | token: TokenWithChainDetails; 12 | 13 | /** 14 | * The address of the token owner who is granting permission to use tokens 15 | */ 16 | owner: string; 17 | 18 | /** 19 | * The integer amount of tokens to approve. 20 | * Optional. 21 | * The maximum amount by default. 22 | */ 23 | amount?: string | number | Big; 24 | } 25 | 26 | export interface GetAllowanceParams { 27 | token: TokenWithChainDetails; 28 | owner: string; 29 | gasFeePaymentMethod?: FeePaymentMethod; 30 | } 31 | 32 | export type GetAllowanceParamsDto = GetAllowanceParams; 33 | 34 | export interface CheckAllowanceParams extends GetAllowanceParams { 35 | /** 36 | * The float amount of tokens to check the allowance. 37 | */ 38 | amount: string | number | Big; 39 | } 40 | 41 | export interface LiquidityPoolsParams { 42 | /** 43 | * The account address to operate tokens with. 44 | */ 45 | accountAddress: string; 46 | /** 47 | * {@link TokenWithChainDetails |The token info object} of operation token. 48 | */ 49 | token: TokenWithChainDetails; 50 | 51 | txFeeParams?: TxFeeParams; 52 | } 53 | 54 | export interface LiquidityPoolsParamsWithAmount extends LiquidityPoolsParams { 55 | /** 56 | * The float amount of tokens. 57 | */ 58 | amount: string; 59 | } 60 | 61 | export interface UserBalanceInfoDTO { 62 | lpAmount: string; 63 | rewardDebt: string; 64 | } 65 | 66 | export interface UserBalanceInfo extends UserBalanceInfoDTO { 67 | userLiquidity: string; 68 | 69 | earned(poolInfo: PoolInfo, decimals?: number): string; 70 | } 71 | 72 | export class UserBalance implements UserBalanceInfo { 73 | lpAmount: string; 74 | rewardDebt: string; 75 | 76 | constructor(userInfo: UserBalanceInfoDTO) { 77 | this.lpAmount = userInfo.lpAmount; 78 | this.rewardDebt = userInfo.rewardDebt; 79 | } 80 | 81 | get userLiquidity(): string { 82 | return convertIntAmountToFloat(this.lpAmount, SYSTEM_PRECISION).toFixed(); 83 | } 84 | 85 | earned(poolInfo: PoolInfo, decimals?: number): string { 86 | const earned = getEarned(this.lpAmount, this.rewardDebt, poolInfo.accRewardPerShareP, poolInfo.p); 87 | if (decimals) { 88 | return convertIntAmountToFloat(earned, decimals).toFixed(); 89 | } 90 | return earned; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/services/liquidity-pool/models/pool.ts: -------------------------------------------------------------------------------- 1 | import { ChainType } from "../../../chains/chain.enums"; 2 | import { AllbridgeCoreClient } from "../../../client/core-api/core-client-base"; 3 | import { PoolInfo, TokenWithChainDetails } from "../../../tokens-info"; 4 | import { RawTransaction } from "../../models"; 5 | import { LiquidityPoolsParams, LiquidityPoolsParamsWithAmount, UserBalanceInfo } from "./pool.model"; 6 | 7 | export abstract class ChainPoolService { 8 | abstract chainType: ChainType; 9 | abstract api: AllbridgeCoreClient; 10 | 11 | abstract getUserBalanceInfo(accountAddress: string, token: TokenWithChainDetails): Promise; 12 | 13 | abstract getPoolInfoFromChain(token: TokenWithChainDetails): Promise; 14 | 15 | abstract buildRawTransactionDeposit(params: LiquidityPoolsParamsWithAmount): Promise; 16 | 17 | abstract buildRawTransactionWithdraw(params: LiquidityPoolsParamsWithAmount): Promise; 18 | 19 | abstract buildRawTransactionClaimRewards(params: LiquidityPoolsParams): Promise; 20 | } 21 | -------------------------------------------------------------------------------- /src/services/models/index.ts: -------------------------------------------------------------------------------- 1 | import { Transaction as SolanaWeb3Transaction, VersionedTransaction } from "@solana/web3.js"; 2 | import { TronWeb } from "tronweb"; 3 | import { Transaction as TronWebTransaction } from "tronweb/src/types/Transaction"; 4 | import { SolanaTxFee } from "./sol"; 5 | 6 | export { SolanaTxFee, PricePerUnitInMicroLamports, ExtraFeeInLamports, SolanaAutoTxFee } from "./sol"; 7 | 8 | /** 9 | * Blockchain fee added to tx 10 | */ 11 | export interface TxFeeParams { 12 | solana?: SolanaTxFee; 13 | } 14 | 15 | /** 16 | * The `EssentialWeb3` interface provides the minimum set of Web3 functionalities 17 | * required by the SDK. It allows any web3-like provider to be used, as long as it 18 | * matches the signature of these essential methods and properties. This prevents 19 | * tight coupling to a specific version of the `web3` library. 20 | */ 21 | export interface EssentialWeb3 { 22 | eth: { 23 | getBalance: (address: string) => Promise; 24 | estimateGas: (tx: any) => Promise; 25 | sendTransaction: (tx: any) => Promise; 26 | Contract: new (abi: any, address?: string) => any; 27 | BatchRequest: new () => any; 28 | }; 29 | } 30 | 31 | /** 32 | * The provider is type that combines connection implementations for different chains.
33 | * TIP: None provider in the Solana blockchain case. 34 | */ 35 | export type Provider = EssentialWeb3 | TronWeb; 36 | 37 | /** 38 | * The `EssentialWeb3Transaction` interface provides the minimum set of Web3 Transaction 39 | * returned by the SDK. It allows any web3-like provider to be used, as long as it 40 | * matches the signature of these essential interface. This prevents 41 | * tight coupling to a specific version of the `web3` library. 42 | */ 43 | export interface EssentialWeb3Transaction { 44 | from?: string; 45 | to?: string; 46 | value?: string; 47 | data?: string; 48 | } 49 | 50 | export type RawTransaction = 51 | | RawTronTransaction 52 | | RawEvmTransaction 53 | | RawSorobanTransaction 54 | | RawBridgeSolanaTransaction 55 | | RawPoolSolanaTransaction; 56 | export type RawEvmTransaction = EssentialWeb3Transaction; 57 | export type RawTronTransaction = TronWebTransaction; 58 | export type RawSorobanTransaction = string; 59 | export type RawPoolSolanaTransaction = SolanaWeb3Transaction; 60 | export type RawBridgeSolanaTransaction = VersionedTransaction; 61 | export type RawSuiTransaction = string; 62 | 63 | export interface SmartContractMethodParameter { 64 | type: string; 65 | value: string | number | Buffer; 66 | } 67 | 68 | export interface TransactionResponse { 69 | txId: string; 70 | } 71 | -------------------------------------------------------------------------------- /src/services/models/srb/utils.ts: -------------------------------------------------------------------------------- 1 | import { contract, rpc } from "@stellar/stellar-sdk"; 2 | import Api = rpc.Api; 3 | import AssembledTransaction = contract.AssembledTransaction; 4 | import SentTransaction = contract.SentTransaction; 5 | 6 | export function getViewResultSoroban(assembledTx: AssembledTransaction): T | undefined { 7 | const { simulation, options } = assembledTx; 8 | if (!simulation) { 9 | throw new Error("Soroban assembled transaction does not have simulation"); 10 | } 11 | 12 | if (Api.isSimulationSuccess(simulation)) { 13 | if (simulation.result == null) { 14 | return; 15 | } 16 | return options.parseResultXdr(simulation.result.retval); 17 | } else { 18 | throw new Error(simulation.error); 19 | } 20 | } 21 | 22 | export function isErrorSorobanResult(assembledTx: AssembledTransaction): boolean { 23 | const { simulation } = assembledTx; 24 | if (!simulation) { 25 | throw new Error("Soroban assembled transaction does not have simulation"); 26 | } 27 | return Api.isSimulationError(simulation); 28 | } 29 | 30 | export async function signAndSendSoroban(assembledTx: AssembledTransaction): Promise> { 31 | await assembledTx.simulate({ restore: true }); 32 | return assembledTx.signAndSend(); 33 | } 34 | -------------------------------------------------------------------------------- /src/services/models/sui/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "@typescript-eslint/ban-types": "off", 4 | "@typescript-eslint/no-explicit-any": "off", 5 | "@typescript-eslint/no-unused-vars": "off" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/services/models/sui/_dependencies/source/0x1/index.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | export const PACKAGE_ID = "0x1"; 3 | export const PUBLISHED_AT = "0x1"; 4 | export const PKG_V13 = "0x1"; 5 | -------------------------------------------------------------------------------- /src/services/models/sui/_dependencies/source/0x1/init.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import * as ascii from "./ascii/structs"; 3 | import * as bitVector from "./bit-vector/structs"; 4 | import * as fixedPoint32 from "./fixed-point32/structs"; 5 | import * as option from "./option/structs"; 6 | import * as string from "./string/structs"; 7 | import * as typeName from "./type-name/structs"; 8 | import * as uq3232 from "./uq32-32/structs"; 9 | import * as uq6464 from "./uq64-64/structs"; 10 | import { StructClassLoader } from "../../../_framework/loader"; 11 | 12 | export function registerClasses(loader: StructClassLoader) { 13 | loader.register(fixedPoint32.FixedPoint32); 14 | loader.register(uq3232.UQ32_32); 15 | loader.register(uq6464.UQ64_64); 16 | loader.register(option.Option); 17 | loader.register(ascii.Char); 18 | loader.register(ascii.String); 19 | loader.register(string.String); 20 | loader.register(typeName.TypeName); 21 | loader.register(bitVector.BitVector); 22 | } 23 | -------------------------------------------------------------------------------- /src/services/models/sui/_dependencies/source/0x31cc14d80c175ae39777c0238f20594c6d4869cfab199f40b69f3319956b8beb/index.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | export const PACKAGE_ID = "0x31cc14d80c175ae39777c0238f20594c6d4869cfab199f40b69f3319956b8beb"; 3 | export const PUBLISHED_AT = "0x31cc14d80c175ae39777c0238f20594c6d4869cfab199f40b69f3319956b8beb"; 4 | export const PKG_V1 = "0x31cc14d80c175ae39777c0238f20594c6d4869cfab199f40b69f3319956b8beb"; 5 | -------------------------------------------------------------------------------- /src/services/models/sui/_dependencies/source/0x31cc14d80c175ae39777c0238f20594c6d4869cfab199f40b69f3319956b8beb/init.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import * as burnMessage from "./burn-message/structs"; 3 | import * as depositForBurn from "./deposit-for-burn/structs"; 4 | import * as handleReceiveMessage from "./handle-receive-message/structs"; 5 | import * as messageTransmitterAuthenticator from "./message-transmitter-authenticator/structs"; 6 | import * as state from "./state/structs"; 7 | import { StructClassLoader } from "../../../_framework/loader"; 8 | 9 | export function registerClasses(loader: StructClassLoader) { 10 | loader.register(state.State); 11 | loader.register(burnMessage.BurnMessage); 12 | loader.register(depositForBurn.DepositForBurnTicket); 13 | loader.register(depositForBurn.ReplaceDepositForBurnTicket); 14 | loader.register(messageTransmitterAuthenticator.MessageTransmitterAuthenticator); 15 | loader.register(handleReceiveMessage.StampReceiptTicketWithBurnMessage); 16 | } 17 | -------------------------------------------------------------------------------- /src/services/models/sui/_dependencies/source/0x346e3233f61eb0055713417bfaddda7dc3bf26816faad1f7606994a368b92917/index.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | export const PACKAGE_ID = "0x346e3233f61eb0055713417bfaddda7dc3bf26816faad1f7606994a368b92917"; 3 | export const PUBLISHED_AT = "0x346e3233f61eb0055713417bfaddda7dc3bf26816faad1f7606994a368b92917"; 4 | export const PKG_V1 = "0x346e3233f61eb0055713417bfaddda7dc3bf26816faad1f7606994a368b92917"; 5 | -------------------------------------------------------------------------------- /src/services/models/sui/_dependencies/source/0x346e3233f61eb0055713417bfaddda7dc3bf26816faad1f7606994a368b92917/init.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import * as mintAllowance from "./mint-allowance/structs"; 3 | import * as treasury from "./treasury/structs"; 4 | import { StructClassLoader } from "../../../_framework/loader"; 5 | 6 | export function registerClasses(loader: StructClassLoader) { 7 | loader.register(mintAllowance.MintAllowance); 8 | loader.register(treasury.Burn); 9 | loader.register(treasury.MintCap); 10 | loader.register(treasury.Treasury); 11 | loader.register(treasury.TreasuryCapKey); 12 | } 13 | -------------------------------------------------------------------------------- /src/services/models/sui/_dependencies/source/0x4931e06dce648b3931f890035bd196920770e913e43e45990b383f6486fdd0a5/index.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | export const PACKAGE_ID = "0x4931e06dce648b3931f890035bd196920770e913e43e45990b383f6486fdd0a5"; 3 | export const PUBLISHED_AT = "0x4931e06dce648b3931f890035bd196920770e913e43e45990b383f6486fdd0a5"; 4 | export const PKG_V1 = "0x4931e06dce648b3931f890035bd196920770e913e43e45990b383f6486fdd0a5"; 5 | -------------------------------------------------------------------------------- /src/services/models/sui/_dependencies/source/0x4931e06dce648b3931f890035bd196920770e913e43e45990b383f6486fdd0a5/init.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import * as message from "./message/structs"; 3 | import * as receiveMessage from "./receive-message/structs"; 4 | import * as state from "./state/structs"; 5 | import { StructClassLoader } from "../../../_framework/loader"; 6 | 7 | export function registerClasses(loader: StructClassLoader) { 8 | loader.register(state.State); 9 | loader.register(message.Message); 10 | loader.register(receiveMessage.Receipt); 11 | loader.register(receiveMessage.StampReceiptTicket); 12 | loader.register(receiveMessage.StampedReceipt); 13 | } 14 | -------------------------------------------------------------------------------- /src/services/models/sui/_dependencies/source/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/index.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | export const PACKAGE_ID = "0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94"; 3 | export const PUBLISHED_AT = "0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94"; 4 | export const PKG_V1 = "0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94"; 5 | -------------------------------------------------------------------------------- /src/services/models/sui/_dependencies/source/0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94/init.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import * as bytes20 from "./bytes20/structs"; 3 | import * as bytes32 from "./bytes32/structs"; 4 | import * as consumedVaas from "./consumed-vaas/structs"; 5 | import * as cursor from "./cursor/structs"; 6 | import * as emitter from "./emitter/structs"; 7 | import * as externalAddress from "./external-address/structs"; 8 | import * as feeCollector from "./fee-collector/structs"; 9 | import * as guardianSet from "./guardian-set/structs"; 10 | import * as guardian from "./guardian/structs"; 11 | import * as publishMessage from "./publish-message/structs"; 12 | import * as set from "./set/structs"; 13 | import * as state from "./state/structs"; 14 | import * as vaa from "./vaa/structs"; 15 | import { StructClassLoader } from "../../../_framework/loader"; 16 | 17 | export function registerClasses(loader: StructClassLoader) { 18 | loader.register(cursor.Cursor); 19 | loader.register(bytes20.Bytes20); 20 | loader.register(guardian.Guardian); 21 | loader.register(guardianSet.GuardianSet); 22 | loader.register(feeCollector.FeeCollector); 23 | loader.register(bytes32.Bytes32); 24 | loader.register(externalAddress.ExternalAddress); 25 | loader.register(set.Empty); 26 | loader.register(set.Set); 27 | loader.register(consumedVaas.ConsumedVAAs); 28 | loader.register(state.State); 29 | loader.register(vaa.VAA); 30 | loader.register(emitter.EmitterCap); 31 | loader.register(emitter.EmitterCreated); 32 | loader.register(publishMessage.MessageTicket); 33 | loader.register(publishMessage.WormholeMessage); 34 | } 35 | -------------------------------------------------------------------------------- /src/services/models/sui/bridge/index.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { compressSuiType } from "../_framework/util"; 3 | 4 | class PackageAddress { 5 | private static $PACKAGE_ID = ""; 6 | private static $PUBLISHED_AT = ""; 7 | private static $PKG_V = []; 8 | 9 | get PACKAGE_ID() { 10 | return compressSuiType(PackageAddress.$PACKAGE_ID); 11 | } 12 | 13 | get PUBLISHED_AT() { 14 | return compressSuiType(PackageAddress.$PUBLISHED_AT); 15 | } 16 | 17 | get PKG_V1() { 18 | return compressSuiType(PackageAddress.$PKG_V[1]); 19 | } 20 | 21 | setPackageId(address: string): void { 22 | PackageAddress.$PACKAGE_ID = address; 23 | } 24 | 25 | setPublishedAt(address: string): void { 26 | PackageAddress.$PUBLISHED_AT = address; 27 | } 28 | 29 | setPkgV(v: number, address: string): void { 30 | PackageAddress.$PKG_V[v] = address; 31 | } 32 | 33 | setAddress(address: string, pkgV1?: string) { 34 | PackageAddress.$PACKAGE_ID = address; 35 | PackageAddress.$PUBLISHED_AT = address; 36 | PackageAddress.$PKG_V[1] = pkgV1 || address; 37 | } 38 | } 39 | 40 | const packageAddress = new PackageAddress(); 41 | export = packageAddress; 42 | -------------------------------------------------------------------------------- /src/services/models/sui/bridge/init.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import * as anotherBridge from "./another-bridge/structs"; 3 | import * as bridge from "./bridge/structs"; 4 | import * as events from "./events/structs"; 5 | import * as poolRewards from "./pool-rewards/structs"; 6 | import * as poolState from "./pool-state/structs"; 7 | import * as pool from "./pool/structs"; 8 | import * as userDeposit from "./user-deposit/structs"; 9 | import { StructClassLoader } from "../_framework/loader"; 10 | 11 | export function registerClasses(loader: StructClassLoader) { 12 | loader.register(anotherBridge.AnotherBridge); 13 | loader.register(userDeposit.UserDeposit); 14 | loader.register(poolRewards.PoolRewards); 15 | loader.register(poolState.PoolState); 16 | loader.register(events.DepositEvent); 17 | loader.register(events.ReceiveFeeEvent); 18 | loader.register(events.RewardsClaimedEvent); 19 | loader.register(events.SwappedEvent); 20 | loader.register(events.SwappedFromVUsdEvent); 21 | loader.register(events.SwappedToVUsdEvent); 22 | loader.register(events.TokensReceivedEvent); 23 | loader.register(events.TokensSentEvent); 24 | loader.register(events.WithdrawEvent); 25 | loader.register(pool.AdminCap); 26 | loader.register(pool.Pool); 27 | loader.register(pool.StopCap); 28 | loader.register(bridge.AdminCap); 29 | loader.register(bridge.Bridge); 30 | loader.register(bridge.FeeCollectorCap); 31 | loader.register(bridge.StopSwapCap); 32 | } 33 | -------------------------------------------------------------------------------- /src/services/models/sui/cctp-bridge/index.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { compressSuiType } from "../_framework/util"; 3 | 4 | class PackageAddress { 5 | private static $PACKAGE_ID = ""; 6 | private static $PUBLISHED_AT = ""; 7 | private static $PKG_V = []; 8 | get PACKAGE_ID() { 9 | return compressSuiType(PackageAddress.$PACKAGE_ID); 10 | } 11 | get PUBLISHED_AT() { 12 | return compressSuiType(PackageAddress.$PUBLISHED_AT); 13 | } 14 | get PKG_V1() { 15 | return compressSuiType(PackageAddress.$PKG_V[1]); 16 | } 17 | setPackageId(address: string): void { 18 | PackageAddress.$PACKAGE_ID = address; 19 | } 20 | setPublishedAt(address: string): void { 21 | PackageAddress.$PUBLISHED_AT = address; 22 | } 23 | setPkgV(v: number, address: string): void { 24 | PackageAddress.$PKG_V[v] = address; 25 | } 26 | setAddress(address: string, pkgV1?: string) { 27 | PackageAddress.$PACKAGE_ID = address; 28 | PackageAddress.$PUBLISHED_AT = address; 29 | PackageAddress.$PKG_V[1] = pkgV1 || address; 30 | } 31 | } 32 | const packageAddress = new PackageAddress(); 33 | export = packageAddress; 34 | -------------------------------------------------------------------------------- /src/services/models/sui/cctp-bridge/init.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import * as cctpBridge from "./cctp-bridge/structs"; 3 | import * as events from "./events/structs"; 4 | import * as messageTransmitterAuthenticator from "./message-transmitter-authenticator/structs"; 5 | import { StructClassLoader } from "../_framework/loader"; 6 | 7 | export function registerClasses(loader: StructClassLoader) { 8 | loader.register(messageTransmitterAuthenticator.MessageTransmitterAuthenticator); 9 | loader.register(events.ReceiveFeeEvent); 10 | loader.register(events.TokensReceivedEvent); 11 | loader.register(events.TokensSentEvent); 12 | loader.register(events.RecipientReplaced); 13 | loader.register(cctpBridge.AdminCap); 14 | loader.register(cctpBridge.FeeCollectorCap); 15 | loader.register(cctpBridge.CctpBridge); 16 | } 17 | -------------------------------------------------------------------------------- /src/services/models/sui/cctp-bridge/message-transmitter-authenticator/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { Transaction } from "@mysten/sui/transactions"; 4 | 5 | export function new_(tx: Transaction) { 6 | return tx.moveCall({ 7 | target: `${PUBLISHED_AT}::message_transmitter_authenticator::new`, 8 | arguments: [], 9 | }); 10 | } 11 | -------------------------------------------------------------------------------- /src/services/models/sui/gas-oracle/index.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { compressSuiType } from "../_framework/util"; 3 | 4 | class PackageAddress { 5 | private static $PACKAGE_ID = ""; 6 | private static $PUBLISHED_AT = ""; 7 | private static $PKG_V = []; 8 | get PACKAGE_ID() { 9 | return compressSuiType(PackageAddress.$PACKAGE_ID); 10 | } 11 | get PUBLISHED_AT() { 12 | return compressSuiType(PackageAddress.$PUBLISHED_AT); 13 | } 14 | get PKG_V1() { 15 | return compressSuiType(PackageAddress.$PKG_V[1]); 16 | } 17 | setPackageId(address: string): void { 18 | PackageAddress.$PACKAGE_ID = address; 19 | } 20 | setPublishedAt(address: string): void { 21 | PackageAddress.$PUBLISHED_AT = address; 22 | } 23 | setPkgV(v: number, address: string): void { 24 | PackageAddress.$PKG_V[v] = address; 25 | } 26 | setAddress(address: string, pkgV1?: string) { 27 | PackageAddress.$PACKAGE_ID = address; 28 | PackageAddress.$PUBLISHED_AT = address; 29 | PackageAddress.$PKG_V[1] = pkgV1 || address; 30 | } 31 | } 32 | const packageAddress = new PackageAddress(); 33 | export = packageAddress; 34 | -------------------------------------------------------------------------------- /src/services/models/sui/gas-oracle/init.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import * as gasOracle from "./gas-oracle/structs"; 3 | import { StructClassLoader } from "../_framework/loader"; 4 | 5 | export function registerClasses(loader: StructClassLoader) { 6 | loader.register(gasOracle.AdminCap); 7 | loader.register(gasOracle.ChainData); 8 | loader.register(gasOracle.GasOracle); 9 | } 10 | -------------------------------------------------------------------------------- /src/services/models/sui/messenger/events/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { obj } from "../../_framework/util"; 4 | import { Transaction, TransactionObjectInput } from "@mysten/sui/transactions"; 5 | 6 | export function messageReceivedEvent(tx: Transaction, message: TransactionObjectInput) { 7 | return tx.moveCall({ 8 | target: `${PUBLISHED_AT}::events::message_received_event`, 9 | arguments: [obj(tx, message)], 10 | }); 11 | } 12 | 13 | export function messageSentEvent(tx: Transaction, message: TransactionObjectInput) { 14 | return tx.moveCall({ 15 | target: `${PUBLISHED_AT}::events::message_sent_event`, 16 | arguments: [obj(tx, message)], 17 | }); 18 | } 19 | -------------------------------------------------------------------------------- /src/services/models/sui/messenger/index.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { compressSuiType } from "../_framework/util"; 3 | 4 | class PackageAddress { 5 | private static $PACKAGE_ID = ""; 6 | private static $PUBLISHED_AT = ""; 7 | private static $PKG_V = []; 8 | get PACKAGE_ID() { 9 | return compressSuiType(PackageAddress.$PACKAGE_ID); 10 | } 11 | get PUBLISHED_AT() { 12 | return compressSuiType(PackageAddress.$PUBLISHED_AT); 13 | } 14 | get PKG_V1() { 15 | return compressSuiType(PackageAddress.$PKG_V[1]); 16 | } 17 | setPackageId(address: string): void { 18 | PackageAddress.$PACKAGE_ID = address; 19 | } 20 | setPublishedAt(address: string): void { 21 | PackageAddress.$PUBLISHED_AT = address; 22 | } 23 | setPkgV(v: number, address: string): void { 24 | PackageAddress.$PKG_V[v] = address; 25 | } 26 | setAddress(address: string, pkgV1?: string) { 27 | PackageAddress.$PACKAGE_ID = address; 28 | PackageAddress.$PUBLISHED_AT = address; 29 | PackageAddress.$PKG_V[1] = pkgV1 || address; 30 | } 31 | } 32 | const packageAddress = new PackageAddress(); 33 | export = packageAddress; 34 | -------------------------------------------------------------------------------- /src/services/models/sui/messenger/init.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import * as events from "./events/structs"; 3 | import * as messenger from "./messenger/structs"; 4 | import { StructClassLoader } from "../_framework/loader"; 5 | 6 | export function registerClasses(loader: StructClassLoader) { 7 | loader.register(events.MessageReceivedEvent); 8 | loader.register(events.MessageSentEvent); 9 | loader.register(messenger.AdminCap); 10 | loader.register(messenger.Messenger); 11 | } 12 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/address/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { pure } from "../../_framework/util"; 4 | import { Transaction, TransactionArgument } from "@mysten/sui/transactions"; 5 | 6 | export function length(tx: Transaction) { 7 | return tx.moveCall({ 8 | target: `${PUBLISHED_AT}::address::length`, 9 | arguments: [], 10 | }); 11 | } 12 | 13 | export function toBytes(tx: Transaction, a: string | TransactionArgument) { 14 | return tx.moveCall({ 15 | target: `${PUBLISHED_AT}::address::to_bytes`, 16 | arguments: [pure(tx, a, `address`)], 17 | }); 18 | } 19 | 20 | export function fromAsciiBytes(tx: Transaction, bytes: Array | TransactionArgument) { 21 | return tx.moveCall({ 22 | target: `${PUBLISHED_AT}::address::from_ascii_bytes`, 23 | arguments: [pure(tx, bytes, `vector`)], 24 | }); 25 | } 26 | 27 | export function fromBytes(tx: Transaction, bytes: Array | TransactionArgument) { 28 | return tx.moveCall({ 29 | target: `${PUBLISHED_AT}::address::from_bytes`, 30 | arguments: [pure(tx, bytes, `vector`)], 31 | }); 32 | } 33 | 34 | export function fromU256(tx: Transaction, n: bigint | TransactionArgument) { 35 | return tx.moveCall({ 36 | target: `${PUBLISHED_AT}::address::from_u256`, 37 | arguments: [pure(tx, n, `u256`)], 38 | }); 39 | } 40 | 41 | export function hexCharValue(tx: Transaction, c: number | TransactionArgument) { 42 | return tx.moveCall({ 43 | target: `${PUBLISHED_AT}::address::hex_char_value`, 44 | arguments: [pure(tx, c, `u8`)], 45 | }); 46 | } 47 | 48 | export function max(tx: Transaction) { 49 | return tx.moveCall({ 50 | target: `${PUBLISHED_AT}::address::max`, 51 | arguments: [], 52 | }); 53 | } 54 | 55 | export function toAsciiString(tx: Transaction, a: string | TransactionArgument) { 56 | return tx.moveCall({ 57 | target: `${PUBLISHED_AT}::address::to_ascii_string`, 58 | arguments: [pure(tx, a, `address`)], 59 | }); 60 | } 61 | 62 | export function toString(tx: Transaction, a: string | TransactionArgument) { 63 | return tx.moveCall({ 64 | target: `${PUBLISHED_AT}::address::to_string`, 65 | arguments: [pure(tx, a, `address`)], 66 | }); 67 | } 68 | 69 | export function toU256(tx: Transaction, a: string | TransactionArgument) { 70 | return tx.moveCall({ 71 | target: `${PUBLISHED_AT}::address::to_u256`, 72 | arguments: [pure(tx, a, `address`)], 73 | }); 74 | } 75 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/borrow/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { GenericArg, generic, obj } from "../../_framework/util"; 4 | import { Transaction, TransactionObjectInput } from "@mysten/sui/transactions"; 5 | 6 | export function borrow(tx: Transaction, typeArg: string, self: TransactionObjectInput) { 7 | return tx.moveCall({ 8 | target: `${PUBLISHED_AT}::borrow::borrow`, 9 | typeArguments: [typeArg], 10 | arguments: [obj(tx, self)], 11 | }); 12 | } 13 | 14 | export function new_(tx: Transaction, typeArg: string, value: GenericArg) { 15 | return tx.moveCall({ 16 | target: `${PUBLISHED_AT}::borrow::new`, 17 | typeArguments: [typeArg], 18 | arguments: [generic(tx, `${typeArg}`, value)], 19 | }); 20 | } 21 | 22 | export function destroy(tx: Transaction, typeArg: string, self: TransactionObjectInput) { 23 | return tx.moveCall({ 24 | target: `${PUBLISHED_AT}::borrow::destroy`, 25 | typeArguments: [typeArg], 26 | arguments: [obj(tx, self)], 27 | }); 28 | } 29 | 30 | export interface PutBackArgs { 31 | self: TransactionObjectInput; 32 | value: GenericArg; 33 | borrow: TransactionObjectInput; 34 | } 35 | 36 | export function putBack(tx: Transaction, typeArg: string, args: PutBackArgs) { 37 | return tx.moveCall({ 38 | target: `${PUBLISHED_AT}::borrow::put_back`, 39 | typeArguments: [typeArg], 40 | arguments: [obj(tx, args.self), generic(tx, `${typeArg}`, args.value), obj(tx, args.borrow)], 41 | }); 42 | } 43 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/clock/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { obj, pure } from "../../_framework/util"; 4 | import { Transaction, TransactionArgument, TransactionObjectInput } from "@mysten/sui/transactions"; 5 | 6 | export function create(tx: Transaction) { 7 | return tx.moveCall({ 8 | target: `${PUBLISHED_AT}::clock::create`, 9 | arguments: [], 10 | }); 11 | } 12 | 13 | export interface ConsensusCommitPrologueArgs { 14 | clock: TransactionObjectInput; 15 | timestampMs: bigint | TransactionArgument; 16 | } 17 | 18 | export function consensusCommitPrologue(tx: Transaction, args: ConsensusCommitPrologueArgs) { 19 | return tx.moveCall({ 20 | target: `${PUBLISHED_AT}::clock::consensus_commit_prologue`, 21 | arguments: [obj(tx, args.clock), pure(tx, args.timestampMs, `u64`)], 22 | }); 23 | } 24 | 25 | export function timestampMs(tx: Transaction, clock: TransactionObjectInput) { 26 | return tx.moveCall({ 27 | target: `${PUBLISHED_AT}::clock::timestamp_ms`, 28 | arguments: [obj(tx, clock)], 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/ecdsa-k1/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { pure } from "../../_framework/util"; 4 | import { Transaction, TransactionArgument } from "@mysten/sui/transactions"; 5 | 6 | export function decompressPubkey(tx: Transaction, pubkey: Array | TransactionArgument) { 7 | return tx.moveCall({ 8 | target: `${PUBLISHED_AT}::ecdsa_k1::decompress_pubkey`, 9 | arguments: [pure(tx, pubkey, `vector`)], 10 | }); 11 | } 12 | 13 | export interface Secp256k1EcrecoverArgs { 14 | signature: Array | TransactionArgument; 15 | msg: Array | TransactionArgument; 16 | hash: number | TransactionArgument; 17 | } 18 | 19 | export function secp256k1Ecrecover(tx: Transaction, args: Secp256k1EcrecoverArgs) { 20 | return tx.moveCall({ 21 | target: `${PUBLISHED_AT}::ecdsa_k1::secp256k1_ecrecover`, 22 | arguments: [pure(tx, args.signature, `vector`), pure(tx, args.msg, `vector`), pure(tx, args.hash, `u8`)], 23 | }); 24 | } 25 | 26 | export interface Secp256k1VerifyArgs { 27 | signature: Array | TransactionArgument; 28 | publicKey: Array | TransactionArgument; 29 | msg: Array | TransactionArgument; 30 | hash: number | TransactionArgument; 31 | } 32 | 33 | export function secp256k1Verify(tx: Transaction, args: Secp256k1VerifyArgs) { 34 | return tx.moveCall({ 35 | target: `${PUBLISHED_AT}::ecdsa_k1::secp256k1_verify`, 36 | arguments: [ 37 | pure(tx, args.signature, `vector`), 38 | pure(tx, args.publicKey, `vector`), 39 | pure(tx, args.msg, `vector`), 40 | pure(tx, args.hash, `u8`), 41 | ], 42 | }); 43 | } 44 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/ecdsa-r1/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { pure } from "../../_framework/util"; 4 | import { Transaction, TransactionArgument } from "@mysten/sui/transactions"; 5 | 6 | export interface Secp256r1EcrecoverArgs { 7 | signature: Array | TransactionArgument; 8 | msg: Array | TransactionArgument; 9 | hash: number | TransactionArgument; 10 | } 11 | 12 | export function secp256r1Ecrecover(tx: Transaction, args: Secp256r1EcrecoverArgs) { 13 | return tx.moveCall({ 14 | target: `${PUBLISHED_AT}::ecdsa_r1::secp256r1_ecrecover`, 15 | arguments: [pure(tx, args.signature, `vector`), pure(tx, args.msg, `vector`), pure(tx, args.hash, `u8`)], 16 | }); 17 | } 18 | 19 | export interface Secp256r1VerifyArgs { 20 | signature: Array | TransactionArgument; 21 | publicKey: Array | TransactionArgument; 22 | msg: Array | TransactionArgument; 23 | hash: number | TransactionArgument; 24 | } 25 | 26 | export function secp256r1Verify(tx: Transaction, args: Secp256r1VerifyArgs) { 27 | return tx.moveCall({ 28 | target: `${PUBLISHED_AT}::ecdsa_r1::secp256r1_verify`, 29 | arguments: [ 30 | pure(tx, args.signature, `vector`), 31 | pure(tx, args.publicKey, `vector`), 32 | pure(tx, args.msg, `vector`), 33 | pure(tx, args.hash, `u8`), 34 | ], 35 | }); 36 | } 37 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/ecvrf/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { pure } from "../../_framework/util"; 4 | import { Transaction, TransactionArgument } from "@mysten/sui/transactions"; 5 | 6 | export interface EcvrfVerifyArgs { 7 | hash: Array | TransactionArgument; 8 | alphaString: Array | TransactionArgument; 9 | publicKey: Array | TransactionArgument; 10 | proof: Array | TransactionArgument; 11 | } 12 | 13 | export function ecvrfVerify(tx: Transaction, args: EcvrfVerifyArgs) { 14 | return tx.moveCall({ 15 | target: `${PUBLISHED_AT}::ecvrf::ecvrf_verify`, 16 | arguments: [ 17 | pure(tx, args.hash, `vector`), 18 | pure(tx, args.alphaString, `vector`), 19 | pure(tx, args.publicKey, `vector`), 20 | pure(tx, args.proof, `vector`), 21 | ], 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/ed25519/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { pure } from "../../_framework/util"; 4 | import { Transaction, TransactionArgument } from "@mysten/sui/transactions"; 5 | 6 | export interface Ed25519VerifyArgs { 7 | signature: Array | TransactionArgument; 8 | publicKey: Array | TransactionArgument; 9 | msg: Array | TransactionArgument; 10 | } 11 | 12 | export function ed25519Verify(tx: Transaction, args: Ed25519VerifyArgs) { 13 | return tx.moveCall({ 14 | target: `${PUBLISHED_AT}::ed25519::ed25519_verify`, 15 | arguments: [ 16 | pure(tx, args.signature, `vector`), 17 | pure(tx, args.publicKey, `vector`), 18 | pure(tx, args.msg, `vector`), 19 | ], 20 | }); 21 | } 22 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/event/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { GenericArg, generic } from "../../_framework/util"; 4 | import { Transaction } from "@mysten/sui/transactions"; 5 | 6 | export function emit(tx: Transaction, typeArg: string, event: GenericArg) { 7 | return tx.moveCall({ 8 | target: `${PUBLISHED_AT}::event::emit`, 9 | typeArguments: [typeArg], 10 | arguments: [generic(tx, `${typeArg}`, event)], 11 | }); 12 | } 13 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/hash/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { pure } from "../../_framework/util"; 4 | import { Transaction, TransactionArgument } from "@mysten/sui/transactions"; 5 | 6 | export function blake2b256(tx: Transaction, data: Array | TransactionArgument) { 7 | return tx.moveCall({ 8 | target: `${PUBLISHED_AT}::hash::blake2b256`, 9 | arguments: [pure(tx, data, `vector`)], 10 | }); 11 | } 12 | 13 | export function keccak256(tx: Transaction, data: Array | TransactionArgument) { 14 | return tx.moveCall({ 15 | target: `${PUBLISHED_AT}::hash::keccak256`, 16 | arguments: [pure(tx, data, `vector`)], 17 | }); 18 | } 19 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/hex/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { pure } from "../../_framework/util"; 4 | import { Transaction, TransactionArgument } from "@mysten/sui/transactions"; 5 | 6 | export function decode(tx: Transaction, hex: Array | TransactionArgument) { 7 | return tx.moveCall({ 8 | target: `${PUBLISHED_AT}::hex::decode`, 9 | arguments: [pure(tx, hex, `vector`)], 10 | }); 11 | } 12 | 13 | export function decodeByte(tx: Transaction, hex: number | TransactionArgument) { 14 | return tx.moveCall({ 15 | target: `${PUBLISHED_AT}::hex::decode_byte`, 16 | arguments: [pure(tx, hex, `u8`)], 17 | }); 18 | } 19 | 20 | export function encode(tx: Transaction, bytes: Array | TransactionArgument) { 21 | return tx.moveCall({ 22 | target: `${PUBLISHED_AT}::hex::encode`, 23 | arguments: [pure(tx, bytes, `vector`)], 24 | }); 25 | } 26 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/hmac/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { pure } from "../../_framework/util"; 4 | import { Transaction, TransactionArgument } from "@mysten/sui/transactions"; 5 | 6 | export interface HmacSha3256Args { 7 | key: Array | TransactionArgument; 8 | msg: Array | TransactionArgument; 9 | } 10 | 11 | export function hmacSha3256(tx: Transaction, args: HmacSha3256Args) { 12 | return tx.moveCall({ 13 | target: `${PUBLISHED_AT}::hmac::hmac_sha3_256`, 14 | arguments: [pure(tx, args.key, `vector`), pure(tx, args.msg, `vector`)], 15 | }); 16 | } 17 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/index.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | export const PACKAGE_ID = "0x2"; 3 | export const PUBLISHED_AT = "0x2"; 4 | export const PKG_V26 = "0x2"; 5 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/math/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { pure } from "../../_framework/util"; 4 | import { Transaction, TransactionArgument } from "@mysten/sui/transactions"; 5 | 6 | export interface MaxArgs { 7 | x: bigint | TransactionArgument; 8 | y: bigint | TransactionArgument; 9 | } 10 | 11 | export function max(tx: Transaction, args: MaxArgs) { 12 | return tx.moveCall({ 13 | target: `${PUBLISHED_AT}::math::max`, 14 | arguments: [pure(tx, args.x, `u64`), pure(tx, args.y, `u64`)], 15 | }); 16 | } 17 | 18 | export interface DiffArgs { 19 | x: bigint | TransactionArgument; 20 | y: bigint | TransactionArgument; 21 | } 22 | 23 | export function diff(tx: Transaction, args: DiffArgs) { 24 | return tx.moveCall({ 25 | target: `${PUBLISHED_AT}::math::diff`, 26 | arguments: [pure(tx, args.x, `u64`), pure(tx, args.y, `u64`)], 27 | }); 28 | } 29 | 30 | export interface DivideAndRoundUpArgs { 31 | x: bigint | TransactionArgument; 32 | y: bigint | TransactionArgument; 33 | } 34 | 35 | export function divideAndRoundUp(tx: Transaction, args: DivideAndRoundUpArgs) { 36 | return tx.moveCall({ 37 | target: `${PUBLISHED_AT}::math::divide_and_round_up`, 38 | arguments: [pure(tx, args.x, `u64`), pure(tx, args.y, `u64`)], 39 | }); 40 | } 41 | 42 | export interface MinArgs { 43 | x: bigint | TransactionArgument; 44 | y: bigint | TransactionArgument; 45 | } 46 | 47 | export function min(tx: Transaction, args: MinArgs) { 48 | return tx.moveCall({ 49 | target: `${PUBLISHED_AT}::math::min`, 50 | arguments: [pure(tx, args.x, `u64`), pure(tx, args.y, `u64`)], 51 | }); 52 | } 53 | 54 | export interface PowArgs { 55 | base: bigint | TransactionArgument; 56 | exponent: number | TransactionArgument; 57 | } 58 | 59 | export function pow(tx: Transaction, args: PowArgs) { 60 | return tx.moveCall({ 61 | target: `${PUBLISHED_AT}::math::pow`, 62 | arguments: [pure(tx, args.base, `u64`), pure(tx, args.exponent, `u8`)], 63 | }); 64 | } 65 | 66 | export function sqrt(tx: Transaction, x: bigint | TransactionArgument) { 67 | return tx.moveCall({ 68 | target: `${PUBLISHED_AT}::math::sqrt`, 69 | arguments: [pure(tx, x, `u64`)], 70 | }); 71 | } 72 | 73 | export function sqrtU128(tx: Transaction, x: bigint | TransactionArgument) { 74 | return tx.moveCall({ 75 | target: `${PUBLISHED_AT}::math::sqrt_u128`, 76 | arguments: [pure(tx, x, `u128`)], 77 | }); 78 | } 79 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/poseidon/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { pure } from "../../_framework/util"; 4 | import { Transaction, TransactionArgument } from "@mysten/sui/transactions"; 5 | 6 | export function poseidonBn254(tx: Transaction, data: Array | TransactionArgument) { 7 | return tx.moveCall({ 8 | target: `${PUBLISHED_AT}::poseidon::poseidon_bn254`, 9 | arguments: [pure(tx, data, `vector`)], 10 | }); 11 | } 12 | 13 | export function poseidonBn254Internal( 14 | tx: Transaction, 15 | data: Array | TransactionArgument> | TransactionArgument 16 | ) { 17 | return tx.moveCall({ 18 | target: `${PUBLISHED_AT}::poseidon::poseidon_bn254_internal`, 19 | arguments: [pure(tx, data, `vector>`)], 20 | }); 21 | } 22 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/sui/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { obj, pure } from "../../_framework/util"; 4 | import { Transaction, TransactionArgument, TransactionObjectInput } from "@mysten/sui/transactions"; 5 | 6 | export function new_(tx: Transaction) { 7 | return tx.moveCall({ target: `${PUBLISHED_AT}::sui::new`, arguments: [] }); 8 | } 9 | 10 | export interface TransferArgs { 11 | c: TransactionObjectInput; 12 | recipient: string | TransactionArgument; 13 | } 14 | 15 | export function transfer(tx: Transaction, args: TransferArgs) { 16 | return tx.moveCall({ 17 | target: `${PUBLISHED_AT}::sui::transfer`, 18 | arguments: [obj(tx, args.c), pure(tx, args.recipient, `address`)], 19 | }); 20 | } 21 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/tx-context/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { pure } from "../../_framework/util"; 4 | import { Transaction, TransactionArgument } from "@mysten/sui/transactions"; 5 | 6 | export interface DeriveIdArgs { 7 | txHash: Array | TransactionArgument; 8 | idsCreated: bigint | TransactionArgument; 9 | } 10 | 11 | export function deriveId(tx: Transaction, args: DeriveIdArgs) { 12 | return tx.moveCall({ 13 | target: `${PUBLISHED_AT}::tx_context::derive_id`, 14 | arguments: [pure(tx, args.txHash, `vector`), pure(tx, args.idsCreated, `u64`)], 15 | }); 16 | } 17 | 18 | export function idsCreated(tx: Transaction) { 19 | return tx.moveCall({ 20 | target: `${PUBLISHED_AT}::tx_context::ids_created`, 21 | arguments: [], 22 | }); 23 | } 24 | 25 | export function digest(tx: Transaction) { 26 | return tx.moveCall({ 27 | target: `${PUBLISHED_AT}::tx_context::digest`, 28 | arguments: [], 29 | }); 30 | } 31 | 32 | export function epoch(tx: Transaction) { 33 | return tx.moveCall({ 34 | target: `${PUBLISHED_AT}::tx_context::epoch`, 35 | arguments: [], 36 | }); 37 | } 38 | 39 | export function epochTimestampMs(tx: Transaction) { 40 | return tx.moveCall({ 41 | target: `${PUBLISHED_AT}::tx_context::epoch_timestamp_ms`, 42 | arguments: [], 43 | }); 44 | } 45 | 46 | export function freshObjectAddress(tx: Transaction) { 47 | return tx.moveCall({ 48 | target: `${PUBLISHED_AT}::tx_context::fresh_object_address`, 49 | arguments: [], 50 | }); 51 | } 52 | 53 | export function sender(tx: Transaction) { 54 | return tx.moveCall({ 55 | target: `${PUBLISHED_AT}::tx_context::sender`, 56 | arguments: [], 57 | }); 58 | } 59 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/types/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { GenericArg, generic } from "../../_framework/util"; 4 | import { Transaction } from "@mysten/sui/transactions"; 5 | 6 | export function isOneTimeWitness(tx: Transaction, typeArg: string, t: GenericArg) { 7 | return tx.moveCall({ 8 | target: `${PUBLISHED_AT}::types::is_one_time_witness`, 9 | typeArguments: [typeArg], 10 | arguments: [generic(tx, `${typeArg}`, t)], 11 | }); 12 | } 13 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/url/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { String } from "../../_dependencies/source/0x1/ascii/structs"; 4 | import { obj, pure } from "../../_framework/util"; 5 | import { Transaction, TransactionArgument, TransactionObjectInput } from "@mysten/sui/transactions"; 6 | 7 | export function innerUrl(tx: Transaction, self: TransactionObjectInput) { 8 | return tx.moveCall({ 9 | target: `${PUBLISHED_AT}::url::inner_url`, 10 | arguments: [obj(tx, self)], 11 | }); 12 | } 13 | 14 | export function newUnsafe(tx: Transaction, url: string | TransactionArgument) { 15 | return tx.moveCall({ 16 | target: `${PUBLISHED_AT}::url::new_unsafe`, 17 | arguments: [pure(tx, url, `${String.$typeName}`)], 18 | }); 19 | } 20 | 21 | export function newUnsafeFromBytes(tx: Transaction, bytes: Array | TransactionArgument) { 22 | return tx.moveCall({ 23 | target: `${PUBLISHED_AT}::url::new_unsafe_from_bytes`, 24 | arguments: [pure(tx, bytes, `vector`)], 25 | }); 26 | } 27 | 28 | export interface UpdateArgs { 29 | self: TransactionObjectInput; 30 | url: string | TransactionArgument; 31 | } 32 | 33 | export function update(tx: Transaction, args: UpdateArgs) { 34 | return tx.moveCall({ 35 | target: `${PUBLISHED_AT}::url::update`, 36 | arguments: [obj(tx, args.self), pure(tx, args.url, `${String.$typeName}`)], 37 | }); 38 | } 39 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/vdf/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { pure } from "../../_framework/util"; 4 | import { Transaction, TransactionArgument } from "@mysten/sui/transactions"; 5 | 6 | export function hashToInput(tx: Transaction, message: Array | TransactionArgument) { 7 | return tx.moveCall({ 8 | target: `${PUBLISHED_AT}::vdf::hash_to_input`, 9 | arguments: [pure(tx, message, `vector`)], 10 | }); 11 | } 12 | 13 | export function hashToInputInternal( 14 | tx: Transaction, 15 | message: Array | TransactionArgument 16 | ) { 17 | return tx.moveCall({ 18 | target: `${PUBLISHED_AT}::vdf::hash_to_input_internal`, 19 | arguments: [pure(tx, message, `vector`)], 20 | }); 21 | } 22 | 23 | export interface VdfVerifyArgs { 24 | input: Array | TransactionArgument; 25 | output: Array | TransactionArgument; 26 | proof: Array | TransactionArgument; 27 | iterations: bigint | TransactionArgument; 28 | } 29 | 30 | export function vdfVerify(tx: Transaction, args: VdfVerifyArgs) { 31 | return tx.moveCall({ 32 | target: `${PUBLISHED_AT}::vdf::vdf_verify`, 33 | arguments: [ 34 | pure(tx, args.input, `vector`), 35 | pure(tx, args.output, `vector`), 36 | pure(tx, args.proof, `vector`), 37 | pure(tx, args.iterations, `u64`), 38 | ], 39 | }); 40 | } 41 | 42 | export interface VdfVerifyInternalArgs { 43 | input: Array | TransactionArgument; 44 | output: Array | TransactionArgument; 45 | proof: Array | TransactionArgument; 46 | iterations: bigint | TransactionArgument; 47 | } 48 | 49 | export function vdfVerifyInternal(tx: Transaction, args: VdfVerifyInternalArgs) { 50 | return tx.moveCall({ 51 | target: `${PUBLISHED_AT}::vdf::vdf_verify_internal`, 52 | arguments: [ 53 | pure(tx, args.input, `vector`), 54 | pure(tx, args.output, `vector`), 55 | pure(tx, args.proof, `vector`), 56 | pure(tx, args.iterations, `u64`), 57 | ], 58 | }); 59 | } 60 | -------------------------------------------------------------------------------- /src/services/models/sui/sui/versioned/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { GenericArg, generic, obj, pure } from "../../_framework/util"; 4 | import { Transaction, TransactionArgument, TransactionObjectInput } from "@mysten/sui/transactions"; 5 | 6 | export function version(tx: Transaction, self: TransactionObjectInput) { 7 | return tx.moveCall({ 8 | target: `${PUBLISHED_AT}::versioned::version`, 9 | arguments: [obj(tx, self)], 10 | }); 11 | } 12 | 13 | export interface CreateArgs { 14 | initVersion: bigint | TransactionArgument; 15 | initValue: GenericArg; 16 | } 17 | 18 | export function create(tx: Transaction, typeArg: string, args: CreateArgs) { 19 | return tx.moveCall({ 20 | target: `${PUBLISHED_AT}::versioned::create`, 21 | typeArguments: [typeArg], 22 | arguments: [pure(tx, args.initVersion, `u64`), generic(tx, `${typeArg}`, args.initValue)], 23 | }); 24 | } 25 | 26 | export function destroy(tx: Transaction, typeArg: string, self: TransactionObjectInput) { 27 | return tx.moveCall({ 28 | target: `${PUBLISHED_AT}::versioned::destroy`, 29 | typeArguments: [typeArg], 30 | arguments: [obj(tx, self)], 31 | }); 32 | } 33 | 34 | export function loadValue(tx: Transaction, typeArg: string, self: TransactionObjectInput) { 35 | return tx.moveCall({ 36 | target: `${PUBLISHED_AT}::versioned::load_value`, 37 | typeArguments: [typeArg], 38 | arguments: [obj(tx, self)], 39 | }); 40 | } 41 | 42 | export function loadValueMut(tx: Transaction, typeArg: string, self: TransactionObjectInput) { 43 | return tx.moveCall({ 44 | target: `${PUBLISHED_AT}::versioned::load_value_mut`, 45 | typeArguments: [typeArg], 46 | arguments: [obj(tx, self)], 47 | }); 48 | } 49 | 50 | export function removeValueForUpgrade(tx: Transaction, typeArg: string, self: TransactionObjectInput) { 51 | return tx.moveCall({ 52 | target: `${PUBLISHED_AT}::versioned::remove_value_for_upgrade`, 53 | typeArguments: [typeArg], 54 | arguments: [obj(tx, self)], 55 | }); 56 | } 57 | 58 | export interface UpgradeArgs { 59 | self: TransactionObjectInput; 60 | newVersion: bigint | TransactionArgument; 61 | newValue: GenericArg; 62 | cap: TransactionObjectInput; 63 | } 64 | 65 | export function upgrade(tx: Transaction, typeArg: string, args: UpgradeArgs) { 66 | return tx.moveCall({ 67 | target: `${PUBLISHED_AT}::versioned::upgrade`, 68 | typeArguments: [typeArg], 69 | arguments: [ 70 | obj(tx, args.self), 71 | pure(tx, args.newVersion, `u64`), 72 | generic(tx, `${typeArg}`, args.newValue), 73 | obj(tx, args.cap), 74 | ], 75 | }); 76 | } 77 | -------------------------------------------------------------------------------- /src/services/models/sui/utils/fee-collector/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { GenericArg, generic, obj, pure } from "../../_framework/util"; 4 | import { Transaction, TransactionArgument, TransactionObjectInput } from "@mysten/sui/transactions"; 5 | 6 | export function new_(tx: Transaction, typeArg: string) { 7 | return tx.moveCall({ 8 | target: `${PUBLISHED_AT}::fee_collector::new`, 9 | typeArguments: [typeArg], 10 | arguments: [], 11 | }); 12 | } 13 | 14 | export function key(tx: Transaction, typeArg: string) { 15 | return tx.moveCall({ 16 | target: `${PUBLISHED_AT}::fee_collector::key`, 17 | typeArguments: [typeArg], 18 | arguments: [], 19 | }); 20 | } 21 | 22 | export function balance(tx: Transaction, typeArgs: [string, string], feeCollector: TransactionObjectInput) { 23 | return tx.moveCall({ 24 | target: `${PUBLISHED_AT}::fee_collector::balance`, 25 | typeArguments: typeArgs, 26 | arguments: [obj(tx, feeCollector)], 27 | }); 28 | } 29 | 30 | export interface WithdrawArgs { 31 | cap: GenericArg; 32 | feeCollector: TransactionObjectInput; 33 | amount: bigint | TransactionArgument; 34 | } 35 | 36 | export function withdraw(tx: Transaction, typeArgs: [string, string], args: WithdrawArgs) { 37 | return tx.moveCall({ 38 | target: `${PUBLISHED_AT}::fee_collector::withdraw`, 39 | typeArguments: typeArgs, 40 | arguments: [generic(tx, `${typeArgs[1]}`, args.cap), obj(tx, args.feeCollector), pure(tx, args.amount, `u64`)], 41 | }); 42 | } 43 | 44 | export interface AddFeeArgs { 45 | feeCollector: TransactionObjectInput; 46 | coin: TransactionObjectInput; 47 | } 48 | 49 | export function addFee(tx: Transaction, typeArgs: [string, string], args: AddFeeArgs) { 50 | return tx.moveCall({ 51 | target: `${PUBLISHED_AT}::fee_collector::add_fee`, 52 | typeArguments: typeArgs, 53 | arguments: [obj(tx, args.feeCollector), obj(tx, args.coin)], 54 | }); 55 | } 56 | -------------------------------------------------------------------------------- /src/services/models/sui/utils/index.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { compressSuiType } from "../_framework/util"; 3 | 4 | class PackageAddress { 5 | private static $PACKAGE_ID = ""; 6 | private static $PUBLISHED_AT = ""; 7 | private static $PKG_V = []; 8 | get PACKAGE_ID() { 9 | return compressSuiType(PackageAddress.$PACKAGE_ID); 10 | } 11 | get PUBLISHED_AT() { 12 | return compressSuiType(PackageAddress.$PUBLISHED_AT); 13 | } 14 | get PKG_V1() { 15 | return compressSuiType(PackageAddress.$PKG_V[1]); 16 | } 17 | setPackageId(address: string): void { 18 | PackageAddress.$PACKAGE_ID = address; 19 | } 20 | setPublishedAt(address: string): void { 21 | PackageAddress.$PUBLISHED_AT = address; 22 | } 23 | setPkgV(v: number, address: string): void { 24 | PackageAddress.$PKG_V[v] = address; 25 | } 26 | setAddress(address: string, pkgV1?: string) { 27 | PackageAddress.$PACKAGE_ID = address; 28 | PackageAddress.$PUBLISHED_AT = address; 29 | PackageAddress.$PKG_V[1] = pkgV1 || address; 30 | } 31 | } 32 | const packageAddress = new PackageAddress(); 33 | export = packageAddress; 34 | -------------------------------------------------------------------------------- /src/services/models/sui/utils/init.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import * as bytes32 from "./bytes32/structs"; 3 | import * as feeCollector from "./fee-collector/structs"; 4 | import * as message from "./message/structs"; 5 | import * as messengerProtocol from "./messenger-protocol/structs"; 6 | import * as set from "./set/structs"; 7 | import * as version from "./version/structs"; 8 | import { StructClassLoader } from "../_framework/loader"; 9 | 10 | export function registerClasses(loader: StructClassLoader) { 11 | loader.register(messengerProtocol.MessengerProtocol); 12 | loader.register(bytes32.Bytes32); 13 | loader.register(message.Message); 14 | loader.register(version.CurrentVersion); 15 | loader.register(set.Empty); 16 | loader.register(set.Set); 17 | loader.register(feeCollector.FeeCollector); 18 | } 19 | -------------------------------------------------------------------------------- /src/services/models/sui/utils/messenger-protocol/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { obj } from "../../_framework/util"; 4 | import { Transaction, TransactionObjectInput } from "@mysten/sui/transactions"; 5 | 6 | export function wormhole(tx: Transaction) { 7 | return tx.moveCall({ 8 | target: `${PUBLISHED_AT}::messenger_protocol::wormhole`, 9 | arguments: [], 10 | }); 11 | } 12 | 13 | export function allbridge(tx: Transaction) { 14 | return tx.moveCall({ 15 | target: `${PUBLISHED_AT}::messenger_protocol::allbridge`, 16 | arguments: [], 17 | }); 18 | } 19 | 20 | export function id(tx: Transaction, messengerProtocol: TransactionObjectInput) { 21 | return tx.moveCall({ 22 | target: `${PUBLISHED_AT}::messenger_protocol::id`, 23 | arguments: [obj(tx, messengerProtocol)], 24 | }); 25 | } 26 | -------------------------------------------------------------------------------- /src/services/models/sui/utils/set/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { GenericArg, generic, obj } from "../../_framework/util"; 4 | import { Transaction, TransactionObjectInput } from "@mysten/sui/transactions"; 5 | 6 | export interface AddArgs { 7 | set: TransactionObjectInput; 8 | key: GenericArg; 9 | } 10 | 11 | export function add(tx: Transaction, typeArg: string, args: AddArgs) { 12 | return tx.moveCall({ 13 | target: `${PUBLISHED_AT}::set::add`, 14 | typeArguments: [typeArg], 15 | arguments: [obj(tx, args.set), generic(tx, `${typeArg}`, args.key)], 16 | }); 17 | } 18 | 19 | export interface ContainsArgs { 20 | set: TransactionObjectInput; 21 | key: GenericArg; 22 | } 23 | 24 | export function contains(tx: Transaction, typeArg: string, args: ContainsArgs) { 25 | return tx.moveCall({ 26 | target: `${PUBLISHED_AT}::set::contains`, 27 | typeArguments: [typeArg], 28 | arguments: [obj(tx, args.set), generic(tx, `${typeArg}`, args.key)], 29 | }); 30 | } 31 | 32 | export function destroyEmpty(tx: Transaction, typeArg: string, set: TransactionObjectInput) { 33 | return tx.moveCall({ 34 | target: `${PUBLISHED_AT}::set::destroy_empty`, 35 | typeArguments: [typeArg], 36 | arguments: [obj(tx, set)], 37 | }); 38 | } 39 | 40 | export interface RemoveArgs { 41 | set: TransactionObjectInput; 42 | key: GenericArg; 43 | } 44 | 45 | export function remove(tx: Transaction, typeArg: string, args: RemoveArgs) { 46 | return tx.moveCall({ 47 | target: `${PUBLISHED_AT}::set::remove`, 48 | typeArguments: [typeArg], 49 | arguments: [obj(tx, args.set), generic(tx, `${typeArg}`, args.key)], 50 | }); 51 | } 52 | 53 | export function new_(tx: Transaction, typeArg: string) { 54 | return tx.moveCall({ 55 | target: `${PUBLISHED_AT}::set::new`, 56 | typeArguments: [typeArg], 57 | arguments: [], 58 | }); 59 | } 60 | -------------------------------------------------------------------------------- /src/services/models/sui/utils/version/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { GenericArg, generic, obj, pure } from "../../_framework/util"; 4 | import { Transaction, TransactionArgument, TransactionObjectInput } from "@mysten/sui/transactions"; 5 | 6 | export interface AssertVersionArgs { 7 | id: TransactionObjectInput; 8 | version: bigint | TransactionArgument; 9 | } 10 | 11 | export function assertVersion(tx: Transaction, typeArg: string, args: AssertVersionArgs) { 12 | return tx.moveCall({ 13 | target: `${PUBLISHED_AT}::version::assert_version`, 14 | typeArguments: [typeArg], 15 | arguments: [obj(tx, args.id), pure(tx, args.version, `u64`)], 16 | }); 17 | } 18 | 19 | export interface InitVersionArgs { 20 | cap: GenericArg; 21 | id: TransactionObjectInput; 22 | version: bigint | TransactionArgument; 23 | } 24 | 25 | export function initVersion(tx: Transaction, typeArg: string, args: InitVersionArgs) { 26 | return tx.moveCall({ 27 | target: `${PUBLISHED_AT}::version::init_version`, 28 | typeArguments: [typeArg], 29 | arguments: [generic(tx, `${typeArg}`, args.cap), obj(tx, args.id), pure(tx, args.version, `u64`)], 30 | }); 31 | } 32 | 33 | export interface MigrateVersionArgs { 34 | cap: GenericArg; 35 | id: TransactionObjectInput; 36 | newVersion: bigint | TransactionArgument; 37 | } 38 | 39 | export function migrateVersion(tx: Transaction, typeArg: string, args: MigrateVersionArgs) { 40 | return tx.moveCall({ 41 | target: `${PUBLISHED_AT}::version::migrate_version`, 42 | typeArguments: [typeArg], 43 | arguments: [generic(tx, `${typeArg}`, args.cap), obj(tx, args.id), pure(tx, args.newVersion, `u64`)], 44 | }); 45 | } 46 | -------------------------------------------------------------------------------- /src/services/models/sui/wormhole-messenger/events/functions.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { PUBLISHED_AT } from ".."; 3 | import { obj, pure } from "../../_framework/util"; 4 | import { Transaction, TransactionArgument, TransactionObjectInput } from "@mysten/sui/transactions"; 5 | 6 | export interface MessageReceivedEventArgs { 7 | message: TransactionObjectInput; 8 | sequence: bigint | TransactionArgument; 9 | } 10 | 11 | export function messageReceivedEvent(tx: Transaction, args: MessageReceivedEventArgs) { 12 | return tx.moveCall({ 13 | target: `${PUBLISHED_AT}::events::message_received_event`, 14 | arguments: [obj(tx, args.message), pure(tx, args.sequence, `u64`)], 15 | }); 16 | } 17 | 18 | export interface MessageSentEventArgs { 19 | message: TransactionObjectInput; 20 | sequence: bigint | TransactionArgument; 21 | } 22 | 23 | export function messageSentEvent(tx: Transaction, args: MessageSentEventArgs) { 24 | return tx.moveCall({ 25 | target: `${PUBLISHED_AT}::events::message_sent_event`, 26 | arguments: [obj(tx, args.message), pure(tx, args.sequence, `u64`)], 27 | }); 28 | } 29 | -------------------------------------------------------------------------------- /src/services/models/sui/wormhole-messenger/index.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import { compressSuiType } from "../_framework/util"; 3 | 4 | class PackageAddress { 5 | private static $PACKAGE_ID = ""; 6 | private static $PUBLISHED_AT = ""; 7 | private static $PKG_V = []; 8 | get PACKAGE_ID() { 9 | return compressSuiType(PackageAddress.$PACKAGE_ID); 10 | } 11 | get PUBLISHED_AT() { 12 | return compressSuiType(PackageAddress.$PUBLISHED_AT); 13 | } 14 | get PKG_V1() { 15 | return compressSuiType(PackageAddress.$PKG_V[1]); 16 | } 17 | setPackageId(address: string): void { 18 | PackageAddress.$PACKAGE_ID = address; 19 | } 20 | setPublishedAt(address: string): void { 21 | PackageAddress.$PUBLISHED_AT = address; 22 | } 23 | setPkgV(v: number, address: string): void { 24 | PackageAddress.$PKG_V[v] = address; 25 | } 26 | setAddress(address: string, pkgV1?: string) { 27 | PackageAddress.$PACKAGE_ID = address; 28 | PackageAddress.$PUBLISHED_AT = address; 29 | PackageAddress.$PKG_V[1] = pkgV1 || address; 30 | } 31 | } 32 | const packageAddress = new PackageAddress(); 33 | export = packageAddress; 34 | -------------------------------------------------------------------------------- /src/services/models/sui/wormhole-messenger/init.ts: -------------------------------------------------------------------------------- 1 | // @ts-nocheck 2 | import * as events from "./events/structs"; 3 | import * as wormholeMessenger from "./wormhole-messenger/structs"; 4 | import { StructClassLoader } from "../_framework/loader"; 5 | 6 | export function registerClasses(loader: StructClassLoader) { 7 | loader.register(events.MessageReceivedEvent); 8 | loader.register(events.MessageSentEvent); 9 | loader.register(wormholeMessenger.AdminCap); 10 | loader.register(wormholeMessenger.WormholeMessenger); 11 | } 12 | -------------------------------------------------------------------------------- /src/services/token/models/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./token.model"; 2 | export { ChainTokenService } from "./token"; 3 | -------------------------------------------------------------------------------- /src/services/token/models/token.model.ts: -------------------------------------------------------------------------------- 1 | import { Big } from "big.js"; 2 | import { FeePaymentMethod } from "../../../models"; 3 | import { TokenWithChainDetails } from "../../../tokens-info"; 4 | 5 | export interface ApproveParams { 6 | /** 7 | * The token info 8 | */ 9 | token: TokenWithChainDetails; 10 | 11 | /** 12 | * The address of the token owner who is granting permission to use tokens 13 | * to the spender 14 | */ 15 | owner: string; 16 | 17 | /** 18 | * The address of the contract that is being granted permission to use tokens 19 | */ 20 | spender: string; 21 | 22 | /** 23 | * The integer amount of tokens to approve. 24 | * Optional. 25 | * The maximum amount by default. 26 | */ 27 | amount?: string | number | Big; 28 | } 29 | 30 | export interface GetTokenBalanceParams { 31 | /** 32 | * The address for which we will find out the token balance 33 | */ 34 | account: string; 35 | token: TokenWithChainDetails; 36 | } 37 | 38 | export interface CheckAllowanceParams extends GetAllowanceParams { 39 | /** 40 | * The float amount of tokens to check the allowance. 41 | */ 42 | amount: string | number | Big; 43 | } 44 | 45 | export interface GetAllowanceParams { 46 | token: TokenWithChainDetails; 47 | spender: string; 48 | owner: string; 49 | gasFeePaymentMethod?: FeePaymentMethod; 50 | } 51 | 52 | export interface ApproveParamsDto { 53 | tokenAddress: string; 54 | chainSymbol: string; 55 | owner: string; 56 | spender: string; 57 | /** 58 | * Integer amount of tokens to approve. 59 | */ 60 | amount?: string; 61 | } 62 | 63 | export type GetAllowanceParamsDto = GetAllowanceParams; 64 | 65 | /** 66 | * @internal 67 | */ 68 | export interface CheckAllowanceParamsDto extends GetAllowanceParamsDto { 69 | /** 70 | * The integer amount of tokens to check the allowance. 71 | */ 72 | amount: string | number | Big; 73 | } 74 | -------------------------------------------------------------------------------- /src/services/token/models/token.ts: -------------------------------------------------------------------------------- 1 | import { Big } from "big.js"; 2 | import { ChainType } from "../../../chains/chain.enums"; 3 | import { AllbridgeCoreClient } from "../../../client/core-api/core-client-base"; 4 | import { GetNativeTokenBalanceParams } from "../../bridge/models"; 5 | import { RawTransaction, TransactionResponse } from "../../models"; 6 | import { ApproveParamsDto, CheckAllowanceParamsDto, GetAllowanceParamsDto, GetTokenBalanceParams } from "./token.model"; 7 | 8 | export abstract class ChainTokenService { 9 | abstract chainType: ChainType; 10 | abstract api: AllbridgeCoreClient; 11 | 12 | abstract getTokenBalance(params: GetTokenBalanceParams): Promise; 13 | 14 | abstract getNativeTokenBalance(params: GetNativeTokenBalanceParams): Promise; 15 | 16 | abstract getAllowance(params: GetAllowanceParamsDto): Promise; 17 | 18 | async checkAllowance(params: CheckAllowanceParamsDto): Promise { 19 | const allowance = await this.getAllowance(params); 20 | return Big(allowance).gte(Big(params.amount)); 21 | } 22 | 23 | abstract approve(params: ApproveParamsDto): Promise; 24 | 25 | abstract buildRawTransactionApprove(params: ApproveParamsDto): Promise; 26 | } 27 | -------------------------------------------------------------------------------- /src/services/token/sui/index.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-unused-vars */ 2 | import { SuiClient } from "@mysten/sui/client"; 3 | import { CoinStruct } from "@mysten/sui/src/client/types/generated"; 4 | import { ChainType } from "../../../chains/chain.enums"; 5 | import { AllbridgeCoreClient } from "../../../client/core-api/core-client-base"; 6 | import { MethodNotSupportedError, SdkError } from "../../../exceptions"; 7 | import { GetNativeTokenBalanceParams } from "../../bridge/models"; 8 | import { RawTransaction, TransactionResponse } from "../../models"; 9 | import { fetchAllPagesRecursive } from "../../utils/sui/paginated"; 10 | import { ApproveParamsDto, ChainTokenService, GetAllowanceParamsDto, GetTokenBalanceParams } from "../models"; 11 | 12 | export class SuiTokenService extends ChainTokenService { 13 | chainType: ChainType.SUI = ChainType.SUI; 14 | private suiClient: SuiClient; 15 | 16 | constructor( 17 | public suiRpcUrl: string, 18 | public api: AllbridgeCoreClient 19 | ) { 20 | super(); 21 | this.suiClient = new SuiClient({ 22 | url: this.suiRpcUrl, 23 | }); 24 | } 25 | 26 | approve(params: ApproveParamsDto): Promise { 27 | throw new MethodNotSupportedError(); 28 | } 29 | 30 | buildRawTransactionApprove(params: ApproveParamsDto): Promise { 31 | throw new MethodNotSupportedError(); 32 | } 33 | 34 | getAllowance(params: GetAllowanceParamsDto): Promise { 35 | throw new MethodNotSupportedError(); 36 | } 37 | 38 | async getTokenBalance(params: GetTokenBalanceParams): Promise { 39 | if (!params.token.originTokenAddress) { 40 | throw new SdkError("SUI token must contain 'originTokenAddress'"); 41 | } 42 | const balance = await this.suiClient.getBalance({ 43 | owner: params.account, 44 | coinType: params.token.originTokenAddress, 45 | }); 46 | return balance.totalBalance; 47 | } 48 | 49 | async getNativeTokenBalance(params: GetNativeTokenBalanceParams): Promise { 50 | const coinsData: CoinStruct[] = await fetchAllPagesRecursive((cursor: string | null | undefined) => 51 | this.suiClient.getCoins({ 52 | owner: params.account, 53 | cursor, 54 | }) 55 | ); 56 | if (coinsData.length === 0) { 57 | return "0"; 58 | } 59 | return coinsData.reduce((total, element) => total + BigInt(element.balance), BigInt(0)).toString(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/services/utils/calculation/index.ts: -------------------------------------------------------------------------------- 1 | import { Big } from "big.js"; 2 | import { convertFloatAmountToInt, getD } from "../../../utils/calculation"; 3 | import { SYSTEM_PRECISION } from "../../../utils/calculation/constants"; 4 | 5 | export function depositAmountToVUsd( 6 | amount: string, 7 | aValue: string, 8 | dValue: string, 9 | tokenBalance: string, 10 | vUsdBalance: string 11 | ): string { 12 | const amountSP = convertFloatAmountToInt(amount, SYSTEM_PRECISION); 13 | const amountSPBig = Big(amountSP); 14 | 15 | const oldD = Big(dValue); 16 | const oldBalance = Big(tokenBalance).plus(vUsdBalance); 17 | 18 | let newTokenBalance; 19 | let newVUsdBalance; 20 | 21 | if (oldD.eq(0) || oldBalance.eq(0)) { 22 | const halfAmount = amountSPBig.div(2); 23 | newTokenBalance = Big(tokenBalance).plus(halfAmount); 24 | newVUsdBalance = Big(vUsdBalance).plus(halfAmount); 25 | } else { 26 | newTokenBalance = Big(tokenBalance).plus(amountSPBig.mul(tokenBalance).div(oldBalance)); 27 | newVUsdBalance = Big(vUsdBalance).plus(amountSPBig.mul(vUsdBalance).div(oldBalance)); 28 | } 29 | const newD = Big(getD(aValue, newTokenBalance.toFixed(), newVUsdBalance.toFixed())); 30 | return newD.minus(oldD).toFixed(); 31 | } 32 | 33 | export function vUsdToWithdrawalAmount(lpAmount: string): string { 34 | const lpAmountSP = convertFloatAmountToInt(lpAmount, SYSTEM_PRECISION); 35 | return Big(lpAmountSP).round().toFixed(); 36 | } 37 | -------------------------------------------------------------------------------- /src/services/utils/index.ts: -------------------------------------------------------------------------------- 1 | import BN from "bn.js"; 2 | 3 | export function amountToHex(amount: string): string { 4 | return "0x" + new BN(amount).toString("hex"); 5 | } 6 | 7 | export function sleep(ms: number): Promise { 8 | return new Promise((resolve) => setTimeout(() => resolve(), ms)); 9 | } 10 | 11 | export const promisify = 12 | // prettier-ignore 13 | // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type 14 | (func: Function) => 15 | (...args: any[]) => 16 | new Promise( 17 | (resolve, reject) => 18 | func(...args, (err: Error, result: any) => (err ? reject(err) : resolve(result))) 19 | ); 20 | -------------------------------------------------------------------------------- /src/services/utils/sol/anchor-provider.ts: -------------------------------------------------------------------------------- 1 | import { AnchorProvider, Provider } from "@project-serum/anchor"; 2 | import { Connection, PublicKey } from "@solana/web3.js"; 3 | 4 | export function buildAnchorProvider(solanaRpcUrl: string, accountAddress: string): Provider { 5 | const connection = new Connection(solanaRpcUrl, "confirmed"); 6 | 7 | const publicKey = new PublicKey(accountAddress); 8 | 9 | return new AnchorProvider( 10 | connection, 11 | // @ts-expect-error enough wallet for fetch actions 12 | { publicKey: publicKey }, 13 | { 14 | preflightCommitment: "confirmed", 15 | commitment: "confirmed", 16 | } 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /src/services/utils/sui/coins.ts: -------------------------------------------------------------------------------- 1 | import { CoinStruct } from "@mysten/sui/client"; 2 | import { Transaction } from "@mysten/sui/transactions"; 3 | 4 | export function getCoinsWithAmounts(amounts: string[], coins: CoinStruct[], tx: Transaction) { 5 | if (coins.length === 0 || !coins[0]) { 6 | return []; 7 | } 8 | const firstCoin = coins[0]; 9 | const requiredAmount = amounts.reduce((total, amount) => total + BigInt(amount), BigInt(0)); 10 | 11 | let currentBalance = BigInt(firstCoin.balance); 12 | const accumulatedCoins: CoinStruct[] = []; 13 | 14 | for (const coin of coins.slice(1)) { 15 | if (currentBalance > requiredAmount) { 16 | return splitAndMergeCoins(tx, firstCoin, accumulatedCoins, amounts); 17 | } else { 18 | currentBalance += BigInt(coin.balance); 19 | accumulatedCoins.push(coin); 20 | } 21 | } 22 | 23 | if (currentBalance >= requiredAmount) { 24 | return splitAndMergeCoins(tx, firstCoin, accumulatedCoins, amounts); 25 | } else { 26 | return []; 27 | } 28 | } 29 | 30 | function splitAndMergeCoins(tx: Transaction, firstCoin: CoinStruct, accumulatedCoins: CoinStruct[], amounts: string[]) { 31 | const pureAmounts = amounts.map((amount) => { 32 | return tx.pure.u64(amount); 33 | }); 34 | if (accumulatedCoins.length > 0) { 35 | tx.mergeCoins( 36 | firstCoin.coinObjectId, 37 | accumulatedCoins.map((c) => c.coinObjectId) 38 | ); 39 | return tx.splitCoins(firstCoin.coinObjectId, pureAmounts); 40 | } 41 | 42 | return tx.splitCoins(firstCoin.coinObjectId, pureAmounts); 43 | } 44 | -------------------------------------------------------------------------------- /src/services/utils/sui/paginated.ts: -------------------------------------------------------------------------------- 1 | interface PaginatedResults { 2 | data: Data[]; 3 | hasNextPage: boolean; 4 | nextCursor?: string | null; 5 | } 6 | 7 | export async function fetchAllPagesRecursive>( 8 | fetchFunction: (cursor?: string | null) => Promise, 9 | cursor?: string | null, 10 | accumulatedData: Data[] = [] 11 | ): Promise { 12 | const result = await fetchFunction(cursor); 13 | const newAccumulatedData = accumulatedData.concat(result.data); 14 | 15 | if (result.hasNextPage && result.nextCursor) { 16 | return fetchAllPagesRecursive(fetchFunction, result.nextCursor, newAccumulatedData); 17 | } else { 18 | return newAccumulatedData; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/services/utils/sui/view.ts: -------------------------------------------------------------------------------- 1 | import { SuiClient } from "@mysten/sui/client"; 2 | import { Transaction } from "@mysten/sui/transactions"; 3 | import { Reified, toBcs, ToJSON, TypeArgument } from "../../models/sui/_framework/reified"; 4 | 5 | const mockSender = "0x0000000000000000000000000000000000000000000000000000000000000000"; 6 | 7 | export async function suiView( 8 | client: SuiClient, 9 | tx: Transaction, 10 | reified: Reified 11 | ): Promise> { 12 | const inspectionResult = await client.devInspectTransactionBlock({ 13 | sender: mockSender, 14 | transactionBlock: tx, 15 | }); 16 | if (inspectionResult.effects.status.status !== "success") { 17 | throw new Error(`inspectionResult failed. ${JSON.stringify(inspectionResult, null, 2)}`); 18 | } 19 | 20 | const returnValue = inspectionResult.results?.pop()?.returnValues?.pop(); 21 | 22 | if (!returnValue) { 23 | throw new Error(`Something with inspectionResult went wrong. ${JSON.stringify(inspectionResult, null, 2)}`); 24 | } 25 | 26 | const [data, _type] = returnValue; 27 | 28 | if (typeof reified === "object") { 29 | return reified.fromBcs(Uint8Array.from(data)).toJSONField() as ToJSON; 30 | } else { 31 | return toBcs(reified).parse(Uint8Array.from(data)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/services/utils/trx/index.ts: -------------------------------------------------------------------------------- 1 | import { TronWeb } from "tronweb"; 2 | import { SignedTransaction } from "tronweb/src/types/Transaction"; 3 | import { InvalidTxError, VerifyTxError } from "../../../exceptions"; 4 | import { RawTransaction } from "../../models"; 5 | import { sleep } from "../index"; 6 | 7 | export async function sendRawTransaction(tronWeb: TronWeb, rawTransaction: RawTransaction): Promise<{ txId: string }> { 8 | const signedTx = await tronWeb.trx.sign(rawTransaction as any); 9 | 10 | if (!(signedTx as SignedTransaction).signature) { 11 | throw new InvalidTxError("Transaction was not signed properly"); 12 | } 13 | 14 | const receipt = await tronWeb.trx.sendRawTransaction(signedTx); 15 | const transactionHash = receipt.transaction.txID; 16 | await verifyTx(tronWeb, transactionHash); 17 | return { txId: transactionHash }; 18 | } 19 | 20 | export async function verifyTx(tronWeb: TronWeb, txId: string, timeout = 10000): Promise { 21 | const start = Date.now(); 22 | 23 | while (true) { 24 | if (Date.now() - start > timeout) { 25 | throw new VerifyTxError("Transaction not found"); 26 | } 27 | const result = await tronWeb.trx.getUnconfirmedTransactionInfo(txId); 28 | if (!result?.receipt) { 29 | await sleep(2000); 30 | continue; 31 | } 32 | if (result.receipt.result === "SUCCESS") { 33 | return result; 34 | } else { 35 | throw new VerifyTxError(`Transaction status is ${result.receipt.result}`); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/tokens-info/index.ts: -------------------------------------------------------------------------------- 1 | import { SdkError } from "../exceptions"; 2 | import { ChainDetailsMap, TokenWithChainDetails } from "./tokens-info.model"; 3 | 4 | export * from "./tokens-info.model"; 5 | 6 | export class TokensInfo { 7 | /** 8 | * @internal 9 | */ 10 | private readonly _map: ChainDetailsMap; 11 | 12 | /** 13 | * @internal 14 | * @param map 15 | */ 16 | constructor(map: ChainDetailsMap) { 17 | this._map = map; 18 | } 19 | 20 | /** 21 | * Returns {@link ChainDetailsMap} containing a list of supported tokens groped by chain. 22 | */ 23 | chainDetailsMap(): ChainDetailsMap { 24 | return this._map; 25 | } 26 | 27 | /** 28 | * Returns a list of supported {@link TokenWithChainDetails | tokens}. 29 | */ 30 | tokens(): TokenWithChainDetails[] { 31 | return Object.values(this._map).flatMap((chainDetails) => chainDetails.tokens); 32 | } 33 | 34 | /** 35 | * Returns a list of supported {@link TokenWithChainDetails | tokens} on the selected chain. 36 | */ 37 | tokensByChain(chainSymbol: string): TokenWithChainDetails[] { 38 | const chainDetails = this._map[chainSymbol]; 39 | if (!chainDetails) { 40 | throw new SdkError(`Chain details not found for chain symbol: ${chainSymbol}`); 41 | } 42 | return chainDetails.tokens; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/utils/calculation/constants.ts: -------------------------------------------------------------------------------- 1 | export const SYSTEM_PRECISION = 3; 2 | -------------------------------------------------------------------------------- /src/utils/calculation/swap-and-bridge-details.ts: -------------------------------------------------------------------------------- 1 | import { Big } from "big.js"; 2 | import { PoolInfo, TokenWithChainDetails } from "../../tokens-info"; 3 | import { convertIntAmountToFloat, fromSystemPrecision, swapFromVUsd, swapToVUsd } from "./index"; 4 | 5 | export interface SendAmountDetails { 6 | sourceLPSwap: AmountImpact; 7 | destLPSwap: AmountImpact; 8 | } 9 | 10 | export interface AmountImpact { 11 | fee: string; 12 | swap: string; 13 | } 14 | 15 | export function getSendAmountDetails( 16 | amountInTokenPrecision: string, 17 | sourceToken: TokenWithChainDetails, 18 | sourcePool: PoolInfo, 19 | destToken: TokenWithChainDetails, 20 | destPool: PoolInfo 21 | ): SendAmountDetails { 22 | const vUsd = swapToVUsd(amountInTokenPrecision, sourceToken, sourcePool); 23 | const vUsdInTokenPrecision = fromSystemPrecision(vUsd, sourceToken.decimals); 24 | const result = swapFromVUsd(vUsd, destToken, destPool); 25 | 26 | const swapToFeeInt = Big(amountInTokenPrecision).times(sourceToken.feeShare); 27 | const swapFromFeeInt = Big(result).div(Big(1).minus(destToken.feeShare)).minus(result); 28 | return { 29 | sourceLPSwap: { 30 | fee: convertIntAmountToFloat(swapToFeeInt, sourceToken.decimals) 31 | .neg() 32 | .round(sourceToken.decimals, Big.roundUp) 33 | .toFixed(), 34 | swap: convertIntAmountToFloat( 35 | Big(amountInTokenPrecision).minus(vUsdInTokenPrecision).minus(swapToFeeInt), 36 | sourceToken.decimals 37 | ) 38 | .neg() 39 | .round(sourceToken.decimals, Big.roundUp) 40 | .toFixed(), 41 | }, 42 | destLPSwap: { 43 | fee: convertIntAmountToFloat(swapFromFeeInt, destToken.decimals) 44 | .neg() 45 | .round(destToken.decimals, Big.roundUp) 46 | .toFixed(), 47 | swap: convertIntAmountToFloat( 48 | fromSystemPrecision(vUsd, destToken.decimals).minus(result).minus(swapFromFeeInt), 49 | destToken.decimals 50 | ) 51 | .neg() 52 | .round(destToken.decimals, Big.roundUp) 53 | .toFixed(), 54 | }, 55 | }; 56 | } 57 | -------------------------------------------------------------------------------- /src/utils/index.ts: -------------------------------------------------------------------------------- 1 | import { AllbridgeCoreSdkOptions } from "../index"; 2 | import { NodeRpcUrlsConfig } from "../services"; 3 | import { DefaultSolUtils, SolUtils } from "./sol"; 4 | import { DefaultSrbUtils, SrbUtils } from "./srb"; 5 | 6 | /** 7 | * Contains usefully methods 8 | */ 9 | export interface Utils { 10 | srb: SrbUtils; 11 | sol: SolUtils; 12 | } 13 | 14 | export class DefaultUtils implements Utils { 15 | srb: SrbUtils; 16 | sol: SolUtils; 17 | 18 | constructor( 19 | readonly nodeRpcUrlsConfig: NodeRpcUrlsConfig, 20 | params: AllbridgeCoreSdkOptions 21 | ) { 22 | this.srb = new DefaultSrbUtils(nodeRpcUrlsConfig, params); 23 | this.sol = new DefaultSolUtils(nodeRpcUrlsConfig, params); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/utils/sol/index.ts: -------------------------------------------------------------------------------- 1 | import { Connection, PublicKey, TransactionMessage, VersionedTransaction } from "@solana/web3.js"; 2 | import { ChainSymbol } from "../../chains/chain.enums"; 3 | import { AllbridgeCoreSdkOptions, SdkError } from "../../index"; 4 | import { NodeRpcUrlsConfig } from "../../services"; 5 | import { fetchAddressLookupTableAccountsFromTx } from "./utils"; 6 | 7 | /** 8 | * Contains usefully Solana methods 9 | */ 10 | export interface SolUtils { 11 | /** 12 | * Add memo to solana's transaction 13 | * @param transaction transaction to add memo 14 | * @param memo memo to add (28 char max) 15 | */ 16 | addMemoToTx(transaction: VersionedTransaction, memo: string): Promise; 17 | } 18 | 19 | export class DefaultSolUtils implements SolUtils { 20 | constructor( 21 | readonly nodeRpcUrlsConfig: NodeRpcUrlsConfig, 22 | readonly params: AllbridgeCoreSdkOptions 23 | ) {} 24 | 25 | async addMemoToTx(transaction: VersionedTransaction, memo: string): Promise { 26 | if (memo.length > 28) { 27 | throw new SdkError("InvalidArgumentException memo cannot be more than 28 characters"); 28 | } 29 | const connection = new Connection(this.nodeRpcUrlsConfig.getNodeRpcUrl(ChainSymbol.SOL), "confirmed"); 30 | const addressLookupTableAccounts = await fetchAddressLookupTableAccountsFromTx(transaction, connection); 31 | const message = TransactionMessage.decompile(transaction.message, { 32 | addressLookupTableAccounts: addressLookupTableAccounts, 33 | }); 34 | const lastInstruction = message.instructions[message.instructions.length - 1]; 35 | if (!lastInstruction?.keys) { 36 | throw new SdkError("Last instruction or its keys are invalid."); 37 | } 38 | 39 | lastInstruction.keys.push({ 40 | pubkey: new PublicKey(Buffer.from(memo)), 41 | isSigner: false, 42 | isWritable: false, 43 | }); 44 | transaction.message = message.compileToV0Message(addressLookupTableAccounts); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/utils/sol/utils.ts: -------------------------------------------------------------------------------- 1 | import { AddressLookupTableAccount, Connection, VersionedTransaction } from "@solana/web3.js"; 2 | import { SdkError } from "../../exceptions"; 3 | 4 | export async function fetchAddressLookupTableAccountsFromTx( 5 | transaction: VersionedTransaction, 6 | connection: Connection 7 | ): Promise { 8 | return await Promise.all( 9 | transaction.message.addressTableLookups.map(async (lookup) => { 10 | return new AddressLookupTableAccount({ 11 | key: lookup.accountKey, 12 | state: AddressLookupTableAccount.deserialize( 13 | await connection.getAccountInfo(lookup.accountKey).then((res) => { 14 | if (!res) { 15 | throw new SdkError("Cannot get AccountInfo"); 16 | } 17 | return res.data; 18 | }) 19 | ), 20 | }); 21 | }) 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /src/version.ts: -------------------------------------------------------------------------------- 1 | export const VERSION = "0.0.0-development"; 2 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": ["./src/**/*.ts"], 3 | "exclude": [ 4 | "./src/**/__tests__", 5 | "node_modules" 6 | ], 7 | "compilerOptions": { 8 | "lib": [ 9 | "es2022" 10 | ], 11 | "module": "commonjs", 12 | "target": "es2022", 13 | 14 | "rootDir": "./", 15 | "outDir": "dist", 16 | 17 | "strict": true, 18 | "sourceMap": true, 19 | "esModuleInterop": true, 20 | "skipLibCheck": true, 21 | "forceConsistentCasingInFileNames": true, 22 | "declaration": true, 23 | "resolveJsonModule": true, 24 | "allowJs": true, 25 | "noUncheckedIndexedAccess": true, 26 | "allowSyntheticDefaultImports": true, 27 | "inlineSources": true, 28 | "strictFunctionTypes": true 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tsconfig.lint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": [] 4 | } 5 | --------------------------------------------------------------------------------