orbiter-bridge-sdks 0.1.15
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 +347 -0
- package/dist/index.d.mts +335 -0
- package/dist/index.d.ts +335 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +35 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
# Orbiter SDK Document
|
|
2
|
+
|
|
3
|
+
## 🌕 Overview
|
|
4
|
+
|
|
5
|
+
- The Orbiter SDK package provides a simplest, out-of-the-box approach to access the Orbiter API to find and execute
|
|
6
|
+
the best on-chain and cross-chain swapping and bridging.
|
|
7
|
+
|
|
8
|
+
- For more information about API, please see page:
|
|
9
|
+
[Orbiter REST API](https://docs.orbiter.finance/developer/rest-api/overview).
|
|
10
|
+
|
|
11
|
+
## 📦 Installation
|
|
12
|
+
|
|
13
|
+
You can use following ways to get the latest version of Orbiter SDK.
|
|
14
|
+
|
|
15
|
+
- npm
|
|
16
|
+
|
|
17
|
+
```shell
|
|
18
|
+
npm install @orbiter-finance/bridge-sdk
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- yarn
|
|
22
|
+
|
|
23
|
+
```shell
|
|
24
|
+
yarn add @orbiter-finance/bridge-sdk
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
- pnpm
|
|
28
|
+
|
|
29
|
+
```shell
|
|
30
|
+
pnpm add @orbiter-finance/bridge-sdk
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Feel free to [report](https://discord.com/invite/FbztTBvnBT) if you encounter any problems.
|
|
34
|
+
|
|
35
|
+
## 👾 Quick Start
|
|
36
|
+
|
|
37
|
+
- ### Set up the SDK
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
import { OrbiterClient, ENDPOINT } from "@orbiter-finance/bridge-sdk";
|
|
41
|
+
const config: ConfigOptions = {
|
|
42
|
+
apiEndpoint: ENDPOINT.TESTNET
|
|
43
|
+
defaultRouterType: RouterType.CONTRACT //Optional, which give priority to the transfer type
|
|
44
|
+
}
|
|
45
|
+
let orbiter: OrbiterClient = await OrbiterClient.create(config);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
- ### Check Available TradePair
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
// get all available chains
|
|
52
|
+
const chains: Chain[] = orbiter.getAllChains()
|
|
53
|
+
|
|
54
|
+
// choose a chain from list to get availabletokens
|
|
55
|
+
const tokens: Token[] = orbiter.getAvailableTokens("chainId")
|
|
56
|
+
|
|
57
|
+
// choose a chain and a token symbol to get available trade pairs
|
|
58
|
+
const tradePairs: TradePair[] = orbiter.getAvailableTradePairs("chainId", "symbol")
|
|
59
|
+
|
|
60
|
+
// or directly get all available trade pairs
|
|
61
|
+
const tradePairs: TradePair[] = orbiter.getAllTradePairs()
|
|
62
|
+
|
|
63
|
+
// in case you want show all symbols
|
|
64
|
+
const symbols = orbiter.getAllSymbols()
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
> 💡Tips:
|
|
68
|
+
>
|
|
69
|
+
> - You don't have to care about the router type you send transaction, SDK will automatically using the availlable
|
|
70
|
+
> type, unless you know what that way means.
|
|
71
|
+
|
|
72
|
+
- ### Create Router and Send Transaction
|
|
73
|
+
|
|
74
|
+
##### From EVM Chains
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { Wallet, JsonRpcProvider } from "ethers"
|
|
78
|
+
|
|
79
|
+
// choose a tradePair to create router
|
|
80
|
+
const tradePair: TradePair = {
|
|
81
|
+
srcChainId: "11155111",
|
|
82
|
+
dstChainId: "421614",
|
|
83
|
+
srcTokenSymbol: "ETH",
|
|
84
|
+
dstTokenSymbol: "ETH",
|
|
85
|
+
}
|
|
86
|
+
const router = orbiter.createRouter(tradePair)
|
|
87
|
+
|
|
88
|
+
// check min and max value
|
|
89
|
+
const min = router.getMinSendAmount()
|
|
90
|
+
const max = router.getMaxSendAmount()
|
|
91
|
+
|
|
92
|
+
// simulationAmount
|
|
93
|
+
const { sendAmount, receiveAmount } = router.simulationAmount("amountBetweenMinAndMax")
|
|
94
|
+
|
|
95
|
+
// connect wallet
|
|
96
|
+
const provider = new JsonRpcProvider("https://ethereum-sepolia-rpc.publicnode.com")
|
|
97
|
+
const wallet = new Wallet("privateKey", provider)
|
|
98
|
+
// check if balance sufficient
|
|
99
|
+
const balance = (await provider.getBalance(wallet)).toString()
|
|
100
|
+
|
|
101
|
+
// if is erc20 token, need approve
|
|
102
|
+
// const approve = await router.createApprove(account.address, sendAmount);
|
|
103
|
+
// const approveResponce = await wallet.sendTransaction(approve);
|
|
104
|
+
// const approveReceipt = await approveRes.wait();
|
|
105
|
+
|
|
106
|
+
// create transaction
|
|
107
|
+
const transactionParams = router.createTransaction(wallet.address, "receiver", sendAmount)
|
|
108
|
+
// send transaction
|
|
109
|
+
const transactionResponce = await wallet.sendTransaction(transactionParams.raw as TransactionRequest)
|
|
110
|
+
const transactionReceipt = await transferResponce.wait()
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
##### From BTC Chains
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import * as bitcoin from 'bitcoinjs-lib'
|
|
117
|
+
import * as ecc from 'tiny-secp256k1';
|
|
118
|
+
import { ECPairFactory, networks } from 'ecpair';
|
|
119
|
+
|
|
120
|
+
// choose a tradePair to create router
|
|
121
|
+
const tradePair: TradePair = {
|
|
122
|
+
srcChainId: 'FRACTAL_TEST',
|
|
123
|
+
dstChainId: '11155111',
|
|
124
|
+
srcTokenSymbol: 'BTC',
|
|
125
|
+
dstTokenSymbol: 'BTC'
|
|
126
|
+
}
|
|
127
|
+
const router = orbiter.createRouter(tradePair);
|
|
128
|
+
|
|
129
|
+
// check min and max value
|
|
130
|
+
const min = router.getMinSendAmount();
|
|
131
|
+
const max = router.getMaxSendAmount();
|
|
132
|
+
|
|
133
|
+
// simulationAmount
|
|
134
|
+
const { sendAmount, receiveAmount } = router.simulationAmount('amountBetweenMinAndMax');
|
|
135
|
+
|
|
136
|
+
// creat payment
|
|
137
|
+
const network = networks.bitcoin;
|
|
138
|
+
const ECPair = ECPairFactory(ecc);
|
|
139
|
+
const keyPair = ECPair.fromWIF(btcPrivateKey, network);
|
|
140
|
+
const payment = bitcoin.payments.p2wpkh({
|
|
141
|
+
pubkey: keyPair.publicKey,
|
|
142
|
+
network,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// create transaction and add output
|
|
146
|
+
const transactionParams = await router.createTransaction(payment.address, 'receiver', sendAmount);
|
|
147
|
+
const psbt = transactionParams.raw as bitcoin.Psbt;
|
|
148
|
+
|
|
149
|
+
// get utxos from chain
|
|
150
|
+
const utxos = ...
|
|
151
|
+
|
|
152
|
+
// add inputs
|
|
153
|
+
const script = payment.output;
|
|
154
|
+
utxos.forEach((utxo: any) => {
|
|
155
|
+
const inputData = {
|
|
156
|
+
hash: utxo.txid,
|
|
157
|
+
index: utxo.vout,
|
|
158
|
+
witnessUtxo: {
|
|
159
|
+
script,
|
|
160
|
+
value: utxo.satoshi
|
|
161
|
+
},
|
|
162
|
+
}
|
|
163
|
+
psbt.addInput(inputData);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// estimate fee from oracle or explorer
|
|
167
|
+
const fee = ...
|
|
168
|
+
|
|
169
|
+
// add change !!!important!!!
|
|
170
|
+
const change = totalAmount - Number(sendAmount) - fee;
|
|
171
|
+
if (change > 0) {
|
|
172
|
+
psbt.addOutput({
|
|
173
|
+
script,
|
|
174
|
+
value: change
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// sign inputs
|
|
179
|
+
for (let i = 0; i < psbt.inputCount; i++) {
|
|
180
|
+
psbt.signInput(i, keyPair);
|
|
181
|
+
psbt.validateSignaturesOfInput(i, (
|
|
182
|
+
pubkey: Buffer,
|
|
183
|
+
msghash: Buffer,
|
|
184
|
+
signature: Buffer,
|
|
185
|
+
) => ECPair.fromPublicKey(pubkey).verify(msghash, signature));
|
|
186
|
+
}
|
|
187
|
+
psbt.finalizeAllInputs();
|
|
188
|
+
|
|
189
|
+
// broadcast
|
|
190
|
+
const broadcastResult = ...
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
##### From Tron Chains
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
import { TronWeb } from "tronweb"
|
|
198
|
+
|
|
199
|
+
// choose a tradePair to create router
|
|
200
|
+
const tradePair: TradePair = {
|
|
201
|
+
srcChainId: "3448148188",
|
|
202
|
+
dstChainId: "11155111",
|
|
203
|
+
srcTokenSymbol: "JST",
|
|
204
|
+
dstTokenSymbol: "JST",
|
|
205
|
+
}
|
|
206
|
+
const router = orbiter.createRouter(tradePair)
|
|
207
|
+
|
|
208
|
+
// check min and max value
|
|
209
|
+
const min = router.getMinSendAmount()
|
|
210
|
+
const max = router.getMaxSendAmount()
|
|
211
|
+
|
|
212
|
+
// simulationAmount
|
|
213
|
+
const { sendAmount, receiveAmount } = router.simulationAmount("amountBetweenMinAndMax")
|
|
214
|
+
|
|
215
|
+
// connect to tronweb
|
|
216
|
+
const tronWeb = new TronWeb({
|
|
217
|
+
fullHost: "https://nile.trongrid.io",
|
|
218
|
+
headers: { "TRON-PRO-API-KEY": "API key" },
|
|
219
|
+
privateKey: "privateKey",
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
// create approve
|
|
223
|
+
const approveParams = await router.createApprove(address, sendAmount)
|
|
224
|
+
// sign and send approve
|
|
225
|
+
const signedApprove = await tronWeb.trx.sign((approveParams.raw as Types.TransactionWrapper).transaction)
|
|
226
|
+
const approveRes = await tronWeb.trx.sendRawTransaction(signedApprove)
|
|
227
|
+
|
|
228
|
+
// create transaction
|
|
229
|
+
const transactionParams = await router.createTransaction(address, evmAddress, sendAmount)
|
|
230
|
+
// sign and send transaction
|
|
231
|
+
const signedTransaction = await tronWeb.trx.sign((transactionParams.raw as Types.TransactionWrapper).transaction)
|
|
232
|
+
const transferRes = await tronWeb.trx.sendRawTransaction(signedTransaction)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
##### From Starknet Chains
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
import { Account, Provider, constants } from "starknet"
|
|
239
|
+
|
|
240
|
+
// choose a tradePair to create router
|
|
241
|
+
const tradePair: TradePair = {
|
|
242
|
+
srcChainId: "SN_SEPOLIA",
|
|
243
|
+
dstChainId: "11155111",
|
|
244
|
+
srcTokenSymbol: "ETH",
|
|
245
|
+
dstTokenSymbol: "ETH",
|
|
246
|
+
}
|
|
247
|
+
const router = orbiter.createRouter(tradePair)
|
|
248
|
+
|
|
249
|
+
// check min and max value
|
|
250
|
+
const min = router.getMinSendAmount()
|
|
251
|
+
const max = router.getMaxSendAmount()
|
|
252
|
+
|
|
253
|
+
// simulationAmount
|
|
254
|
+
const { sendAmount, receiveAmount } = router.simulationAmount("amountBetweenMinAndMax")
|
|
255
|
+
|
|
256
|
+
// connect account
|
|
257
|
+
const provider = new Provider({ nodeUrl: constants.NetworkName.SN_SEPOLIA })
|
|
258
|
+
const account = new Account(provider, starknetAddress, privateKey)
|
|
259
|
+
|
|
260
|
+
// create approve
|
|
261
|
+
const approveParams = await router.createApprove(account.address, sendAmount)
|
|
262
|
+
|
|
263
|
+
// create transaction
|
|
264
|
+
const transactionParams = router.createTransaction(wallet.address, "receiver", sendAmount)
|
|
265
|
+
|
|
266
|
+
// send approve and transaction
|
|
267
|
+
const transactionResponce = await account.execute([approveParams.raw as Call, transactionParams.raw as Call])
|
|
268
|
+
const transactionReceipt = await provider.waitForTransaction(transactionResponce.transaction_hash)
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
##### From Solana Chains
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
import bs58 from "bs58"
|
|
275
|
+
import { Connection, Keypair, TransactionMessage, VersionedTransaction, LAMPORTS_PER_SOL } from "@solana/web3.js"
|
|
276
|
+
|
|
277
|
+
// choose a tradePair to create router
|
|
278
|
+
const tradePair: TradePair = {
|
|
279
|
+
srcChainId: "SOLANA_DEV",
|
|
280
|
+
dstChainId: "11155111",
|
|
281
|
+
srcTokenSymbol: "USDC",
|
|
282
|
+
dstTokenSymbol: "USDC",
|
|
283
|
+
}
|
|
284
|
+
const router = orbiter.createRouter(tradePair)
|
|
285
|
+
|
|
286
|
+
// check min and max value
|
|
287
|
+
const min = router.getMinSendAmount()
|
|
288
|
+
const max = router.getMaxSendAmount()
|
|
289
|
+
|
|
290
|
+
// simulationAmount
|
|
291
|
+
const { sendAmount, receiveAmount } = router.simulationAmount("amountBetweenMinAndMax")
|
|
292
|
+
|
|
293
|
+
// connect wallet
|
|
294
|
+
const connection = new Connection("solana-endpoint", "confirmed")
|
|
295
|
+
const sender = Keypair.fromSecretKey(bs58.decode("privateKey"))
|
|
296
|
+
|
|
297
|
+
// create transaction
|
|
298
|
+
const transactionParams = await router.createTransaction(sender.publicKey.toString(), "receiver", sendAmount)
|
|
299
|
+
|
|
300
|
+
// process transaction
|
|
301
|
+
const transaction = transactionParams.raw as Transaction
|
|
302
|
+
const blockhash = await connection.getLatestBlockhash()
|
|
303
|
+
transaction.recentBlockhash = blockhash.blockhash
|
|
304
|
+
transaction.feePayer = sender.publicKey
|
|
305
|
+
const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
|
|
306
|
+
units: 1000000,
|
|
307
|
+
})
|
|
308
|
+
const addPriorityFee = ComputeBudgetProgram.setComputeUnitPrice({
|
|
309
|
+
microLamports: 100,
|
|
310
|
+
})
|
|
311
|
+
transaction.add(modifyComputeUnits).add(addPriorityFee)
|
|
312
|
+
transaction.sign(sender)
|
|
313
|
+
|
|
314
|
+
const signature = await connection.sendRawTransaction(transaction.serialize())
|
|
315
|
+
|
|
316
|
+
//check transaction status
|
|
317
|
+
const status = await connection.getSignatureStatus(signature, {
|
|
318
|
+
searchTransactionHistory: false,
|
|
319
|
+
})
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
> 💡Tips:
|
|
323
|
+
>
|
|
324
|
+
> - The function [createTransfer] will return deferent type of transfer structure which depends on source chain
|
|
325
|
+
> type, for EVM it will be TransactionRequest, for BTC will be a PSBT for Starknet will be Call, etc. For more
|
|
326
|
+
> information please see their official document.
|
|
327
|
+
|
|
328
|
+
- ### Check Bridge Status
|
|
329
|
+
|
|
330
|
+
```typescript
|
|
331
|
+
const transactionStatus = await orbiter.checkTransactionStatus(hash)
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
- ### Check User Opoints and Transaction History
|
|
335
|
+
|
|
336
|
+
```typescript
|
|
337
|
+
// get user Opoints
|
|
338
|
+
const opoints = await orbiter.getUserOpoint(wallet.address)
|
|
339
|
+
|
|
340
|
+
// get user transaction history
|
|
341
|
+
const history = await orbiter.getTransactionHistory(wallet.address, TxType.BRIDGE, 0)
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
> 💡Tips:
|
|
345
|
+
>
|
|
346
|
+
> - For structure of result on these two function, please check
|
|
347
|
+
> [Orbiter REST API](https://docs.orbiter.finance/developer/rest-api/overview).
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { VMType } from '@orbiter-finance/vm-core';
|
|
2
|
+
|
|
3
|
+
interface APIResponse<T> {
|
|
4
|
+
status: string;
|
|
5
|
+
message: string;
|
|
6
|
+
result: T;
|
|
7
|
+
}
|
|
8
|
+
interface APIPageResponse<T> {
|
|
9
|
+
count: number;
|
|
10
|
+
rows: T[];
|
|
11
|
+
offset?: number;
|
|
12
|
+
limit?: number;
|
|
13
|
+
}
|
|
14
|
+
interface ChainConfig {
|
|
15
|
+
chainId: string;
|
|
16
|
+
networkId: string;
|
|
17
|
+
internalId: number;
|
|
18
|
+
name: string;
|
|
19
|
+
nativeCurrency: Token;
|
|
20
|
+
tokens: Token[];
|
|
21
|
+
contracts: Contract[];
|
|
22
|
+
vm: VMType;
|
|
23
|
+
}
|
|
24
|
+
interface Token {
|
|
25
|
+
name: string;
|
|
26
|
+
symbol: string;
|
|
27
|
+
decimals: number;
|
|
28
|
+
coinKey: string;
|
|
29
|
+
address: string;
|
|
30
|
+
isNative?: boolean;
|
|
31
|
+
}
|
|
32
|
+
interface Contract {
|
|
33
|
+
name: string;
|
|
34
|
+
address: string;
|
|
35
|
+
}
|
|
36
|
+
interface RouterConfig {
|
|
37
|
+
line: string;
|
|
38
|
+
endpoint: string;
|
|
39
|
+
endpointContract?: string;
|
|
40
|
+
srcChain: string;
|
|
41
|
+
tgtChain: string;
|
|
42
|
+
srcToken: string;
|
|
43
|
+
tgtToken: string;
|
|
44
|
+
maxAmt: string;
|
|
45
|
+
minAmt: string;
|
|
46
|
+
tradeFee: string;
|
|
47
|
+
withholdingFee: string;
|
|
48
|
+
vc: string;
|
|
49
|
+
state: RouterState;
|
|
50
|
+
type: string;
|
|
51
|
+
opool?: {
|
|
52
|
+
[key: string]: string;
|
|
53
|
+
};
|
|
54
|
+
compRatio: number;
|
|
55
|
+
spentTime: number;
|
|
56
|
+
tieredFee: TieredFee[];
|
|
57
|
+
point?: number | undefined;
|
|
58
|
+
}
|
|
59
|
+
interface TieredFee {
|
|
60
|
+
range: [number, number];
|
|
61
|
+
tradeFee: number;
|
|
62
|
+
withholdingFee: number;
|
|
63
|
+
}
|
|
64
|
+
declare enum RouterState {
|
|
65
|
+
AVAILABLE = "available",
|
|
66
|
+
DISABLED = "disabled"
|
|
67
|
+
}
|
|
68
|
+
interface Transaction {
|
|
69
|
+
sourceId: string;
|
|
70
|
+
targetId: string;
|
|
71
|
+
sourceChain: string;
|
|
72
|
+
targetChain: string;
|
|
73
|
+
sourceAmount: string;
|
|
74
|
+
sourceMaker: string;
|
|
75
|
+
sourceAddress: string;
|
|
76
|
+
targetAddress: string;
|
|
77
|
+
sourceSymbol: string;
|
|
78
|
+
targetSymbol: string;
|
|
79
|
+
status: number;
|
|
80
|
+
sourceTime: string;
|
|
81
|
+
targetTime: string;
|
|
82
|
+
points?: string;
|
|
83
|
+
}
|
|
84
|
+
interface PointRule {
|
|
85
|
+
[chain: string]: {
|
|
86
|
+
[symbol: string]: string;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
declare enum TxType {
|
|
90
|
+
BRIDGE = "0",
|
|
91
|
+
COLLECTOR = "1",
|
|
92
|
+
SWAP = "2",
|
|
93
|
+
COMMISSION = "3",
|
|
94
|
+
SAME_CHAIN_SWAP = "4"
|
|
95
|
+
}
|
|
96
|
+
interface TxHistoryItem extends Transaction {
|
|
97
|
+
txType: TxType;
|
|
98
|
+
targetAmount?: string;
|
|
99
|
+
finalAmount?: string | null;
|
|
100
|
+
originSymbol?: string | null;
|
|
101
|
+
originToken?: string | null;
|
|
102
|
+
originAmount?: string | null;
|
|
103
|
+
finalSymbol?: string | null;
|
|
104
|
+
finalToken?: string | null;
|
|
105
|
+
sourceTokenInfo?: TokenInfo;
|
|
106
|
+
targetTokenInfo?: TokenInfo;
|
|
107
|
+
sourceToken?: string;
|
|
108
|
+
}
|
|
109
|
+
interface TokenInfo {
|
|
110
|
+
chainId: number;
|
|
111
|
+
address: string;
|
|
112
|
+
symbol: string;
|
|
113
|
+
name: string;
|
|
114
|
+
decimals: number;
|
|
115
|
+
priceUSD: string;
|
|
116
|
+
coinKey: string;
|
|
117
|
+
logoURI: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
interface ConfigOptions {
|
|
121
|
+
apiEndpoint: ENDPOINT;
|
|
122
|
+
dealerId?: string;
|
|
123
|
+
apiKey?: string;
|
|
124
|
+
channelId?: string;
|
|
125
|
+
defaultRouterType?: RouterType;
|
|
126
|
+
}
|
|
127
|
+
declare enum ENDPOINT {
|
|
128
|
+
TESTNET = "https://testnet-api.orbiter.finance/sdk",
|
|
129
|
+
MAINNET = "https://api.orbiter.finance/sdk"
|
|
130
|
+
}
|
|
131
|
+
declare enum CDNENDPOINT {
|
|
132
|
+
TESTNET = "https://testnet-cdn.orbiter.finance/config",
|
|
133
|
+
MAINNET = "https://cdn.orbiter.finance/config"
|
|
134
|
+
}
|
|
135
|
+
interface TradePair {
|
|
136
|
+
srcChainId: string;
|
|
137
|
+
dstChainId: string;
|
|
138
|
+
srcTokenSymbol: string;
|
|
139
|
+
dstTokenSymbol: string;
|
|
140
|
+
routerType?: RouterType;
|
|
141
|
+
}
|
|
142
|
+
declare enum RouterType {
|
|
143
|
+
EOA = "EOA",
|
|
144
|
+
CONTRACT = "CONTRACT"
|
|
145
|
+
}
|
|
146
|
+
interface Chain {
|
|
147
|
+
id: string;
|
|
148
|
+
name: string;
|
|
149
|
+
}
|
|
150
|
+
interface TransactionParams {
|
|
151
|
+
routerType: RouterType;
|
|
152
|
+
srcAddress: string;
|
|
153
|
+
dstAddress: string;
|
|
154
|
+
value: string;
|
|
155
|
+
amount: string;
|
|
156
|
+
raw: unknown;
|
|
157
|
+
simulationAmountPlusWithHoldingFee?: SimulationAmountPlusWithHoldingFeeType;
|
|
158
|
+
}
|
|
159
|
+
interface SimulationAmountPlusWithHoldingFeeType {
|
|
160
|
+
sendAmount: {
|
|
161
|
+
amount: string;
|
|
162
|
+
isNativeCurrency: boolean;
|
|
163
|
+
token?: Token;
|
|
164
|
+
};
|
|
165
|
+
withholdingFee: {
|
|
166
|
+
amount: string;
|
|
167
|
+
isNativeCurrency: boolean;
|
|
168
|
+
token?: Token;
|
|
169
|
+
};
|
|
170
|
+
isOPool: boolean;
|
|
171
|
+
type: string;
|
|
172
|
+
opool: any;
|
|
173
|
+
}
|
|
174
|
+
interface ApproveParams {
|
|
175
|
+
ownerAddress: string;
|
|
176
|
+
spenderAddress: string;
|
|
177
|
+
value: string;
|
|
178
|
+
amount: string;
|
|
179
|
+
raw: unknown;
|
|
180
|
+
}
|
|
181
|
+
interface DynamicPointParams {
|
|
182
|
+
chainId: string;
|
|
183
|
+
symbol: string;
|
|
184
|
+
withholdingFee: string;
|
|
185
|
+
tradeFee: string;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
declare class ApiService {
|
|
189
|
+
private apiEndpoint;
|
|
190
|
+
private cdnEndpoint;
|
|
191
|
+
private apiKey?;
|
|
192
|
+
private channelId?;
|
|
193
|
+
constructor(apiEndpoint: ENDPOINT, apiKey?: string, channelId?: string);
|
|
194
|
+
private fetchAPIGet;
|
|
195
|
+
private fetchCDNGet;
|
|
196
|
+
getChainList(): Promise<ChainConfig[]>;
|
|
197
|
+
getTokenList(): Promise<Record<string, Token[]>>;
|
|
198
|
+
getRouterList(dealerId?: string): Promise<RouterConfig[]>;
|
|
199
|
+
getBasePointRules(): Promise<PointRule>;
|
|
200
|
+
getSimulatedReceiveAmount(line: string, value: string, nonce?: string, dealer?: string, brokerageTradeFeeRate?: number): Promise<{
|
|
201
|
+
receiveAmount: string;
|
|
202
|
+
router: RouterConfig;
|
|
203
|
+
}>;
|
|
204
|
+
getTransactionHistory(address: string, txType: TxType, offset?: number): Promise<APIPageResponse<TxHistoryItem>>;
|
|
205
|
+
getTransactionStatus(hash: string, chainId?: string, address?: string, value?: string): Promise<any>;
|
|
206
|
+
getUserOpoint(address: string): Promise<any>;
|
|
207
|
+
getDynamicPoint(param: DynamicPointParams): Promise<string>;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
declare class ConfigService {
|
|
211
|
+
private readonly _apiService;
|
|
212
|
+
private readonly _config;
|
|
213
|
+
private _chainConfigs?;
|
|
214
|
+
private _routerConfigs?;
|
|
215
|
+
private _basePointRules?;
|
|
216
|
+
constructor(_apiService: ApiService, _config: ConfigOptions);
|
|
217
|
+
initConfig(): Promise<void>;
|
|
218
|
+
initChainConfigs(): Promise<void>;
|
|
219
|
+
initRouterConfigs(): Promise<void>;
|
|
220
|
+
initBasePointRules(): Promise<void>;
|
|
221
|
+
getRouterConfigs(): RouterConfig[];
|
|
222
|
+
getRouterConfig(tradePair: TradePair): RouterConfig | undefined;
|
|
223
|
+
getChainConfigs(): ChainConfig[];
|
|
224
|
+
getChainConfigByName(chainName: string): ChainConfig | undefined;
|
|
225
|
+
getChainConfigById(chainId: string): ChainConfig | undefined;
|
|
226
|
+
getBasePointRule(chainId: string, symbol: string): string;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
declare class VMService {
|
|
230
|
+
private readonly _configService;
|
|
231
|
+
constructor(configService: ConfigService);
|
|
232
|
+
isValidTransferType(routerType: RouterType): boolean;
|
|
233
|
+
getAmountWithVc(amount: string, token: Token, vc: string): string;
|
|
234
|
+
createTransaction(srcAddress: string, srcToken: Token, dstAddress: string, dstToken: Token, value: string, vc: string, routerType: RouterType, makerAddress: string, chainId: string, contractAddress?: string, channelId?: string, simulationAmountPlusWithHoldingFee?: SimulationAmountPlusWithHoldingFeeType, ext?: any): Promise<TransactionParams>;
|
|
235
|
+
createApprove(ownerAddress: string, spenderAddress: string, approveToken: Token, chainId: string, value: string): Promise<ApproveParams>;
|
|
236
|
+
createAllowance(ownerAddress: string, spenderAddress: string, approveToken: Token, chainId: string): Promise<unknown>;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
declare class Router {
|
|
240
|
+
readonly srcChainConfig: ChainConfig;
|
|
241
|
+
readonly srcToken: Token;
|
|
242
|
+
readonly dstChainConfig: ChainConfig;
|
|
243
|
+
readonly dstToken: Token;
|
|
244
|
+
readonly basePoint: string;
|
|
245
|
+
private readonly _VMService;
|
|
246
|
+
readonly routerConfig: RouterConfig;
|
|
247
|
+
readonly routerTypes: RouterType[];
|
|
248
|
+
private readonly _channelId?;
|
|
249
|
+
constructor(srcChainConfig: ChainConfig, srcToken: Token, dstChainConfig: ChainConfig, dstToken: Token, basePoint: string, _VMService: VMService, routerConfig: RouterConfig, routerTypes: RouterType[], _channelId?: string | undefined);
|
|
250
|
+
get routerId(): string;
|
|
251
|
+
get vc(): string;
|
|
252
|
+
get withholdingFee(): string;
|
|
253
|
+
get tradeFee(): string;
|
|
254
|
+
get makerAddress(): string;
|
|
255
|
+
get contractAddress(): string | undefined;
|
|
256
|
+
get spentTime(): number;
|
|
257
|
+
createTransaction(srcAddress: string, dstAddress: string, amount: string, ext?: any): Promise<TransactionParams>;
|
|
258
|
+
createApprove(ownerAddress: string, amount: string, token?: Token): Promise<ApproveParams>;
|
|
259
|
+
createAllowance(ownerAddress: string, token?: Token): Promise<unknown>;
|
|
260
|
+
getMinSendAmountMinusWithHoldingFee(): string;
|
|
261
|
+
getMinSendAmount(): string;
|
|
262
|
+
getMaxSendAmount(): string;
|
|
263
|
+
getIsOPool(): boolean;
|
|
264
|
+
equalFeeTokenBridgeToken(): boolean;
|
|
265
|
+
simulationAmountPlusWithHoldingFee(amount: string): {
|
|
266
|
+
sendAmount: {
|
|
267
|
+
amount: string;
|
|
268
|
+
token: Token | undefined;
|
|
269
|
+
isNativeCurrency: boolean;
|
|
270
|
+
};
|
|
271
|
+
withholdingFee: {
|
|
272
|
+
amount: string;
|
|
273
|
+
token: Token | undefined;
|
|
274
|
+
isNativeCurrency: boolean;
|
|
275
|
+
};
|
|
276
|
+
tradeFeeRate: string;
|
|
277
|
+
type: string;
|
|
278
|
+
isOPool: boolean;
|
|
279
|
+
receiveAmount: string;
|
|
280
|
+
opool: {
|
|
281
|
+
[key: string]: string;
|
|
282
|
+
} | undefined;
|
|
283
|
+
};
|
|
284
|
+
simulationAmount(amount: string): {
|
|
285
|
+
sendAmount: string;
|
|
286
|
+
receiveAmount: string;
|
|
287
|
+
};
|
|
288
|
+
private _getResponseIntent;
|
|
289
|
+
private _getTargetAmountSafeLengthByToken;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
declare class OrbiterClient {
|
|
293
|
+
private readonly _config;
|
|
294
|
+
private readonly _apiService;
|
|
295
|
+
private readonly _configService;
|
|
296
|
+
private readonly _VMServiceFactory;
|
|
297
|
+
private readonly _defaultRouterType;
|
|
298
|
+
constructor(config: ConfigOptions);
|
|
299
|
+
init(): Promise<void>;
|
|
300
|
+
static create(config: ConfigOptions): Promise<OrbiterClient>;
|
|
301
|
+
createRouter(tradePair: TradePair): Router;
|
|
302
|
+
private checkTradePairType;
|
|
303
|
+
getAllChains(): Chain[];
|
|
304
|
+
getAllSymbols(): string[];
|
|
305
|
+
getChainConfig(chainId: string): ChainConfig | undefined;
|
|
306
|
+
getAvailableTokens(chainId: string): Token[];
|
|
307
|
+
getAllTradePairs(): TradePair[];
|
|
308
|
+
getAvailableTradePairs(srcChainId?: string, srcTokenSymbol?: string): TradePair[];
|
|
309
|
+
getTransactionHistory(address: string, txType: TxType, offset?: number): Promise<APIPageResponse<TxHistoryItem>>;
|
|
310
|
+
getTransactionStatus(hash: string, chainId?: string, address?: string, value?: string): Promise<{
|
|
311
|
+
chainId: string;
|
|
312
|
+
hash: string;
|
|
313
|
+
sender: string;
|
|
314
|
+
receiver: string;
|
|
315
|
+
amount: string;
|
|
316
|
+
symbol: string;
|
|
317
|
+
timestamp: string;
|
|
318
|
+
status: number;
|
|
319
|
+
opStatus: number;
|
|
320
|
+
targetId: string;
|
|
321
|
+
targetAmount: string;
|
|
322
|
+
targetSymbol: string;
|
|
323
|
+
targetChain: string;
|
|
324
|
+
}>;
|
|
325
|
+
getUserOpoint(address: string): Promise<{
|
|
326
|
+
address: string;
|
|
327
|
+
summary: {
|
|
328
|
+
[key: string]: number;
|
|
329
|
+
};
|
|
330
|
+
points: number;
|
|
331
|
+
}>;
|
|
332
|
+
getDynamicPoint(param: DynamicPointParams): Promise<string>;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export { type APIPageResponse, type APIResponse, ApiService, type ApproveParams, CDNENDPOINT, type Chain, type ChainConfig, type ConfigOptions, type Contract, type DynamicPointParams, ENDPOINT, OrbiterClient, type PointRule, Router, type RouterConfig, RouterState, RouterType, type SimulationAmountPlusWithHoldingFeeType, type TieredFee, type Token, type TokenInfo, type TradePair, type Transaction, type TransactionParams, type TxHistoryItem, TxType };
|