@avalabs/bridge-unified 0.0.0-license-20240801163452 → 0.0.0-tmp-lombard-sdk-integration-20251210211743
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/README.md +81 -13
- package/dist/index.cjs +39 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +283 -56
- package/dist/index.d.ts +283 -56
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/package.json +11 -2
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ The bridging ecosystem is complex. There are often multiple tools that can be us
|
|
|
16
16
|
|
|
17
17
|
These are the bridges we currently support:
|
|
18
18
|
|
|
19
|
-
- **CCTP** - preferred for
|
|
19
|
+
- **CCTP** - preferred for bridging USDC between Ethereum and Avalanche C-Chain. See the `bridges/cctp` folder.
|
|
20
20
|
|
|
21
21
|
Future bridges we plan to support:
|
|
22
22
|
|
|
@@ -40,8 +40,62 @@ Future bridges we plan to support:
|
|
|
40
40
|
import { createUnifiedBridgeService, getEnabledBridgeServices, Environment, BridgeTransfer } from '@avalabs/bridge-unified';
|
|
41
41
|
|
|
42
42
|
const environment = Environment.TEST;
|
|
43
|
+
const evmSigner: EvmSigner = {
|
|
44
|
+
sign: async ({ data, from, to, value }) => {
|
|
45
|
+
return await window.ethereum.request({
|
|
46
|
+
method: 'eth_sendTransaction,',
|
|
47
|
+
params:{
|
|
48
|
+
account: from,
|
|
49
|
+
data: data ?? undefined,
|
|
50
|
+
from,
|
|
51
|
+
to: to ?? null,
|
|
52
|
+
chain: undefined,
|
|
53
|
+
value
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const btcSigner: BtcSigner = {
|
|
60
|
+
sign: async ({ inputs, outputs }) => {
|
|
61
|
+
return await window.ethereum.request({
|
|
62
|
+
method: 'bitcoin_signTransaction',
|
|
63
|
+
params: { inputs, outputs },
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const cctpInitializer: EvmBridgeInitializer = {
|
|
69
|
+
type: BridgeType.CCTP,
|
|
70
|
+
signer: evmSigner,
|
|
71
|
+
};
|
|
72
|
+
const icttErc20Initializer: EvmBridgeInitializer = {
|
|
73
|
+
type: BridgeType.ICTT_ERC20_ERC20,
|
|
74
|
+
signer: evmSigner,
|
|
75
|
+
};
|
|
76
|
+
const avalancheEvmInitializer: EvmBridgeInitializer = {
|
|
77
|
+
type: BridgeType.AVALANCHE_EVM,
|
|
78
|
+
signer: evmSigner,
|
|
79
|
+
};
|
|
80
|
+
const avalancheBtcInitializer: AvaToBtcBridgeInitializer = {
|
|
81
|
+
type: BridgeType.AVALANCHE_AVA_BTC,
|
|
82
|
+
signer: evmSigner,
|
|
83
|
+
bitcoinFunctions: bitcoinProvider as BitcoinFunctions,
|
|
84
|
+
};
|
|
85
|
+
const bitcoinAvaInitializer: BtcToAvaBridgeInitializer = {
|
|
86
|
+
type: BridgeType.AVALANCHE_BTC_AVA,
|
|
87
|
+
signer: btcSigner,
|
|
88
|
+
bitcoinFunctions: bitcoinProvider as BitcoinFunctions,
|
|
89
|
+
};
|
|
90
|
+
|
|
43
91
|
// use all available bridges
|
|
44
|
-
const
|
|
92
|
+
const enabledBridgeInitializers: BridgeInitializer[] = [
|
|
93
|
+
cctpInitializer,
|
|
94
|
+
icttErc20Initializer,
|
|
95
|
+
avalancheEvmInitializer,
|
|
96
|
+
avalancheBtcInitializer,
|
|
97
|
+
bitcoinAvaInitializer,
|
|
98
|
+
]
|
|
45
99
|
|
|
46
100
|
// fetch all available bridge services
|
|
47
101
|
const enabledBridgeServices = await getEnabledBridgeServices(environment, disabledBridgeTypes);
|
|
@@ -69,7 +123,7 @@ const updateListener = (transfer: BridgeTransfer) => {
|
|
|
69
123
|
// start tracking the transfer's state. whenever the state changes, it will call the provided `updateListener`
|
|
70
124
|
const { cancel, result } = await unifiedService.trackTransfer({bridgeTransfer, updateListener, ...})
|
|
71
125
|
|
|
72
|
-
//
|
|
126
|
+
// immediately stops tracking and rejects the tracker's promise
|
|
73
127
|
// cancel()
|
|
74
128
|
|
|
75
129
|
// wait for the transfer to finish and get its final state
|
|
@@ -78,9 +132,9 @@ const finalizedBridgeTransfer = await result
|
|
|
78
132
|
|
|
79
133
|
## API
|
|
80
134
|
|
|
81
|
-
### getEnabledBridgeServices(environment,
|
|
135
|
+
### getEnabledBridgeServices(environment, enabledBridgeInitializers);
|
|
82
136
|
|
|
83
|
-
Type: `(environment: Environment,
|
|
137
|
+
Type: `(environment: Environment, enabledBridgeInitializers: BridgeInitializer[]) => Promise<BridgeServicesMap>`
|
|
84
138
|
|
|
85
139
|
Returns all available bridge services for a given environment (excluding disabledBridgeTypes). Any bridge service which fails to initialize will be absent from this returned value.
|
|
86
140
|
|
|
@@ -90,11 +144,11 @@ Type: `Environment`
|
|
|
90
144
|
|
|
91
145
|
Defines if the bridge service should use `testnet` or `mainnet`.
|
|
92
146
|
|
|
93
|
-
####
|
|
147
|
+
#### enabledBridgeInitializers
|
|
94
148
|
|
|
95
|
-
Type: `
|
|
149
|
+
Type: `BridgeInitializer[]`
|
|
96
150
|
|
|
97
|
-
|
|
151
|
+
Enables the integration of the provided `BridgeType`s based on each `BridgeInitializer`.
|
|
98
152
|
|
|
99
153
|
#### enabledBridgeServices
|
|
100
154
|
|
|
@@ -141,20 +195,34 @@ Type: `(params: TransferParams) => Promise<bigint>`
|
|
|
141
195
|
|
|
142
196
|
Estimates the gas cost of a specific transfer.
|
|
143
197
|
|
|
144
|
-
####
|
|
198
|
+
#### getMinimumTransferAmount
|
|
145
199
|
|
|
146
|
-
Type: `(
|
|
200
|
+
Type: `(params: FeeParams) => Promise<bigint>`
|
|
147
201
|
|
|
148
|
-
|
|
202
|
+
Calculates and returns the minimum transfer amount for a given bridge transfer.
|
|
149
203
|
|
|
150
204
|
#### transferAsset
|
|
151
205
|
|
|
152
206
|
Type: `(params: TransferParams) => Promise<BridgeTransfer>`
|
|
153
207
|
|
|
154
208
|
Starts a new bridge transfer, executing every required step in a single call.
|
|
155
|
-
Transactions signing is done by
|
|
209
|
+
Transactions signing is done by a custom `sign` callback. The custom `sign` implementation may use their own solution or the default `dispatch` callback to submit the transaction to the network.
|
|
156
210
|
Returns a `BridgeTransfer` containing all the (known) initial values such as: environment, addresses, amount, fee, transaction hash, required and actual block confirmation counts, etc.
|
|
157
211
|
|
|
212
|
+
Notes about TransferParams:
|
|
213
|
+
fromAddress: The address where the bridge amount is from.
|
|
214
|
+
|
|
215
|
+
toAddress: The address where the bridge amount is going to end up.
|
|
216
|
+
|
|
217
|
+
For example, A user has an account with AddressC and AddressBtc.
|
|
218
|
+
The user wants to bridge some funds from Ethereum to Avalanche using the same address. FromAddress and toAddress will be both AddressC.
|
|
219
|
+
|
|
220
|
+
The user wants to bridge some funds from Bitcoin to Avalanche.
|
|
221
|
+
FromAddress is AddressBtc and toAddress is AddressC.
|
|
222
|
+
|
|
223
|
+
Some bridges allows you to bridge the tokens to a different address. (CCTP and ICTT ERC20).
|
|
224
|
+
In this case, fromAddress is the address of the token is getting bridged from. And toAddress is the address which is going to receive the bridged funds.
|
|
225
|
+
|
|
158
226
|
#### trackTransfer
|
|
159
227
|
|
|
160
228
|
Type: `(params: TrackingParams) => ({cancel, result})`
|
|
@@ -165,7 +233,7 @@ Tracks the given `BridgeTransfer`'s progress and invokes the provided listener c
|
|
|
165
233
|
|
|
166
234
|
Type: `() => void`
|
|
167
235
|
|
|
168
|
-
If it's still pending, rejects the tracker's promise (`result`)
|
|
236
|
+
If it's still pending, rejects the tracker's promise (`result`) immediately and breaks its loop under the hood.
|
|
169
237
|
|
|
170
238
|
###### result
|
|
171
239
|
|