@rhea-finance/cross-chain-aggregation-dex 1.0.6 → 2.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/README.md +279 -268
- package/dist/executors/aptos.d.mts +19 -0
- package/dist/executors/aptos.d.ts +19 -0
- package/dist/executors/aptos.js +140 -0
- package/dist/executors/aptos.js.map +1 -0
- package/dist/executors/aptos.mjs +138 -0
- package/dist/executors/aptos.mjs.map +1 -0
- package/dist/executors/bitcoin.d.mts +22 -0
- package/dist/executors/bitcoin.d.ts +22 -0
- package/dist/executors/bitcoin.js +153 -0
- package/dist/executors/bitcoin.js.map +1 -0
- package/dist/executors/bitcoin.mjs +151 -0
- package/dist/executors/bitcoin.mjs.map +1 -0
- package/dist/executors/evm.d.mts +18 -0
- package/dist/executors/evm.d.ts +18 -0
- package/dist/executors/evm.js +233 -0
- package/dist/executors/evm.js.map +1 -0
- package/dist/executors/evm.mjs +231 -0
- package/dist/executors/evm.mjs.map +1 -0
- package/dist/executors/near.d.mts +18 -0
- package/dist/executors/near.d.ts +18 -0
- package/dist/executors/near.js +162 -0
- package/dist/executors/near.js.map +1 -0
- package/dist/executors/near.mjs +160 -0
- package/dist/executors/near.mjs.map +1 -0
- package/dist/executors/solana.d.mts +20 -0
- package/dist/executors/solana.d.ts +20 -0
- package/dist/executors/solana.js +151 -0
- package/dist/executors/solana.js.map +1 -0
- package/dist/executors/solana.mjs +149 -0
- package/dist/executors/solana.mjs.map +1 -0
- package/dist/executors/sui.d.mts +19 -0
- package/dist/executors/sui.d.ts +19 -0
- package/dist/executors/sui.js +154 -0
- package/dist/executors/sui.js.map +1 -0
- package/dist/executors/sui.mjs +152 -0
- package/dist/executors/sui.mjs.map +1 -0
- package/dist/executors/tron.d.mts +24 -0
- package/dist/executors/tron.d.ts +24 -0
- package/dist/executors/tron.js +161 -0
- package/dist/executors/tron.js.map +1 -0
- package/dist/executors/tron.mjs +159 -0
- package/dist/executors/tron.mjs.map +1 -0
- package/dist/executors/zcash.d.mts +19 -0
- package/dist/executors/zcash.d.ts +19 -0
- package/dist/executors/zcash.js +158 -0
- package/dist/executors/zcash.js.map +1 -0
- package/dist/executors/zcash.mjs +156 -0
- package/dist/executors/zcash.mjs.map +1 -0
- package/dist/index.d.mts +278 -250
- package/dist/index.d.ts +278 -250
- package/dist/index.js +2369 -573
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2340 -560
- package/dist/index.mjs.map +1 -1
- package/dist/registry-DRYUqs7T.d.mts +532 -0
- package/dist/registry-DRYUqs7T.d.ts +532 -0
- package/dist/shared-BdH3hWuP.d.ts +23 -0
- package/dist/shared-BqpFeosz.d.mts +23 -0
- package/package.json +51 -17
package/README.md
CHANGED
|
@@ -1,355 +1,366 @@
|
|
|
1
1
|
# @rhea-finance/cross-chain-aggregation-dex
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript SDK for the unified multi-chain Swap API. It provides raw and normalized quote, build, execution, order status, report, and history interfaces without coupling the core package to a wallet or UI framework.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Supported chain families: EVM, Solana, Aptos, NEAR, Tron, Bitcoin, Zcash, and Sui.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- 🌉 **Cross-chain Support**: Integrates with NearIntents for cross-chain swaps
|
|
9
|
-
- 🔀 **Pre-swap Handling**: Automatically handles conversion from non-bluechip tokens to bluechip tokens
|
|
10
|
-
- 📦 **Type Safety**: Complete TypeScript type definitions
|
|
11
|
-
- 🔌 **Adapter Pattern**: Abstracts dependencies through adapter interfaces for easy integration
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
7
|
+
## Install
|
|
14
8
|
|
|
15
9
|
```bash
|
|
16
|
-
npm install @rhea-finance/cross-chain-aggregation-dex
|
|
17
|
-
# or
|
|
18
10
|
pnpm add @rhea-finance/cross-chain-aggregation-dex
|
|
19
|
-
# or
|
|
20
|
-
yarn add @rhea-finance/cross-chain-aggregation-dex
|
|
21
11
|
```
|
|
22
12
|
|
|
23
|
-
## Quick
|
|
13
|
+
## Quick start
|
|
24
14
|
|
|
25
|
-
|
|
15
|
+
All token amounts are base-unit decimal strings. Slippage uses basis points (`50` means 0.5%).
|
|
26
16
|
|
|
27
|
-
|
|
17
|
+
```ts
|
|
18
|
+
import { SwapClient, type QuoteRequest } from "@rhea-finance/cross-chain-aggregation-dex";
|
|
28
19
|
|
|
29
|
-
|
|
30
|
-
import {
|
|
31
|
-
FindPathAdapter,
|
|
32
|
-
IntentsQuotationAdapter,
|
|
33
|
-
NearChainAdapter,
|
|
34
|
-
ConfigAdapter,
|
|
35
|
-
} from "@rhea-finance/cross-chain-aggregation-dex";
|
|
20
|
+
const getAccessToken = async () => sessionStorage.getItem("access-token") ?? "";
|
|
36
21
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
`https://smartrouter.rhea.finance/findPath?${new URLSearchParams({
|
|
42
|
-
amountIn: params.amountIn,
|
|
43
|
-
tokenIn: params.tokenIn,
|
|
44
|
-
tokenOut: params.tokenOut,
|
|
45
|
-
pathDeep: "3",
|
|
46
|
-
slippage: String(params.slippage),
|
|
47
|
-
})}`
|
|
48
|
-
);
|
|
49
|
-
return response.json();
|
|
50
|
-
},
|
|
51
|
-
};
|
|
22
|
+
const client = new SwapClient({
|
|
23
|
+
baseUrl: "https://api.rhea.finance",
|
|
24
|
+
getAccessToken,
|
|
25
|
+
});
|
|
52
26
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
pathDeep: "2",
|
|
63
|
-
chainId: "0",
|
|
64
|
-
routerCount: "1",
|
|
65
|
-
skipUnwrapNativeToken: "false",
|
|
66
|
-
user: params.user,
|
|
67
|
-
receiveUser: params.receiveUser,
|
|
68
|
-
})}`
|
|
69
|
-
);
|
|
70
|
-
return response.json();
|
|
27
|
+
const request: QuoteRequest = {
|
|
28
|
+
fromChain: "btc",
|
|
29
|
+
toChain: "near",
|
|
30
|
+
tokenIn: {
|
|
31
|
+
chain: "btc",
|
|
32
|
+
address: "btc",
|
|
33
|
+
symbol: "BTC",
|
|
34
|
+
decimals: 8,
|
|
35
|
+
isNative: true,
|
|
71
36
|
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
// Call your NearIntents API
|
|
78
|
-
const response = await fetch("https://your-api.com/intents/quote", {
|
|
79
|
-
method: "POST",
|
|
80
|
-
body: JSON.stringify(params),
|
|
81
|
-
});
|
|
82
|
-
return response.json();
|
|
37
|
+
tokenOut: {
|
|
38
|
+
chain: "near",
|
|
39
|
+
address: "wrap.near",
|
|
40
|
+
symbol: "wNEAR",
|
|
41
|
+
decimals: 24,
|
|
83
42
|
},
|
|
43
|
+
amountIn: "100000",
|
|
44
|
+
slippageBps: 50,
|
|
45
|
+
sender: "bc1...",
|
|
46
|
+
recipient: "alice.near",
|
|
84
47
|
};
|
|
85
48
|
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
async call({ transactions }) {
|
|
89
|
-
// Use your Near wallet or RPC to call contracts
|
|
90
|
-
// Return { status: "success", txHash: "..." }
|
|
91
|
-
},
|
|
92
|
-
async view({ contractId, methodName, args }) {
|
|
93
|
-
// Use your Near RPC to view contract state
|
|
94
|
-
},
|
|
95
|
-
};
|
|
49
|
+
const quote = await client.quote(request);
|
|
50
|
+
const build = await client.buildSwap({ quote });
|
|
96
51
|
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
getRefExchangeId: () => "v2.ref-finance.near",
|
|
100
|
-
getWrapNearContractId: () => "wrap.near",
|
|
101
|
-
getFindPathUrl: () => "https://smartrouter.ref.finance",
|
|
102
|
-
getTokenStorageDepositRead: () => "1250000000000000000000",
|
|
103
|
-
};
|
|
52
|
+
// build is safe to inspect or send to another process.
|
|
53
|
+
// Register a chain executor before calling executeSwap.
|
|
104
54
|
```
|
|
105
55
|
|
|
106
|
-
|
|
56
|
+
`buildSwap()` never opens a wallet. To execute a build, inject one or more `ChainExecutor` implementations when creating the client:
|
|
107
57
|
|
|
108
|
-
```
|
|
109
|
-
|
|
58
|
+
```ts
|
|
59
|
+
const clientWithExecutor = new SwapClient({
|
|
60
|
+
baseUrl: "https://api.rhea.finance",
|
|
61
|
+
getAccessToken,
|
|
62
|
+
executors: [bitcoinExecutor],
|
|
63
|
+
});
|
|
110
64
|
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
nearChainAdapter,
|
|
115
|
-
configAdapter,
|
|
65
|
+
const result = await clientWithExecutor.executeSwap({
|
|
66
|
+
build,
|
|
67
|
+
waitFor: "submitted",
|
|
116
68
|
});
|
|
117
69
|
```
|
|
118
70
|
|
|
119
|
-
### 3. Get Quote
|
|
120
71
|
|
|
121
|
-
```typescript
|
|
122
|
-
import { TokenInfo } from "@rhea-finance/cross-chain-aggregation-dex";
|
|
123
72
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
decimals: 18,
|
|
128
|
-
chain: "near",
|
|
129
|
-
};
|
|
73
|
+
### Executor adapters
|
|
74
|
+
|
|
75
|
+
Each executor is imported from its own subpath and accepts a wallet-neutral adapter. The application decides whether that adapter wraps a browser wallet, server signer, RPC service, or HSM.
|
|
130
76
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
77
|
+
```ts
|
|
78
|
+
import { SwapClient } from "@rhea-finance/cross-chain-aggregation-dex";
|
|
79
|
+
import {
|
|
80
|
+
createEvmExecutor,
|
|
81
|
+
type EvmWalletAdapter,
|
|
82
|
+
} from "@rhea-finance/cross-chain-aggregation-dex/executors/evm";
|
|
83
|
+
|
|
84
|
+
const evmWallet: EvmWalletAdapter = {
|
|
85
|
+
getIdentityKey: () => wallet.address,
|
|
86
|
+
signMessage: (message) => wallet.signMessage(message),
|
|
87
|
+
sendTransaction: async (tx) => {
|
|
88
|
+
const response = await wallet.sendTransaction({
|
|
89
|
+
to: tx.to,
|
|
90
|
+
data: tx.data,
|
|
91
|
+
value: tx.value,
|
|
92
|
+
gasLimit: tx.gasLimit,
|
|
93
|
+
});
|
|
94
|
+
return { txHash: response.hash, raw: response };
|
|
95
|
+
},
|
|
96
|
+
signTypedData: async (request) =>
|
|
97
|
+
wallet.signTypedData(
|
|
98
|
+
request.typedData.domain,
|
|
99
|
+
request.typedData.types,
|
|
100
|
+
request.typedData.message
|
|
101
|
+
),
|
|
102
|
+
waitForTransaction: async (txHash) => provider.waitForTransaction(txHash),
|
|
136
103
|
};
|
|
137
104
|
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
slippage: 50, // 0.5% (50 basis points)
|
|
143
|
-
swapType: "EXACT_INPUT",
|
|
105
|
+
const client = new SwapClient({
|
|
106
|
+
baseUrl: "https://api.rhea.finance",
|
|
107
|
+
getAccessToken,
|
|
108
|
+
executors: [createEvmExecutor(evmWallet)],
|
|
144
109
|
});
|
|
110
|
+
```
|
|
145
111
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
}
|
|
112
|
+
Other executor subpaths follow the same pattern:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { createSolanaExecutor } from "@rhea-finance/cross-chain-aggregation-dex/executors/solana";
|
|
116
|
+
import { createAptosExecutor } from "@rhea-finance/cross-chain-aggregation-dex/executors/aptos";
|
|
117
|
+
import { createNearExecutor } from "@rhea-finance/cross-chain-aggregation-dex/executors/near";
|
|
118
|
+
import { createTronExecutor } from "@rhea-finance/cross-chain-aggregation-dex/executors/tron";
|
|
119
|
+
import { createBitcoinExecutor } from "@rhea-finance/cross-chain-aggregation-dex/executors/bitcoin";
|
|
120
|
+
import { createZcashExecutor } from "@rhea-finance/cross-chain-aggregation-dex/executors/zcash";
|
|
121
|
+
import { createSuiExecutor } from "@rhea-finance/cross-chain-aggregation-dex/executors/sui";
|
|
153
122
|
```
|
|
154
123
|
|
|
155
|
-
|
|
124
|
+
Bitcoin requires `feeRate` in the build or a configured fallback:
|
|
156
125
|
|
|
157
|
-
```
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
recipient: "user.near",
|
|
161
|
-
depositAddress: "deposit.near", // optional
|
|
126
|
+
```ts
|
|
127
|
+
const bitcoinExecutor = createBitcoinExecutor(bitcoinWallet, {
|
|
128
|
+
defaultFeeRate: 4,
|
|
162
129
|
});
|
|
163
|
-
|
|
164
|
-
if (result.success) {
|
|
165
|
-
console.log("Transaction hash:", result.txHash);
|
|
166
|
-
} else {
|
|
167
|
-
console.error("Swap failed:", result.error);
|
|
168
|
-
}
|
|
169
130
|
```
|
|
170
131
|
|
|
171
|
-
|
|
132
|
+
Zcash adapters may return `{ requiresUserAction: true }` for legacy wallets that complete transfer confirmation in an external interface. The SDK returns `requires-user-action` without creating a fake transaction hash.
|
|
133
|
+
|
|
134
|
+
`swap({ quote })` is the convenience form of `buildSwap({ quote })` followed by `executeSwap({ build })`. It does not request another quote.
|
|
135
|
+
|
|
136
|
+
## MCA swaps
|
|
137
|
+
|
|
138
|
+
MCA deposit and withdrawal are execution modes of the unified root API. Use the same `client.quote()`, `client.buildSwap()`, `client.swap()`, `client.report()`, and `client.getHistory()` methods as a regular swap. The SDK does not create MCA accounts or query lending positions.
|
|
172
139
|
|
|
173
|
-
|
|
174
|
-
import { completeQuote } from "@rhea-finance/cross-chain-aggregation-dex";
|
|
140
|
+
### Deposit into an MCA
|
|
175
141
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
142
|
+
The destination asset address is the Burrow token id expected by the Swap API. Execution reuses the registered source-chain executor.
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
const quote = await client.quote({
|
|
146
|
+
flow: "deposit",
|
|
147
|
+
mcaAccountId: "account.near",
|
|
148
|
+
fromChain: "1",
|
|
149
|
+
toChain: "near",
|
|
150
|
+
tokenIn: ethereumUsdc,
|
|
151
|
+
tokenOut: mcaUsdc,
|
|
152
|
+
amountIn: "1000000",
|
|
153
|
+
slippageBps: 50,
|
|
154
|
+
sender: "0x...",
|
|
155
|
+
recipient: "account.near",
|
|
156
|
+
signerChain: "evm",
|
|
157
|
+
collateral: {
|
|
158
|
+
useAsCollateral: true,
|
|
182
159
|
},
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const result = await client.swap({ quote, waitFor: "completed" });
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The report includes `multi_addr`. Its `tx_type` remains `same-chain` or `cross-chain`, matching the unified Swap API.
|
|
166
|
+
|
|
167
|
+
### Withdraw directly to NEAR
|
|
168
|
+
|
|
169
|
+
Register a NEAR executor and request the NEAR path. The SDK parses `nearMcaWithdrawTx`, builds the MCA `exec` function call, and asks the injected NEAR wallet to send it. This path does not create an additional off-chain MCA message signature.
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
const quote = await client.quote({
|
|
173
|
+
flow: "withdraw",
|
|
174
|
+
mcaAccountId: "account.near",
|
|
175
|
+
fromChain: "near",
|
|
176
|
+
toChain: "near",
|
|
177
|
+
tokenIn: mcaUsdc,
|
|
178
|
+
tokenOut: nearUsdc,
|
|
179
|
+
amountIn: "1000000",
|
|
180
|
+
slippageBps: 50,
|
|
181
|
+
sender: "account.near",
|
|
182
|
+
recipient: "alice.near",
|
|
183
|
+
signerChain: "near",
|
|
184
|
+
collateral: {
|
|
185
|
+
needDecrease: false,
|
|
186
|
+
decreaseAmountBurrow: "0",
|
|
188
187
|
},
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
188
|
+
executionPreference: "near",
|
|
189
|
+
boundNearAccountId: "alice.near",
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
await client.swap({ quote, waitFor: "completed" });
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
With `executionPreference: "auto"`, NEAR direct execution is selected only when the destination chain is NEAR and `recipient` exactly matches `boundNearAccountId`.
|
|
196
|
+
|
|
197
|
+
### Withdraw through the multichain relayer
|
|
198
|
+
|
|
199
|
+
For other destination chains, expose `getIdentityKey()` and `signMessage()` on the connected wallet adapter used by its registered executor. The SDK signs the exact `messageToSign` returned by the API, then submits `mcaRelayer` through `POST /api/swap/swap`. No source-chain executor broadcasts a transaction for this path.
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
const quote = await client.quote({
|
|
203
|
+
flow: "withdraw",
|
|
204
|
+
mcaAccountId: "account.near",
|
|
205
|
+
fromChain: "near",
|
|
206
|
+
toChain: "1",
|
|
207
|
+
tokenIn: mcaUsdc,
|
|
208
|
+
tokenOut: ethereumUsdc,
|
|
209
|
+
amountIn: "1000000",
|
|
210
|
+
slippageBps: 50,
|
|
211
|
+
sender: "account.near",
|
|
212
|
+
recipient: wallet.address,
|
|
213
|
+
signerChain: "evm",
|
|
214
|
+
collateral: {
|
|
215
|
+
needDecrease: true,
|
|
216
|
+
decreaseAmountBurrow: "1000000",
|
|
217
|
+
withdrawAll: true,
|
|
194
218
|
},
|
|
195
|
-
|
|
219
|
+
executionPreference: "relayer",
|
|
220
|
+
});
|
|
196
221
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
targetChain: "bsc",
|
|
203
|
-
amountIn: "1000000000000000000",
|
|
204
|
-
slippage: 50,
|
|
205
|
-
recipient: "0x...", // Target chain address
|
|
206
|
-
refundTo: "user.near",
|
|
222
|
+
await client.swap({
|
|
223
|
+
quote,
|
|
224
|
+
waitFor: "completed",
|
|
225
|
+
beforeSign(preview) {
|
|
226
|
+
showMcaSignatureConfirmation(preview);
|
|
207
227
|
},
|
|
208
|
-
|
|
209
|
-
intentsQuotationAdapter,
|
|
210
|
-
dexRouter: router,
|
|
211
|
-
bluechipTokens,
|
|
212
|
-
configAdapter,
|
|
213
|
-
}
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
console.log("Deposit address:", completeQuoteResult.intents.depositAddress);
|
|
217
|
-
console.log("Final amount out:", completeQuoteResult.finalAmountOut);
|
|
218
|
-
|
|
219
|
-
if (completeQuoteResult.preSwap) {
|
|
220
|
-
console.log("Pre-swap required:", completeQuoteResult.preSwap.quote);
|
|
221
|
-
}
|
|
228
|
+
});
|
|
222
229
|
```
|
|
223
230
|
|
|
224
|
-
|
|
231
|
+
Supported MCA signer identity formats are EVM, Solana, Bitcoin, NEAR, Aptos, Sui, Zcash, and Tron. Wallet implementations remain application-owned:
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
import {
|
|
235
|
+
formatMcaWallet,
|
|
236
|
+
selectMcaSigner,
|
|
237
|
+
} from "@rhea-finance/cross-chain-aggregation-dex";
|
|
238
|
+
|
|
239
|
+
formatMcaWallet("evm", "0xAbC"); // { EVM: "AbC" }
|
|
225
240
|
|
|
226
|
-
|
|
241
|
+
const signer = selectMcaSigner(boundMcaWallets, connectedSignerIdentities);
|
|
242
|
+
```
|
|
227
243
|
|
|
228
|
-
|
|
244
|
+
The executor registered for the selected chain must expose `signMessage` when the relayer preview requests a message signature. The SDK never receives a private key or recovery phrase.
|
|
229
245
|
|
|
230
|
-
|
|
246
|
+
### Collateral policy
|
|
231
247
|
|
|
232
|
-
|
|
233
|
-
- `tokenIn`: Input token information
|
|
234
|
-
- `tokenOut`: Output token information
|
|
235
|
-
- `amountIn`: Input amount (string format, considering decimals)
|
|
236
|
-
- `slippage`: Slippage tolerance (prefer bps, 50 = 0.5%). Percent/decimal inputs are also accepted.
|
|
237
|
-
- `swapType`: Swap type ("EXACT_INPUT" | "EXACT_OUTPUT")
|
|
248
|
+
The SDK does not fetch a lending portfolio. Pass collateral decisions explicitly, or calculate the API fields from data already held by the application:
|
|
238
249
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
- `amountOut`: Output amount
|
|
242
|
-
- `minAmountOut`: Minimum output amount (considering slippage)
|
|
243
|
-
- `routes`: Route information
|
|
244
|
-
- `error`: Error message (if failed)
|
|
250
|
+
```ts
|
|
251
|
+
import { resolveMcaWithdrawPolicy } from "@rhea-finance/cross-chain-aggregation-dex";
|
|
245
252
|
|
|
246
|
-
|
|
253
|
+
const collateral = resolveMcaWithdrawPolicy({
|
|
254
|
+
collateralBalance: "12.5",
|
|
255
|
+
availableBalance: "1000000",
|
|
256
|
+
amountIn: "999999",
|
|
257
|
+
isMax: false,
|
|
258
|
+
});
|
|
259
|
+
```
|
|
247
260
|
|
|
248
|
-
|
|
261
|
+
`withdrawAll` becomes true for max selection, exact available balance, or a ratio of at least `0.999999`. The calculation uses decimal strings and `BigInt`, not floating-point arithmetic.
|
|
249
262
|
|
|
250
|
-
|
|
251
|
-
- `quote`: Quote result
|
|
252
|
-
- `recipient`: Recipient address
|
|
253
|
-
- `depositAddress`: Deposit address (optional, for cross-chain scenarios)
|
|
263
|
+
MCA history uses the MCA account id as the server-side history search key. The backend matches this value against `sender`, `recipient`, and `multi_addr`:
|
|
254
264
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
265
|
+
```ts
|
|
266
|
+
const history = await client.getHistory({
|
|
267
|
+
sender: "account.near",
|
|
268
|
+
});
|
|
269
|
+
```
|
|
260
270
|
|
|
261
|
-
|
|
271
|
+
The SDK preserves the server page instead of filtering `record.multi_addr` again. Address fields may be presentation-normalized by the API, so callers should not require exact equality with the MCA account id.
|
|
262
272
|
|
|
263
|
-
|
|
273
|
+
## API surfaces
|
|
264
274
|
|
|
265
|
-
|
|
266
|
-
- `sourceToken`: Source token
|
|
267
|
-
- `targetToken`: Target token
|
|
268
|
-
- `sourceChain`: Source chain
|
|
269
|
-
- `targetChain`: Target chain
|
|
270
|
-
- `amountIn`: Input amount
|
|
271
|
-
- `slippage`: Slippage tolerance
|
|
272
|
-
- `recipient`: Recipient address
|
|
273
|
-
- `refundTo`: Refund address (optional)
|
|
275
|
+
Normalized methods:
|
|
274
276
|
|
|
275
|
-
|
|
276
|
-
- `
|
|
277
|
-
- `
|
|
278
|
-
- `
|
|
279
|
-
- `
|
|
277
|
+
- `quote()`
|
|
278
|
+
- `buildSwap()`
|
|
279
|
+
- `executeSwap()` and `swap()`
|
|
280
|
+
- `getOrderStatus()` and `waitForOrder()`
|
|
281
|
+
- `report()` and `retryReport()`
|
|
282
|
+
- `getHistory()`
|
|
280
283
|
|
|
281
|
-
|
|
284
|
+
Raw methods preserve the unified API `data` shape:
|
|
282
285
|
|
|
283
|
-
|
|
286
|
+
- `quoteRaw()`
|
|
287
|
+
- `buildRaw()`
|
|
288
|
+
- `submitOrderRaw()`
|
|
289
|
+
- `getOrderStatusRaw()`
|
|
290
|
+
- `reportRaw()`
|
|
291
|
+
- `getHistoryRaw()`
|
|
284
292
|
|
|
285
|
-
Normalize token ID, remove `nep141:` prefix, convert `near` to `wrap.near`.
|
|
286
293
|
|
|
287
|
-
### `convertSlippageToBasisPoints(slippage: number): number`
|
|
288
294
|
|
|
289
|
-
|
|
295
|
+
## Execution kinds
|
|
290
296
|
|
|
291
|
-
|
|
297
|
+
Build responses are validated and represented as a discriminated union:
|
|
292
298
|
|
|
293
|
-
|
|
299
|
+
- `evm-transaction`
|
|
300
|
+
- `evm-signature`
|
|
301
|
+
- `solana-transaction`
|
|
302
|
+
- `aptos-entry-function`
|
|
303
|
+
- `near-transaction-batch`
|
|
304
|
+
- `tron-transfer`
|
|
305
|
+
- `bitcoin-transfer`
|
|
306
|
+
- `zcash-transfer`
|
|
307
|
+
- `sui-transfer`
|
|
294
308
|
|
|
295
|
-
|
|
309
|
+
The SDK core defines the executor contract and registry. Wallet-specific implementations are injected by the application, so importing the package does not access browser wallet globals.
|
|
296
310
|
|
|
297
|
-
|
|
311
|
+
## Runtime and credentials
|
|
298
312
|
|
|
299
|
-
-
|
|
300
|
-
- `
|
|
301
|
-
- `
|
|
302
|
-
-
|
|
303
|
-
- `
|
|
313
|
+
- Browsers and Node.js 18+ use the global Fetch API.
|
|
314
|
+
- Node.js 16 requires a compatible `fetch` implementation through `new SwapClient({ fetch })`.
|
|
315
|
+
- Supply credentials with `apiKey` or `getAccessToken`; when both are present, `getAccessToken` takes precedence.
|
|
316
|
+
- The package contains no fixed API credential and never manages private keys or wallet recovery phrases.
|
|
317
|
+
- Use `AbortSignal` on network, build, execute, and polling calls when cancellation is required.
|
|
304
318
|
|
|
305
|
-
```typescript
|
|
306
|
-
import { logger } from "@rhea-finance/cross-chain-aggregation-dex";
|
|
307
319
|
|
|
308
|
-
// The logger is automatically used internally
|
|
309
|
-
// You can also use it in your code if needed
|
|
310
|
-
logger.debug("Debug message");
|
|
311
|
-
logger.info("Info message");
|
|
312
|
-
logger.warn("Warning message");
|
|
313
|
-
logger.error("Error message");
|
|
314
|
-
```
|
|
315
320
|
|
|
316
|
-
##
|
|
321
|
+
## Retry and logging
|
|
317
322
|
|
|
318
|
-
|
|
323
|
+
Quote, history, and order-status requests retry network errors, timeouts, HTTP 429, and retryable 5xx responses twice by default. Build, report, order submission, and wallet execution are never retried automatically.
|
|
319
324
|
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
325
|
+
```ts
|
|
326
|
+
const client = new SwapClient({
|
|
327
|
+
baseUrl: "https://api.rhea.finance",
|
|
328
|
+
retry: {
|
|
329
|
+
maxRetries: 2,
|
|
330
|
+
baseDelayMs: 250,
|
|
331
|
+
maxDelayMs: 2_000,
|
|
332
|
+
jitter: true,
|
|
333
|
+
},
|
|
334
|
+
logger: {
|
|
335
|
+
log(entry) {
|
|
336
|
+
telemetry.emit(entry.event, entry);
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
});
|
|
330
340
|
```
|
|
331
341
|
|
|
332
|
-
|
|
342
|
+
Log entries contain only request stage, endpoint path, attempt, response status, timing, and SDK error code. They do not include credentials, query strings, request bodies, signatures, or serialized transactions.
|
|
333
343
|
|
|
334
|
-
|
|
335
|
-
# Install dependencies
|
|
336
|
-
pnpm install
|
|
344
|
+
## Amount conversion
|
|
337
345
|
|
|
338
|
-
|
|
339
|
-
pnpm build
|
|
346
|
+
`parseUnits` and `formatUnits` use string arithmetic and never pass token values through floating-point numbers:
|
|
340
347
|
|
|
341
|
-
|
|
342
|
-
|
|
348
|
+
```ts
|
|
349
|
+
import {
|
|
350
|
+
formatUnits,
|
|
351
|
+
parseUnits,
|
|
352
|
+
} from "@rhea-finance/cross-chain-aggregation-dex";
|
|
343
353
|
|
|
344
|
-
|
|
345
|
-
|
|
354
|
+
parseUnits("1.25", 6); // "1250000"
|
|
355
|
+
formatUnits("1250000", 6); // "1.25"
|
|
346
356
|
```
|
|
347
357
|
|
|
348
|
-
|
|
358
|
+
Both functions reject negative values, scientific notation, malformed input, and unsupported precision. Token decimals must be an integer between 0 and 255.
|
|
349
359
|
|
|
350
|
-
|
|
360
|
+
## History filtering
|
|
351
361
|
|
|
352
|
-
|
|
362
|
+
The service handles sender and pagination. `getHistory({ status })` filters the current returned page locally and sets `filteredLocally: true`; server totals remain unchanged.
|
|
363
|
+
|
|
364
|
+
## License
|
|
353
365
|
|
|
354
|
-
|
|
355
|
-
- [Rhea Finance](https://rhea.finance)
|
|
366
|
+
MIT
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { C as ChainRef, q as ChainExecutor } from '../registry-DRYUqs7T.mjs';
|
|
2
|
+
import { E as ExecutorErrorAdapter, T as TransactionSubmission } from '../shared-BqpFeosz.mjs';
|
|
3
|
+
|
|
4
|
+
interface AptosWalletAdapter extends ExecutorErrorAdapter {
|
|
5
|
+
getChain(): ChainRef | Promise<ChainRef>;
|
|
6
|
+
signAndSubmitTransaction(payload: {
|
|
7
|
+
function: string;
|
|
8
|
+
typeArguments: string[];
|
|
9
|
+
functionArguments: unknown[];
|
|
10
|
+
}, options: {
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
}): Promise<TransactionSubmission>;
|
|
13
|
+
waitForTransaction?(txHash: string, options: {
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
}): Promise<unknown>;
|
|
16
|
+
}
|
|
17
|
+
declare function createAptosExecutor(adapter: AptosWalletAdapter): ChainExecutor<"aptos-entry-function">;
|
|
18
|
+
|
|
19
|
+
export { type AptosWalletAdapter, createAptosExecutor };
|