@avalabs/bridge-unified 0.0.0-hello-world-20230824162317
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +22 -0
- package/.turbo/turbo-lint.log +4 -0
- package/CHANGELOG.md +9 -0
- package/README.md +39 -0
- package/dist/index.cjs +7 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +36 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/package.json +22 -0
- package/src/errors/index.ts +20 -0
- package/src/handlers/check-for-pending-bridge-journey.ts +20 -0
- package/src/handlers/execute-bridge-journey-step.ts +20 -0
- package/src/handlers/plan-bridge-journey.ts +25 -0
- package/src/index.ts +2 -0
- package/src/unified-bridge-service.ts +19 -0
- package/tsconfig.json +8 -0
- package/tsup.config.ts +4 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
> @avalabs/bridge-unified@1.0.1 build /home/runner/work/consumer-sdks/consumer-sdks/packages/bridge-unified
|
|
3
|
+
> tsup
|
|
4
|
+
|
|
5
|
+
[34mCLI[39m Building entry: ./src/index.ts
|
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m tsup v7.2.0
|
|
8
|
+
[34mCLI[39m Using tsup config: /home/runner/work/consumer-sdks/consumer-sdks/packages/bridge-unified/tsup.config.ts
|
|
9
|
+
[34mCLI[39m Target: es2021
|
|
10
|
+
[34mCLI[39m Cleaning output folder
|
|
11
|
+
[34mCJS[39m Build start
|
|
12
|
+
[34mESM[39m Build start
|
|
13
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m496.00 B[39m
|
|
14
|
+
[32mCJS[39m [1mdist/index.cjs.map [22m[32m4.71 KB[39m
|
|
15
|
+
[32mCJS[39m ⚡️ Build success in 730ms
|
|
16
|
+
[32mESM[39m [1mdist/index.js [22m[32m484.00 B[39m
|
|
17
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m4.71 KB[39m
|
|
18
|
+
[32mESM[39m ⚡️ Build success in 746ms
|
|
19
|
+
[34mDTS[39m Build start
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 8791ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m1.25 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m1.25 KB[39m
|
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://subnets.avax.network/">
|
|
3
|
+
<picture>
|
|
4
|
+
<img alt="Avalanche Logo" src="https://images.ctfassets.net/gcj8jwzm6086/Gse8dqDEnJtT87RsbbEf4/1609daeb09e9db4a6617d44623028356/Avalanche_Horizontal_White.svg" width="auto" height="60">
|
|
5
|
+
</picture>
|
|
6
|
+
</a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
A package for routing tokens from Chain A to Chain B, and unifying multiple bridge tools into one.
|
|
11
|
+
<p>
|
|
12
|
+
|
|
13
|
+
## What is this?
|
|
14
|
+
|
|
15
|
+
The bridging ecosystem is complex. There are often multiple tools that can be used to bridge tokens from one chain to another, and sometimes to get a token from chain A to C you need to use multiple bridging tools and route through chain B first. This package simplifies that process by creating the _Unified Bridge API_, a standard interface for bridging tokens from one chain to another without having to worry about the underlying tools or the underlying intermediary chains.
|
|
16
|
+
|
|
17
|
+
These are the bridges we currently support:
|
|
18
|
+
|
|
19
|
+
- **Avalanche Bridge** - is capable of transferring a fixed list of tokens between Ethereum and Avalanche C-Chain. See the `@avalabs/bridge-avalanche` package.
|
|
20
|
+
- **CCTP** - preferred for brdiging USDC between Ethereum and Avalanche C-Chain. See the `@avalabs/bridge-cctp` package.
|
|
21
|
+
|
|
22
|
+
Future bridges we plan to support:
|
|
23
|
+
|
|
24
|
+
- **Teleporter** - for moving tokens between subnets.
|
|
25
|
+
- **Cross-Chain Transfer** - for moving tokens between the three Avalanche Primary Network chains (X-Chain, C-Chain, and P-Chain).
|
|
26
|
+
|
|
27
|
+
## Getting Started
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npm install @avalabs/bridge-unified
|
|
31
|
+
# or
|
|
32
|
+
yarn add @avalabs/bridge-unified
|
|
33
|
+
# or
|
|
34
|
+
pnpm add @avalabs/bridge-unified
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## How it works
|
|
38
|
+
|
|
39
|
+
TODO: Explain details of this api.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var o=class extends Error{constructor(s,a){super(s);this.code=a;this.code=a;}},e=class extends o{constructor(t="Not implemented"){super(t,5001),this.name="NotImplementedError";}};var n=async r=>{throw new e};var i=r=>{throw new e};var m=async({address:r,chainIds:t})=>{throw new e};var O=r=>({planBridgeJourney:i,executeBridgeJourneyStep:n,checkForPendingBridgeJourney:m});
|
|
4
|
+
|
|
5
|
+
exports.createUnifiedBridgeService = O;
|
|
6
|
+
//# sourceMappingURL=out.js.map
|
|
7
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors/index.ts","../src/handlers/execute-bridge-journey-step.ts","../../../packages-internal/bridge-shared/src/constants/constants.ts","../src/handlers/plan-bridge-journey.ts","../src/handlers/check-for-pending-bridge-journey.ts","../src/unified-bridge-service.ts"],"names":["BridgeError","message","code","NotImplementedError","executeBridgeJourneyStep","_params","ETHEREUM_INFO","planBridgeJourney","checkForPendingBridgeJourney","_address","_chainIds","createUnifiedBridgeService","_options"],"mappings":"AAIA,IAAMA,EAAN,cAA0B,KAAM,CAC9B,YACEC,EACOC,EACP,CACA,MAAMD,CAAO,EAFN,UAAAC,EAGP,KAAK,KAAOA,CACd,CACF,EAEaC,EAAN,cAAkCH,CAAY,CACnD,YAAYC,EAAU,kBAAmB,CACvC,MAAMA,EAAS,IAAyB,EACxC,KAAK,KAAO,qBACd,CACF,ECZO,IAAMG,EAA2B,MAAOC,GAA4C,CAWzF,MAAM,IAAIF,CACZ,ECjBO,IAAMG,EAAgB,CAC3B,aACA,WAAY,IACZ,sBAAuB,GACvB,OAAQ,+DACV,ECcO,IAAMC,EAAqBF,GAA4D,CAE5F,MAAM,IAAIF,CACZ,ECjBO,IAAMK,EAA+B,MAAO,CACjD,QAASC,EACT,SAAUC,CACZ,IAGM,CAKJ,MAAM,IAAIP,CACZ,ECPO,IAAMQ,EAA8BC,IAClC,CACL,kBAAAL,EACA,yBAAAH,EACA,6BAAAI,CACF","sourcesContent":["export enum ErrorCode {\n NOT_IMPLEMENTED = 5001,\n}\n\nclass BridgeError extends Error {\n constructor(\n message: string,\n public code: ErrorCode,\n ) {\n super(message);\n this.code = code;\n }\n}\n\nexport class NotImplementedError extends BridgeError {\n constructor(message = 'Not implemented') {\n super(message, ErrorCode.NOT_IMPLEMENTED);\n this.name = 'NotImplementedError';\n }\n}\n","import { NotImplementedError } from '../errors';\n\ntype ExecuteBridgeJourneyStepParams = {\n stepIndex: number;\n journey: unknown;\n};\n\nexport const executeBridgeJourneyStep = async (_params: ExecuteBridgeJourneyStepParams) => {\n /**\n * 1. Validate the journey\n * 3. Forward request along to the right bridge platform's package.\n * 4. Return an observable that emits events when:\n * - User signs the transaction (returns the fromChain txId)\n * - Every block confirmation on fromChain\n * - fromChain tx completed, starting the toChain tx (returns the toChainTxId)\n * - Every block confirmation on toChain\n * - toChain tx completed\n */\n throw new NotImplementedError();\n};\n","import { ChainVm, type EvmChain } from '../types/chain';\n\nexport const ETHEREUM_INFO = {\n vmType: ChainVm.EthereumVM,\n evmChainId: '1',\n confirmationThreshold: 96,\n rpcUrl: 'https://mainnet.infura.io/v3/3d8a7c0b1b5a4b0e8b0b3b0f2b0b0b0b',\n} as const satisfies EvmChain;\n","import { NotImplementedError } from '../errors';\nimport { BridgePlatform, type Token } from '@internal/bridge-shared';\n\ntype GetBridgeRouterParams = {\n fromChainId: string;\n toChainId: string;\n fromToken: Token;\n};\n\ntype BridgeTransactionStep = {\n fromChainId: string;\n toChainId: string;\n bridgePlatform: BridgePlatform;\n fromToken: Token;\n toToken: Token;\n};\n\n/**\n * Returns a list of transaction steps needed to complete a bridge from chain A to B.\n * The response may include multiple steps if the bridge requires multiple hops.\n */\nexport const planBridgeJourney = (_params: GetBridgeRouterParams): BridgeTransactionStep[] => {\n // Implement smart logic for determining how to get the token from chain A to B\n throw new NotImplementedError();\n};\n","import type { Address } from 'viem';\nimport { NotImplementedError } from '../errors';\n\n/**\n * Checks for any currently pending bridge transactions. Useful for dApps that want\n * to display the current tx's status after a page refresh.\n */\nexport const checkForPendingBridgeJourney = async ({\n address: _address,\n chainIds: _chainIds,\n}: {\n address: Address;\n chainIds: string[];\n}) => {\n /**\n * 1. If wallet is Core, request current bridge journey. Otherwise, check glacier to see if the provided wallet has bridge tx in the past 100 transactions on the provided chains.\n * 3. Returns an array of txIds for all pending transactions\n */\n throw new NotImplementedError();\n};\n","import { executeBridgeJourneyStep } from './handlers/execute-bridge-journey-step';\nimport { planBridgeJourney } from './handlers/plan-bridge-journey';\n\nimport type { Environment, MaybePromise, NativeToken } from '@internal/bridge-shared';\nimport { checkForPendingBridgeJourney } from './handlers/check-for-pending-bridge-journey';\n\nexport type BridgeServiceConfig = {\n environment: `${Environment}`;\n getChainNativeAsset: ({ evmChainId }: { evmChainId: string }) => MaybePromise<NativeToken>;\n getChainErc20Asset: ({ evmChainId, address }: { evmChainId: string; address: string }) => MaybePromise<NativeToken>;\n};\n\nexport const createUnifiedBridgeService = (_options: BridgeServiceConfig) => {\n return {\n planBridgeJourney,\n executeBridgeJourneyStep,\n checkForPendingBridgeJourney,\n };\n};\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as _internal_bridge_shared from '@internal/bridge-shared';
|
|
2
|
+
import { Environment, MaybePromise, NativeToken } from '@internal/bridge-shared';
|
|
3
|
+
|
|
4
|
+
type BridgeServiceConfig = {
|
|
5
|
+
environment: `${Environment}`;
|
|
6
|
+
getChainNativeAsset: ({ evmChainId }: {
|
|
7
|
+
evmChainId: string;
|
|
8
|
+
}) => MaybePromise<NativeToken>;
|
|
9
|
+
getChainErc20Asset: ({ evmChainId, address }: {
|
|
10
|
+
evmChainId: string;
|
|
11
|
+
address: string;
|
|
12
|
+
}) => MaybePromise<NativeToken>;
|
|
13
|
+
};
|
|
14
|
+
declare const createUnifiedBridgeService: (_options: BridgeServiceConfig) => {
|
|
15
|
+
planBridgeJourney: (_params: {
|
|
16
|
+
fromChainId: string;
|
|
17
|
+
toChainId: string;
|
|
18
|
+
fromToken: _internal_bridge_shared.Token;
|
|
19
|
+
}) => {
|
|
20
|
+
fromChainId: string;
|
|
21
|
+
toChainId: string;
|
|
22
|
+
bridgePlatform: _internal_bridge_shared.BridgePlatform;
|
|
23
|
+
fromToken: _internal_bridge_shared.Token;
|
|
24
|
+
toToken: _internal_bridge_shared.Token;
|
|
25
|
+
}[];
|
|
26
|
+
executeBridgeJourneyStep: (_params: {
|
|
27
|
+
stepIndex: number;
|
|
28
|
+
journey: unknown;
|
|
29
|
+
}) => Promise<never>;
|
|
30
|
+
checkForPendingBridgeJourney: ({ address: _address, chainIds: _chainIds, }: {
|
|
31
|
+
address: `0x${string}`;
|
|
32
|
+
chainIds: string[];
|
|
33
|
+
}) => Promise<never>;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { BridgeServiceConfig, createUnifiedBridgeService };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as _internal_bridge_shared from '@internal/bridge-shared';
|
|
2
|
+
import { Environment, MaybePromise, NativeToken } from '@internal/bridge-shared';
|
|
3
|
+
|
|
4
|
+
type BridgeServiceConfig = {
|
|
5
|
+
environment: `${Environment}`;
|
|
6
|
+
getChainNativeAsset: ({ evmChainId }: {
|
|
7
|
+
evmChainId: string;
|
|
8
|
+
}) => MaybePromise<NativeToken>;
|
|
9
|
+
getChainErc20Asset: ({ evmChainId, address }: {
|
|
10
|
+
evmChainId: string;
|
|
11
|
+
address: string;
|
|
12
|
+
}) => MaybePromise<NativeToken>;
|
|
13
|
+
};
|
|
14
|
+
declare const createUnifiedBridgeService: (_options: BridgeServiceConfig) => {
|
|
15
|
+
planBridgeJourney: (_params: {
|
|
16
|
+
fromChainId: string;
|
|
17
|
+
toChainId: string;
|
|
18
|
+
fromToken: _internal_bridge_shared.Token;
|
|
19
|
+
}) => {
|
|
20
|
+
fromChainId: string;
|
|
21
|
+
toChainId: string;
|
|
22
|
+
bridgePlatform: _internal_bridge_shared.BridgePlatform;
|
|
23
|
+
fromToken: _internal_bridge_shared.Token;
|
|
24
|
+
toToken: _internal_bridge_shared.Token;
|
|
25
|
+
}[];
|
|
26
|
+
executeBridgeJourneyStep: (_params: {
|
|
27
|
+
stepIndex: number;
|
|
28
|
+
journey: unknown;
|
|
29
|
+
}) => Promise<never>;
|
|
30
|
+
checkForPendingBridgeJourney: ({ address: _address, chainIds: _chainIds, }: {
|
|
31
|
+
address: `0x${string}`;
|
|
32
|
+
chainIds: string[];
|
|
33
|
+
}) => Promise<never>;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { BridgeServiceConfig, createUnifiedBridgeService };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
var o=class extends Error{constructor(s,a){super(s);this.code=a;this.code=a;}},e=class extends o{constructor(t="Not implemented"){super(t,5001),this.name="NotImplementedError";}};var n=async r=>{throw new e};var i=r=>{throw new e};var m=async({address:r,chainIds:t})=>{throw new e};var O=r=>({planBridgeJourney:i,executeBridgeJourneyStep:n,checkForPendingBridgeJourney:m});
|
|
2
|
+
|
|
3
|
+
export { O as createUnifiedBridgeService };
|
|
4
|
+
//# sourceMappingURL=out.js.map
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors/index.ts","../src/handlers/execute-bridge-journey-step.ts","../../../packages-internal/bridge-shared/src/constants/constants.ts","../src/handlers/plan-bridge-journey.ts","../src/handlers/check-for-pending-bridge-journey.ts","../src/unified-bridge-service.ts"],"names":["BridgeError","message","code","NotImplementedError","executeBridgeJourneyStep","_params","ETHEREUM_INFO","planBridgeJourney","checkForPendingBridgeJourney","_address","_chainIds","createUnifiedBridgeService","_options"],"mappings":"AAIA,IAAMA,EAAN,cAA0B,KAAM,CAC9B,YACEC,EACOC,EACP,CACA,MAAMD,CAAO,EAFN,UAAAC,EAGP,KAAK,KAAOA,CACd,CACF,EAEaC,EAAN,cAAkCH,CAAY,CACnD,YAAYC,EAAU,kBAAmB,CACvC,MAAMA,EAAS,IAAyB,EACxC,KAAK,KAAO,qBACd,CACF,ECZO,IAAMG,EAA2B,MAAOC,GAA4C,CAWzF,MAAM,IAAIF,CACZ,ECjBO,IAAMG,EAAgB,CAC3B,aACA,WAAY,IACZ,sBAAuB,GACvB,OAAQ,+DACV,ECcO,IAAMC,EAAqBF,GAA4D,CAE5F,MAAM,IAAIF,CACZ,ECjBO,IAAMK,EAA+B,MAAO,CACjD,QAASC,EACT,SAAUC,CACZ,IAGM,CAKJ,MAAM,IAAIP,CACZ,ECPO,IAAMQ,EAA8BC,IAClC,CACL,kBAAAL,EACA,yBAAAH,EACA,6BAAAI,CACF","sourcesContent":["export enum ErrorCode {\n NOT_IMPLEMENTED = 5001,\n}\n\nclass BridgeError extends Error {\n constructor(\n message: string,\n public code: ErrorCode,\n ) {\n super(message);\n this.code = code;\n }\n}\n\nexport class NotImplementedError extends BridgeError {\n constructor(message = 'Not implemented') {\n super(message, ErrorCode.NOT_IMPLEMENTED);\n this.name = 'NotImplementedError';\n }\n}\n","import { NotImplementedError } from '../errors';\n\ntype ExecuteBridgeJourneyStepParams = {\n stepIndex: number;\n journey: unknown;\n};\n\nexport const executeBridgeJourneyStep = async (_params: ExecuteBridgeJourneyStepParams) => {\n /**\n * 1. Validate the journey\n * 3. Forward request along to the right bridge platform's package.\n * 4. Return an observable that emits events when:\n * - User signs the transaction (returns the fromChain txId)\n * - Every block confirmation on fromChain\n * - fromChain tx completed, starting the toChain tx (returns the toChainTxId)\n * - Every block confirmation on toChain\n * - toChain tx completed\n */\n throw new NotImplementedError();\n};\n","import { ChainVm, type EvmChain } from '../types/chain';\n\nexport const ETHEREUM_INFO = {\n vmType: ChainVm.EthereumVM,\n evmChainId: '1',\n confirmationThreshold: 96,\n rpcUrl: 'https://mainnet.infura.io/v3/3d8a7c0b1b5a4b0e8b0b3b0f2b0b0b0b',\n} as const satisfies EvmChain;\n","import { NotImplementedError } from '../errors';\nimport { BridgePlatform, type Token } from '@internal/bridge-shared';\n\ntype GetBridgeRouterParams = {\n fromChainId: string;\n toChainId: string;\n fromToken: Token;\n};\n\ntype BridgeTransactionStep = {\n fromChainId: string;\n toChainId: string;\n bridgePlatform: BridgePlatform;\n fromToken: Token;\n toToken: Token;\n};\n\n/**\n * Returns a list of transaction steps needed to complete a bridge from chain A to B.\n * The response may include multiple steps if the bridge requires multiple hops.\n */\nexport const planBridgeJourney = (_params: GetBridgeRouterParams): BridgeTransactionStep[] => {\n // Implement smart logic for determining how to get the token from chain A to B\n throw new NotImplementedError();\n};\n","import type { Address } from 'viem';\nimport { NotImplementedError } from '../errors';\n\n/**\n * Checks for any currently pending bridge transactions. Useful for dApps that want\n * to display the current tx's status after a page refresh.\n */\nexport const checkForPendingBridgeJourney = async ({\n address: _address,\n chainIds: _chainIds,\n}: {\n address: Address;\n chainIds: string[];\n}) => {\n /**\n * 1. If wallet is Core, request current bridge journey. Otherwise, check glacier to see if the provided wallet has bridge tx in the past 100 transactions on the provided chains.\n * 3. Returns an array of txIds for all pending transactions\n */\n throw new NotImplementedError();\n};\n","import { executeBridgeJourneyStep } from './handlers/execute-bridge-journey-step';\nimport { planBridgeJourney } from './handlers/plan-bridge-journey';\n\nimport type { Environment, MaybePromise, NativeToken } from '@internal/bridge-shared';\nimport { checkForPendingBridgeJourney } from './handlers/check-for-pending-bridge-journey';\n\nexport type BridgeServiceConfig = {\n environment: `${Environment}`;\n getChainNativeAsset: ({ evmChainId }: { evmChainId: string }) => MaybePromise<NativeToken>;\n getChainErc20Asset: ({ evmChainId, address }: { evmChainId: string; address: string }) => MaybePromise<NativeToken>;\n};\n\nexport const createUnifiedBridgeService = (_options: BridgeServiceConfig) => {\n return {\n planBridgeJourney,\n executeBridgeJourneyStep,\n checkForPendingBridgeJourney,\n };\n};\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@avalabs/bridge-unified",
|
|
3
|
+
"version": "0.0.0-hello-world-20230824162317",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"aptos": "1.17.0",
|
|
8
|
+
"lodash-es": "4.17.21",
|
|
9
|
+
"viem": "1.6.0"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"tsup": "7.2.0",
|
|
13
|
+
"type-fest": "4.2.0",
|
|
14
|
+
"eslint-config-custom": "0.0.0-hello-world-20230824162317",
|
|
15
|
+
"@internal/bridge-shared": "0.0.0-hello-world-20230824162317",
|
|
16
|
+
"@internal/tsup-config": "0.0.0-hello-world-20230824162317"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup",
|
|
20
|
+
"lint": "eslint \"src/**/*.ts\""
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export enum ErrorCode {
|
|
2
|
+
NOT_IMPLEMENTED = 5001,
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
class BridgeError extends Error {
|
|
6
|
+
constructor(
|
|
7
|
+
message: string,
|
|
8
|
+
public code: ErrorCode,
|
|
9
|
+
) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.code = code;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class NotImplementedError extends BridgeError {
|
|
16
|
+
constructor(message = 'Not implemented') {
|
|
17
|
+
super(message, ErrorCode.NOT_IMPLEMENTED);
|
|
18
|
+
this.name = 'NotImplementedError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Address } from 'viem';
|
|
2
|
+
import { NotImplementedError } from '../errors';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Checks for any currently pending bridge transactions. Useful for dApps that want
|
|
6
|
+
* to display the current tx's status after a page refresh.
|
|
7
|
+
*/
|
|
8
|
+
export const checkForPendingBridgeJourney = async ({
|
|
9
|
+
address: _address,
|
|
10
|
+
chainIds: _chainIds,
|
|
11
|
+
}: {
|
|
12
|
+
address: Address;
|
|
13
|
+
chainIds: string[];
|
|
14
|
+
}) => {
|
|
15
|
+
/**
|
|
16
|
+
* 1. If wallet is Core, request current bridge journey. Otherwise, check glacier to see if the provided wallet has bridge tx in the past 100 transactions on the provided chains.
|
|
17
|
+
* 3. Returns an array of txIds for all pending transactions
|
|
18
|
+
*/
|
|
19
|
+
throw new NotImplementedError();
|
|
20
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { NotImplementedError } from '../errors';
|
|
2
|
+
|
|
3
|
+
type ExecuteBridgeJourneyStepParams = {
|
|
4
|
+
stepIndex: number;
|
|
5
|
+
journey: unknown;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const executeBridgeJourneyStep = async (_params: ExecuteBridgeJourneyStepParams) => {
|
|
9
|
+
/**
|
|
10
|
+
* 1. Validate the journey
|
|
11
|
+
* 3. Forward request along to the right bridge platform's package.
|
|
12
|
+
* 4. Return an observable that emits events when:
|
|
13
|
+
* - User signs the transaction (returns the fromChain txId)
|
|
14
|
+
* - Every block confirmation on fromChain
|
|
15
|
+
* - fromChain tx completed, starting the toChain tx (returns the toChainTxId)
|
|
16
|
+
* - Every block confirmation on toChain
|
|
17
|
+
* - toChain tx completed
|
|
18
|
+
*/
|
|
19
|
+
throw new NotImplementedError();
|
|
20
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { NotImplementedError } from '../errors';
|
|
2
|
+
import { BridgePlatform, type Token } from '@internal/bridge-shared';
|
|
3
|
+
|
|
4
|
+
type GetBridgeRouterParams = {
|
|
5
|
+
fromChainId: string;
|
|
6
|
+
toChainId: string;
|
|
7
|
+
fromToken: Token;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type BridgeTransactionStep = {
|
|
11
|
+
fromChainId: string;
|
|
12
|
+
toChainId: string;
|
|
13
|
+
bridgePlatform: BridgePlatform;
|
|
14
|
+
fromToken: Token;
|
|
15
|
+
toToken: Token;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Returns a list of transaction steps needed to complete a bridge from chain A to B.
|
|
20
|
+
* The response may include multiple steps if the bridge requires multiple hops.
|
|
21
|
+
*/
|
|
22
|
+
export const planBridgeJourney = (_params: GetBridgeRouterParams): BridgeTransactionStep[] => {
|
|
23
|
+
// Implement smart logic for determining how to get the token from chain A to B
|
|
24
|
+
throw new NotImplementedError();
|
|
25
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { executeBridgeJourneyStep } from './handlers/execute-bridge-journey-step';
|
|
2
|
+
import { planBridgeJourney } from './handlers/plan-bridge-journey';
|
|
3
|
+
|
|
4
|
+
import type { Environment, MaybePromise, NativeToken } from '@internal/bridge-shared';
|
|
5
|
+
import { checkForPendingBridgeJourney } from './handlers/check-for-pending-bridge-journey';
|
|
6
|
+
|
|
7
|
+
export type BridgeServiceConfig = {
|
|
8
|
+
environment: `${Environment}`;
|
|
9
|
+
getChainNativeAsset: ({ evmChainId }: { evmChainId: string }) => MaybePromise<NativeToken>;
|
|
10
|
+
getChainErc20Asset: ({ evmChainId, address }: { evmChainId: string; address: string }) => MaybePromise<NativeToken>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const createUnifiedBridgeService = (_options: BridgeServiceConfig) => {
|
|
14
|
+
return {
|
|
15
|
+
planBridgeJourney,
|
|
16
|
+
executeBridgeJourneyStep,
|
|
17
|
+
checkForPendingBridgeJourney,
|
|
18
|
+
};
|
|
19
|
+
};
|
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED