@avalabs/bridge-unified 1.0.1
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 +7 -0
- package/README.md +92 -0
- package/dist/index.cjs +9 -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 +7 -0
- package/dist/index.js.map +1 -0
- package/package.json +22 -0
- package/src/bridge-service.ts +18 -0
- package/src/errors/index.ts +20 -0
- package/src/handlers/get-bridge-router.ts +25 -0
- package/src/handlers/submit-and-watch-bridge-transaction.ts +1 -0
- package/src/handlers/submit-bridge-transaction-step.ts +22 -0
- package/src/index.ts +1 -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[32m473.00 B[39m
|
|
14
|
+
[32mCJS[39m [1mdist/index.cjs.map [22m[32m3.67 KB[39m
|
|
15
|
+
[32mCJS[39m ⚡️ Build success in 464ms
|
|
16
|
+
[32mESM[39m [1mdist/index.js [22m[32m459.00 B[39m
|
|
17
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m3.67 KB[39m
|
|
18
|
+
[32mESM[39m ⚡️ Build success in 464ms
|
|
19
|
+
[34mDTS[39m Build start
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 7247ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m1.23 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m1.23 KB[39m
|
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<br/>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://subnets.avax.network/">
|
|
5
|
+
<picture>
|
|
6
|
+
<img alt="Avalanche Logo" src="https://images.ctfassets.net/gcj8jwzm6086/Gse8dqDEnJtT87RsbbEf4/1609daeb09e9db4a6617d44623028356/Avalanche_Horizontal_White.svg" width="auto" height="60">
|
|
7
|
+
</picture>
|
|
8
|
+
</a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
Parse arbitrary VM data for display in the Avalanche Subnet Explorer.
|
|
13
|
+
<p>
|
|
14
|
+
|
|
15
|
+
<br>
|
|
16
|
+
|
|
17
|
+
## Supported VMs
|
|
18
|
+
|
|
19
|
+
- MoveVM
|
|
20
|
+
|
|
21
|
+
## Getting Started
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npm install @avalabs/vm-parser
|
|
25
|
+
# or
|
|
26
|
+
yarn add @avalabs/vm-parser
|
|
27
|
+
# or
|
|
28
|
+
pnpm add @avalabs/vm-parser
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Overview
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
// 1. Import modules.
|
|
35
|
+
import { createMoveVmConfig, DataDisplayFormat } from '@avalabs/vm-parser';
|
|
36
|
+
import {
|
|
37
|
+
Card,
|
|
38
|
+
CardTitle,
|
|
39
|
+
CardContent,
|
|
40
|
+
Chip,
|
|
41
|
+
TableContainer,
|
|
42
|
+
Table,
|
|
43
|
+
TableBody,
|
|
44
|
+
TableRow,
|
|
45
|
+
TableCell,
|
|
46
|
+
} from 'some-ui-library';
|
|
47
|
+
import useSWR from 'swr'; // Or your preferred data fetching library
|
|
48
|
+
|
|
49
|
+
const MOVE_RPC_URL =
|
|
50
|
+
'https://seed-node1-rpc.movementlabs.xyz/ext/bc/2gLyawqthdiyrJktJmdnDAb1XVc6xwJXU6iJKu3Uwj21F2mXAK/rpc';
|
|
51
|
+
// 2. Set up your config
|
|
52
|
+
const moveVmConfig = createMoveVmConfig(MOVE_RPC_URL);
|
|
53
|
+
|
|
54
|
+
const TransactionDetails = ({ txId }: { txId: string }) => {
|
|
55
|
+
// 2. Get the data from the config's `getPageData` function
|
|
56
|
+
const { data } = useSWR(txId, moveVmConfig.transactionDetails.getPageData);
|
|
57
|
+
|
|
58
|
+
// 3. Display the data dynamically based on the config's displayFormat.
|
|
59
|
+
return (
|
|
60
|
+
<>
|
|
61
|
+
{moveVmConfig.displayFormat.map(({ sectionTitle, fields }) => (
|
|
62
|
+
<Card>
|
|
63
|
+
<CardTitle>{sectionTitle}</CardTitle>
|
|
64
|
+
<CardContent>
|
|
65
|
+
<TableContainer>
|
|
66
|
+
<Table>
|
|
67
|
+
<TableBody>
|
|
68
|
+
{fields.map(({ name, displayValue, displayFormat }) => (
|
|
69
|
+
<TableRow>
|
|
70
|
+
<TableCell>{field.name}</TableCell>
|
|
71
|
+
<TableCell>
|
|
72
|
+
/* Display the field differently depending on its display formatter */
|
|
73
|
+
{field.displayFormat === DataDisplayFormat.CHIP ? (
|
|
74
|
+
<Chip>{field.displayValue}</Chip>
|
|
75
|
+
) : field.displayFormat === DataDisplayFormat.DATETIME ? (
|
|
76
|
+
new Date(field.displayValue).toLocaleString()
|
|
77
|
+
) : (
|
|
78
|
+
fields.displayValue
|
|
79
|
+
)}
|
|
80
|
+
</TableCell>
|
|
81
|
+
</TableRow>
|
|
82
|
+
))}
|
|
83
|
+
</TableBody>
|
|
84
|
+
</Table>
|
|
85
|
+
</TableContainer>
|
|
86
|
+
</CardContent>
|
|
87
|
+
</Card>
|
|
88
|
+
))}
|
|
89
|
+
</>
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('viem');
|
|
4
|
+
|
|
5
|
+
var t=class extends Error{constructor(a,m){super(a);this.code=m;this.code=m;}},e=class extends t{constructor(o="Not implemented"){super(o,5001),this.name="NotImplementedError";}};var n=async r=>{throw new e};var i=r=>{throw new e};var s=()=>{};var v=r=>({getBridgeRouter:i,submitBridgeTransactionStep:n,submitAndWatchBridgeTransaction:s});
|
|
6
|
+
|
|
7
|
+
exports.createBridgeService = v;
|
|
8
|
+
//# sourceMappingURL=out.js.map
|
|
9
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/handlers/submit-bridge-transaction-step.ts","../src/errors/index.ts","../src/handlers/get-bridge-router.ts","../src/handlers/submit-and-watch-bridge-transaction.ts","../src/bridge-service.ts"],"names":["BridgeError","message","code","NotImplementedError","submitBridgeTransactionStep","_params","getBridgeRouter","submitAndWatchBridgeTransaction","createBridgeService","_options"],"mappings":"AAAA,MAA6B,OCI7B,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,EDPO,IAAMG,EAA8B,MAAOC,GAA2C,CAQ3F,MAAM,IAAIF,CACZ,EEAO,IAAMG,EAAmBD,GAA4D,CAE1F,MAAM,IAAIF,CACZ,ECxBO,IAAMI,EAAkC,IAAM,CAAC,ECW/C,IAAMC,EAAuBC,IAC3B,CACL,gBAAAH,EACA,4BAAAF,EACA,gCAAAG,CACF","sourcesContent":["import { type Address } from 'viem';\nimport type { Token } from '@internal/bridge-shared';\nimport { NotImplementedError } from '../errors';\n\ntype SubmitBridgeTransactionParams = {\n fromChainId: string;\n toChainId: string;\n fromAddress: Address;\n token: Token;\n amount: string;\n};\n\nexport const submitBridgeTransactionStep = async (_params: SubmitBridgeTransactionParams) => {\n /**\n * 1. Validate the token is supported on the fromChainId\n * 2. Validate the token is supported on the toChainId\n * 3. Figure out which bridge platform to use based on the from/to chains and the token being transferred\n * - Ex: Ethereum -> Avalanche USDC = use CCTP, but Ethereum -> Avalanche WAVAX use Avalanche bridge\n * 4. Return the transaction id\n */\n throw new NotImplementedError();\n};\n","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';\nimport type { BridgePlatform, 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 the steps required to complete a bridge transaction.\n * It could sometimes take multiple transactions to complete a bridge from chain A to B.\n */\nexport const getBridgeRouter = (_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","export const submitAndWatchBridgeTransaction = () => {};\n","import { submitBridgeTransactionStep } from './handlers/submit-bridge-transaction-step';\nimport { getBridgeRouter } from './handlers/get-bridge-router';\nimport { submitAndWatchBridgeTransaction } from './handlers/submit-and-watch-bridge-transaction';\nimport type { Environment, MaybePromise, NativeToken } from '@internal/bridge-shared';\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 createBridgeService = (_options: BridgeServiceConfig) => {\n return {\n getBridgeRouter,\n submitBridgeTransactionStep,\n submitAndWatchBridgeTransaction,\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 createBridgeService: (_options: BridgeServiceConfig) => {
|
|
15
|
+
getBridgeRouter: (_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
|
+
submitBridgeTransactionStep: (_params: {
|
|
27
|
+
fromChainId: string;
|
|
28
|
+
toChainId: string;
|
|
29
|
+
fromAddress: `0x${string}`;
|
|
30
|
+
token: _internal_bridge_shared.Token;
|
|
31
|
+
amount: string;
|
|
32
|
+
}) => Promise<never>;
|
|
33
|
+
submitAndWatchBridgeTransaction: () => void;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { BridgeServiceConfig, createBridgeService };
|
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 createBridgeService: (_options: BridgeServiceConfig) => {
|
|
15
|
+
getBridgeRouter: (_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
|
+
submitBridgeTransactionStep: (_params: {
|
|
27
|
+
fromChainId: string;
|
|
28
|
+
toChainId: string;
|
|
29
|
+
fromAddress: `0x${string}`;
|
|
30
|
+
token: _internal_bridge_shared.Token;
|
|
31
|
+
amount: string;
|
|
32
|
+
}) => Promise<never>;
|
|
33
|
+
submitAndWatchBridgeTransaction: () => void;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { BridgeServiceConfig, createBridgeService };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import 'viem';
|
|
2
|
+
|
|
3
|
+
var t=class extends Error{constructor(a,m){super(a);this.code=m;this.code=m;}},e=class extends t{constructor(o="Not implemented"){super(o,5001),this.name="NotImplementedError";}};var n=async r=>{throw new e};var i=r=>{throw new e};var s=()=>{};var v=r=>({getBridgeRouter:i,submitBridgeTransactionStep:n,submitAndWatchBridgeTransaction:s});
|
|
4
|
+
|
|
5
|
+
export { v as createBridgeService };
|
|
6
|
+
//# sourceMappingURL=out.js.map
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/handlers/submit-bridge-transaction-step.ts","../src/errors/index.ts","../src/handlers/get-bridge-router.ts","../src/handlers/submit-and-watch-bridge-transaction.ts","../src/bridge-service.ts"],"names":["BridgeError","message","code","NotImplementedError","submitBridgeTransactionStep","_params","getBridgeRouter","submitAndWatchBridgeTransaction","createBridgeService","_options"],"mappings":"AAAA,MAA6B,OCI7B,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,EDPO,IAAMG,EAA8B,MAAOC,GAA2C,CAQ3F,MAAM,IAAIF,CACZ,EEAO,IAAMG,EAAmBD,GAA4D,CAE1F,MAAM,IAAIF,CACZ,ECxBO,IAAMI,EAAkC,IAAM,CAAC,ECW/C,IAAMC,EAAuBC,IAC3B,CACL,gBAAAH,EACA,4BAAAF,EACA,gCAAAG,CACF","sourcesContent":["import { type Address } from 'viem';\nimport type { Token } from '@internal/bridge-shared';\nimport { NotImplementedError } from '../errors';\n\ntype SubmitBridgeTransactionParams = {\n fromChainId: string;\n toChainId: string;\n fromAddress: Address;\n token: Token;\n amount: string;\n};\n\nexport const submitBridgeTransactionStep = async (_params: SubmitBridgeTransactionParams) => {\n /**\n * 1. Validate the token is supported on the fromChainId\n * 2. Validate the token is supported on the toChainId\n * 3. Figure out which bridge platform to use based on the from/to chains and the token being transferred\n * - Ex: Ethereum -> Avalanche USDC = use CCTP, but Ethereum -> Avalanche WAVAX use Avalanche bridge\n * 4. Return the transaction id\n */\n throw new NotImplementedError();\n};\n","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';\nimport type { BridgePlatform, 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 the steps required to complete a bridge transaction.\n * It could sometimes take multiple transactions to complete a bridge from chain A to B.\n */\nexport const getBridgeRouter = (_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","export const submitAndWatchBridgeTransaction = () => {};\n","import { submitBridgeTransactionStep } from './handlers/submit-bridge-transaction-step';\nimport { getBridgeRouter } from './handlers/get-bridge-router';\nimport { submitAndWatchBridgeTransaction } from './handlers/submit-and-watch-bridge-transaction';\nimport type { Environment, MaybePromise, NativeToken } from '@internal/bridge-shared';\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 createBridgeService = (_options: BridgeServiceConfig) => {\n return {\n getBridgeRouter,\n submitBridgeTransactionStep,\n submitAndWatchBridgeTransaction,\n };\n};\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@avalabs/bridge-unified",
|
|
3
|
+
"version": "1.0.1",
|
|
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
|
+
"@internal/bridge-shared": "0.0.0",
|
|
15
|
+
"@internal/tsup-config": "0.0.1",
|
|
16
|
+
"eslint-config-custom": "0.0.0"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup",
|
|
20
|
+
"lint": "eslint \"src/**/*.ts\""
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { submitBridgeTransactionStep } from './handlers/submit-bridge-transaction-step';
|
|
2
|
+
import { getBridgeRouter } from './handlers/get-bridge-router';
|
|
3
|
+
import { submitAndWatchBridgeTransaction } from './handlers/submit-and-watch-bridge-transaction';
|
|
4
|
+
import type { Environment, MaybePromise, NativeToken } from '@internal/bridge-shared';
|
|
5
|
+
|
|
6
|
+
export type BridgeServiceConfig = {
|
|
7
|
+
environment: `${Environment}`;
|
|
8
|
+
getChainNativeAsset: ({ evmChainId }: { evmChainId: string }) => MaybePromise<NativeToken>;
|
|
9
|
+
getChainErc20Asset: ({ evmChainId, address }: { evmChainId: string; address: string }) => MaybePromise<NativeToken>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const createBridgeService = (_options: BridgeServiceConfig) => {
|
|
13
|
+
return {
|
|
14
|
+
getBridgeRouter,
|
|
15
|
+
submitBridgeTransactionStep,
|
|
16
|
+
submitAndWatchBridgeTransaction,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -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,25 @@
|
|
|
1
|
+
import { NotImplementedError } from '../errors';
|
|
2
|
+
import type { BridgePlatform, 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 the steps required to complete a bridge transaction.
|
|
20
|
+
* It could sometimes take multiple transactions to complete a bridge from chain A to B.
|
|
21
|
+
*/
|
|
22
|
+
export const getBridgeRouter = (_params: GetBridgeRouterParams): BridgeTransactionStep[] => {
|
|
23
|
+
// Implement smart logic for determining how to get the token from chain A to B
|
|
24
|
+
throw new NotImplementedError();
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const submitAndWatchBridgeTransaction = () => {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Address } from 'viem';
|
|
2
|
+
import type { Token } from '@internal/bridge-shared';
|
|
3
|
+
import { NotImplementedError } from '../errors';
|
|
4
|
+
|
|
5
|
+
type SubmitBridgeTransactionParams = {
|
|
6
|
+
fromChainId: string;
|
|
7
|
+
toChainId: string;
|
|
8
|
+
fromAddress: Address;
|
|
9
|
+
token: Token;
|
|
10
|
+
amount: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const submitBridgeTransactionStep = async (_params: SubmitBridgeTransactionParams) => {
|
|
14
|
+
/**
|
|
15
|
+
* 1. Validate the token is supported on the fromChainId
|
|
16
|
+
* 2. Validate the token is supported on the toChainId
|
|
17
|
+
* 3. Figure out which bridge platform to use based on the from/to chains and the token being transferred
|
|
18
|
+
* - Ex: Ethereum -> Avalanche USDC = use CCTP, but Ethereum -> Avalanche WAVAX use Avalanche bridge
|
|
19
|
+
* 4. Return the transaction id
|
|
20
|
+
*/
|
|
21
|
+
throw new NotImplementedError();
|
|
22
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './bridge-service';
|
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED