@sodax/sdk 1.3.1-beta-rc1 → 1.3.1-beta-rc2
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/dist/index.cjs +921 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +341 -7
- package/dist/index.d.ts +341 -7
- package/dist/index.mjs +909 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -5
package/dist/index.mjs
CHANGED
|
@@ -15,6 +15,8 @@ import { CosmosTxV1Beta1Tx } from '@injectivelabs/core-proto-ts';
|
|
|
15
15
|
import * as rlp from 'rlp';
|
|
16
16
|
import * as anchor from '@coral-xyz/anchor';
|
|
17
17
|
import BN from 'bn.js';
|
|
18
|
+
import * as bitcoin from 'bitcoinjs-lib';
|
|
19
|
+
import * as ecc from '@bitcoinerlab/secp256k1';
|
|
18
20
|
|
|
19
21
|
// src/shared/abis/asset-manager.abi.ts
|
|
20
22
|
var assetManagerAbi = [
|
|
@@ -6826,7 +6828,7 @@ var stakingRouterAbi = [
|
|
|
6826
6828
|
];
|
|
6827
6829
|
|
|
6828
6830
|
// ../types/dist/constants/index.js
|
|
6829
|
-
var CONFIG_VERSION =
|
|
6831
|
+
var CONFIG_VERSION = 28;
|
|
6830
6832
|
var AVALANCHE_MAINNET_CHAIN_ID = "0xa86a.avax";
|
|
6831
6833
|
var ARBITRUM_MAINNET_CHAIN_ID = "0xa4b1.arbitrum";
|
|
6832
6834
|
var BASE_MAINNET_CHAIN_ID = "0x2105.base";
|
|
@@ -6843,6 +6845,7 @@ var HYPEREVM_MAINNET_CHAIN_ID = "hyper";
|
|
|
6843
6845
|
var LIGHTLINK_MAINNET_CHAIN_ID = "lightlink";
|
|
6844
6846
|
var NEAR_MAINNET_CHAIN_ID = "near";
|
|
6845
6847
|
var ETHEREUM_MAINNET_CHAIN_ID = "ethereum";
|
|
6848
|
+
var BITCOIN_MAINNET_CHAIN_ID = "bitcoin";
|
|
6846
6849
|
var REDBELLY_MAINNET_CHAIN_ID = "redbelly";
|
|
6847
6850
|
var KAIA_MAINNET_CHAIN_ID = "0x2019.kaia";
|
|
6848
6851
|
var HUB_CHAIN_IDS = [SONIC_MAINNET_CHAIN_ID];
|
|
@@ -6863,6 +6866,7 @@ var CHAIN_IDS = [
|
|
|
6863
6866
|
LIGHTLINK_MAINNET_CHAIN_ID,
|
|
6864
6867
|
NEAR_MAINNET_CHAIN_ID,
|
|
6865
6868
|
ETHEREUM_MAINNET_CHAIN_ID,
|
|
6869
|
+
BITCOIN_MAINNET_CHAIN_ID,
|
|
6866
6870
|
REDBELLY_MAINNET_CHAIN_ID,
|
|
6867
6871
|
KAIA_MAINNET_CHAIN_ID
|
|
6868
6872
|
];
|
|
@@ -6977,6 +6981,12 @@ var baseChainInfo = {
|
|
|
6977
6981
|
type: "EVM",
|
|
6978
6982
|
chainId: 1
|
|
6979
6983
|
},
|
|
6984
|
+
[BITCOIN_MAINNET_CHAIN_ID]: {
|
|
6985
|
+
name: "Bitcoin",
|
|
6986
|
+
id: BITCOIN_MAINNET_CHAIN_ID,
|
|
6987
|
+
type: "BITCOIN",
|
|
6988
|
+
chainId: "bitcoin"
|
|
6989
|
+
},
|
|
6980
6990
|
[REDBELLY_MAINNET_CHAIN_ID]: {
|
|
6981
6991
|
name: "Redbelly",
|
|
6982
6992
|
id: REDBELLY_MAINNET_CHAIN_ID,
|
|
@@ -7007,6 +7017,7 @@ var ChainIdToIntentRelayChainId = {
|
|
|
7007
7017
|
[LIGHTLINK_MAINNET_CHAIN_ID]: 27756n,
|
|
7008
7018
|
[NEAR_MAINNET_CHAIN_ID]: 15n,
|
|
7009
7019
|
[ETHEREUM_MAINNET_CHAIN_ID]: 2n,
|
|
7020
|
+
[BITCOIN_MAINNET_CHAIN_ID]: 627463n,
|
|
7010
7021
|
[REDBELLY_MAINNET_CHAIN_ID]: 726564n,
|
|
7011
7022
|
[KAIA_MAINNET_CHAIN_ID]: 27489n
|
|
7012
7023
|
};
|
|
@@ -7919,6 +7930,42 @@ var spokeChainConfig = {
|
|
|
7919
7930
|
rpcUrl: "https://injective-rpc.publicnode.com:443",
|
|
7920
7931
|
walletAddress: ""
|
|
7921
7932
|
},
|
|
7933
|
+
[BITCOIN_MAINNET_CHAIN_ID]: {
|
|
7934
|
+
addresses: {
|
|
7935
|
+
assetManager: "bc1p4z9555xw0266vhq2x5un4zdmm9dt9zyet32fs7wa7u5ckdxusd9qsw4xfx"
|
|
7936
|
+
},
|
|
7937
|
+
chain: baseChainInfo[BITCOIN_MAINNET_CHAIN_ID],
|
|
7938
|
+
bnUSD: "no",
|
|
7939
|
+
nativeToken: "BTC",
|
|
7940
|
+
supportedTokens: {
|
|
7941
|
+
BTC: {
|
|
7942
|
+
symbol: "BTC",
|
|
7943
|
+
name: "Bitcoin",
|
|
7944
|
+
decimals: 8,
|
|
7945
|
+
address: "0:0",
|
|
7946
|
+
xChainId: BITCOIN_MAINNET_CHAIN_ID
|
|
7947
|
+
},
|
|
7948
|
+
bnUSD: {
|
|
7949
|
+
symbol: "bnUSD",
|
|
7950
|
+
name: "bnUSD",
|
|
7951
|
+
decimals: 18,
|
|
7952
|
+
address: "0:0",
|
|
7953
|
+
xChainId: BITCOIN_MAINNET_CHAIN_ID
|
|
7954
|
+
},
|
|
7955
|
+
BUSD: {
|
|
7956
|
+
symbol: "BUSD",
|
|
7957
|
+
name: "BUSDSTABLECOIN",
|
|
7958
|
+
decimals: 6,
|
|
7959
|
+
address: "897442:43",
|
|
7960
|
+
xChainId: BITCOIN_MAINNET_CHAIN_ID
|
|
7961
|
+
}
|
|
7962
|
+
},
|
|
7963
|
+
radfiApiUrl: "https://staging.api.radfi.co/api",
|
|
7964
|
+
radfiApiKey: "",
|
|
7965
|
+
radfiUmsUrl: "https://staging.ums.radfi.co/api",
|
|
7966
|
+
network: "MAINNET",
|
|
7967
|
+
rpcUrl: "https://mempool.space/api"
|
|
7968
|
+
},
|
|
7922
7969
|
[STELLAR_MAINNET_CHAIN_ID]: {
|
|
7923
7970
|
addresses: {
|
|
7924
7971
|
connection: "CDFQDDPUPAM3XPGORHDOEFRNLMKOH3N3X6XTXNLSXJQXIU3RVCM3OPEP",
|
|
@@ -9415,6 +9462,22 @@ var hubAssets = {
|
|
|
9415
9462
|
name: "RedBelly POL",
|
|
9416
9463
|
vault: SodaTokens.sodaPOL.address
|
|
9417
9464
|
}
|
|
9465
|
+
},
|
|
9466
|
+
[BITCOIN_MAINNET_CHAIN_ID]: {
|
|
9467
|
+
[spokeChainConfig[BITCOIN_MAINNET_CHAIN_ID].supportedTokens.BTC.address]: {
|
|
9468
|
+
asset: "0xeb0393893b5bf98a50073d6740738b08e575058b",
|
|
9469
|
+
decimal: 8,
|
|
9470
|
+
symbol: "BTC",
|
|
9471
|
+
name: "Bitcoin",
|
|
9472
|
+
vault: "0x7A1A5555842Ad2D0eD274d09b5c4406a95799D5d"
|
|
9473
|
+
},
|
|
9474
|
+
[spokeChainConfig[BITCOIN_MAINNET_CHAIN_ID].supportedTokens.BUSD.address]: {
|
|
9475
|
+
asset: "0xdb41c7d09406026d4582bc2fc6d6319c323fe1bb",
|
|
9476
|
+
decimal: 6,
|
|
9477
|
+
symbol: "BUSD",
|
|
9478
|
+
name: "BUSD.BUSD.BUSD",
|
|
9479
|
+
vault: "0xE801CA34E19aBCbFeA12025378D19c4FBE250131"
|
|
9480
|
+
}
|
|
9418
9481
|
}
|
|
9419
9482
|
};
|
|
9420
9483
|
var solverConfig = {
|
|
@@ -9555,6 +9618,10 @@ var swapSupportedTokens = {
|
|
|
9555
9618
|
spokeChainConfig[NEAR_MAINNET_CHAIN_ID].supportedTokens.USDC,
|
|
9556
9619
|
spokeChainConfig[NEAR_MAINNET_CHAIN_ID].supportedTokens.USDT
|
|
9557
9620
|
],
|
|
9621
|
+
[BITCOIN_MAINNET_CHAIN_ID]: [
|
|
9622
|
+
spokeChainConfig[BITCOIN_MAINNET_CHAIN_ID].supportedTokens.BTC
|
|
9623
|
+
// spokeChainConfig[BITCOIN_MAINNET_CHAIN_ID].supportedTokens.BUSD, // TODO: re-enable when trading wallet balance is ready
|
|
9624
|
+
],
|
|
9558
9625
|
[ETHEREUM_MAINNET_CHAIN_ID]: [
|
|
9559
9626
|
spokeChainConfig[ETHEREUM_MAINNET_CHAIN_ID].supportedTokens.ETH,
|
|
9560
9627
|
spokeChainConfig[ETHEREUM_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
@@ -9756,6 +9823,9 @@ var moneyMarketSupportedTokens = {
|
|
|
9756
9823
|
spokeChainConfig[KAIA_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
9757
9824
|
spokeChainConfig[KAIA_MAINNET_CHAIN_ID].supportedTokens.USDT,
|
|
9758
9825
|
spokeChainConfig[KAIA_MAINNET_CHAIN_ID].supportedTokens.SODA
|
|
9826
|
+
],
|
|
9827
|
+
[BITCOIN_MAINNET_CHAIN_ID]: [
|
|
9828
|
+
spokeChainConfig[BITCOIN_MAINNET_CHAIN_ID].supportedTokens.BTC
|
|
9759
9829
|
]
|
|
9760
9830
|
};
|
|
9761
9831
|
var moneyMarketReserveAssets = [
|
|
@@ -9780,7 +9850,7 @@ var defaultSharedConfig = {
|
|
|
9780
9850
|
};
|
|
9781
9851
|
|
|
9782
9852
|
// ../types/dist/common/index.js
|
|
9783
|
-
var ChainTypeArr = ["ICON", "EVM", "INJECTIVE", "SUI", "STELLAR", "SOLANA", "NEAR"];
|
|
9853
|
+
var ChainTypeArr = ["ICON", "EVM", "INJECTIVE", "SUI", "STELLAR", "SOLANA", "NEAR", "BITCOIN"];
|
|
9784
9854
|
|
|
9785
9855
|
// ../types/dist/injective/index.js
|
|
9786
9856
|
var InjectiveExecuteResponse = class _InjectiveExecuteResponse {
|
|
@@ -9799,6 +9869,17 @@ var InjectiveExecuteResponse = class _InjectiveExecuteResponse {
|
|
|
9799
9869
|
return response;
|
|
9800
9870
|
}
|
|
9801
9871
|
};
|
|
9872
|
+
|
|
9873
|
+
// ../types/dist/btc/index.js
|
|
9874
|
+
function detectBitcoinAddressType(address) {
|
|
9875
|
+
if (address.startsWith("bc1p") || address.startsWith("tb1p"))
|
|
9876
|
+
return "P2TR";
|
|
9877
|
+
if (address.startsWith("bc1") || address.startsWith("tb1"))
|
|
9878
|
+
return "P2WPKH";
|
|
9879
|
+
if (address.startsWith("1") || address.startsWith("m") || address.startsWith("n"))
|
|
9880
|
+
return "P2PKH";
|
|
9881
|
+
throw new Error(`Unknown Bitcoin address type: ${address}`);
|
|
9882
|
+
}
|
|
9802
9883
|
var DEFAULT_MAX_RETRY = 3;
|
|
9803
9884
|
var DEFAULT_RELAY_TX_TIMEOUT = 12e4;
|
|
9804
9885
|
var DEFAULT_RETRY_DELAY_MS = 2e3;
|
|
@@ -21177,6 +21258,714 @@ var SolanaSpokeService = class _SolanaSpokeService {
|
|
|
21177
21258
|
}
|
|
21178
21259
|
}
|
|
21179
21260
|
};
|
|
21261
|
+
|
|
21262
|
+
// src/shared/entities/btc/RadfiProvider.ts
|
|
21263
|
+
var RadfiProvider = class {
|
|
21264
|
+
constructor(config) {
|
|
21265
|
+
this.config = config;
|
|
21266
|
+
}
|
|
21267
|
+
async authenticate(params) {
|
|
21268
|
+
const res = await this.request("/auth/authenticate", {
|
|
21269
|
+
method: "POST",
|
|
21270
|
+
body: JSON.stringify(params)
|
|
21271
|
+
});
|
|
21272
|
+
if (!res.ok) {
|
|
21273
|
+
const err = await res.json();
|
|
21274
|
+
throw new Error(err.message || "Radfi authentication failed");
|
|
21275
|
+
}
|
|
21276
|
+
return res.json().then((r) => ({
|
|
21277
|
+
accessToken: r.data?.accessToken ?? "",
|
|
21278
|
+
refreshToken: r.data?.refreshToken ?? "",
|
|
21279
|
+
tradingAddress: r.data?.tradingAddress ?? r.data?.wallet?.tradingAddress ?? ""
|
|
21280
|
+
}));
|
|
21281
|
+
}
|
|
21282
|
+
async refreshAccessToken(refreshToken) {
|
|
21283
|
+
const res = await this.request("/auth/refresh-token", {
|
|
21284
|
+
method: "POST",
|
|
21285
|
+
body: JSON.stringify({ refreshToken })
|
|
21286
|
+
});
|
|
21287
|
+
if (!res.ok) {
|
|
21288
|
+
const err = await res.json();
|
|
21289
|
+
throw new Error(err.message || "Token refresh failed");
|
|
21290
|
+
}
|
|
21291
|
+
return res.json().then((r) => ({
|
|
21292
|
+
accessToken: r.data?.accessToken ?? "",
|
|
21293
|
+
refreshToken: r.data?.refreshToken ?? refreshToken
|
|
21294
|
+
}));
|
|
21295
|
+
}
|
|
21296
|
+
async createTradingWallet(params, accessToken) {
|
|
21297
|
+
const res = await this.request("/wallets", {
|
|
21298
|
+
method: "POST",
|
|
21299
|
+
headers: {
|
|
21300
|
+
Authorization: `Bearer ${accessToken || this.config.apiKey}`
|
|
21301
|
+
},
|
|
21302
|
+
body: JSON.stringify(params)
|
|
21303
|
+
});
|
|
21304
|
+
if (!res.ok) {
|
|
21305
|
+
const err = await res.json();
|
|
21306
|
+
throw new Error(err.message || "Failed to create trading wallet");
|
|
21307
|
+
}
|
|
21308
|
+
return res.json().then((r) => r.data);
|
|
21309
|
+
}
|
|
21310
|
+
async getTradingWallet(userAddress, accessToken) {
|
|
21311
|
+
const res = await this.request(`/wallets/details/${userAddress}`, {
|
|
21312
|
+
method: "GET",
|
|
21313
|
+
headers: accessToken ? { Authorization: `Bearer ${accessToken}` } : {}
|
|
21314
|
+
});
|
|
21315
|
+
if (!res.ok) {
|
|
21316
|
+
throw new Error("Trading wallet not found");
|
|
21317
|
+
}
|
|
21318
|
+
const data = await res.json().then((r) => r.data);
|
|
21319
|
+
if (!data) throw new Error("Trading wallet not found");
|
|
21320
|
+
return data;
|
|
21321
|
+
}
|
|
21322
|
+
async getBalance(address) {
|
|
21323
|
+
if (!this.config.umsUrl) {
|
|
21324
|
+
throw new Error("RadfiConfig.umsUrl is required for getBalance");
|
|
21325
|
+
}
|
|
21326
|
+
const umsUrl = this.config.umsUrl;
|
|
21327
|
+
const res = await fetch(`${umsUrl}/wallets/balance?address=${address}`, {
|
|
21328
|
+
method: "GET",
|
|
21329
|
+
headers: { "Content-Type": "application/json" }
|
|
21330
|
+
});
|
|
21331
|
+
if (!res.ok) {
|
|
21332
|
+
throw new Error("Failed to fetch wallet balance");
|
|
21333
|
+
}
|
|
21334
|
+
const { data } = await res.json();
|
|
21335
|
+
return {
|
|
21336
|
+
btcSatoshi: BigInt(data.btcSatoshi ?? "0"),
|
|
21337
|
+
pendingSatoshi: BigInt(data.pendingSatoshi ?? "0"),
|
|
21338
|
+
externalPendingSatoshi: BigInt(data.externalPendingSatoshi ?? "0"),
|
|
21339
|
+
totalUtxos: Number(data.totalUtxos ?? 0)
|
|
21340
|
+
};
|
|
21341
|
+
}
|
|
21342
|
+
async checkIfTradingWalletExists(userAddress) {
|
|
21343
|
+
try {
|
|
21344
|
+
await this.getTradingWallet(userAddress);
|
|
21345
|
+
return true;
|
|
21346
|
+
} catch (error) {
|
|
21347
|
+
return false;
|
|
21348
|
+
}
|
|
21349
|
+
}
|
|
21350
|
+
async createWithdrawTransaction(params, accessToken) {
|
|
21351
|
+
const res = await this.request("/sodax/transaction", {
|
|
21352
|
+
method: "POST",
|
|
21353
|
+
headers: {
|
|
21354
|
+
Authorization: `Bearer ${accessToken ?? this.config.apiKey}`
|
|
21355
|
+
},
|
|
21356
|
+
body: JSON.stringify({
|
|
21357
|
+
type: "sodax-withdraw",
|
|
21358
|
+
params: {
|
|
21359
|
+
amount: params.amount.toString(),
|
|
21360
|
+
tokenId: params.token,
|
|
21361
|
+
sodaxData: params.data
|
|
21362
|
+
}
|
|
21363
|
+
})
|
|
21364
|
+
});
|
|
21365
|
+
if (!res.ok) {
|
|
21366
|
+
const err = await res.json();
|
|
21367
|
+
throw new Error(err.message || "Radfi transaction request failed");
|
|
21368
|
+
}
|
|
21369
|
+
return res.json().then((r) => r.data);
|
|
21370
|
+
}
|
|
21371
|
+
async requestRadfiSignature(params, accessToken) {
|
|
21372
|
+
const res = await this.request("/sodax/transaction/sign", {
|
|
21373
|
+
method: "POST",
|
|
21374
|
+
headers: {
|
|
21375
|
+
Authorization: `Bearer ${accessToken ?? this.config.apiKey}`
|
|
21376
|
+
},
|
|
21377
|
+
body: JSON.stringify({
|
|
21378
|
+
type: "sodax-withdraw",
|
|
21379
|
+
params
|
|
21380
|
+
})
|
|
21381
|
+
});
|
|
21382
|
+
if (!res.ok) {
|
|
21383
|
+
const err = await res.json();
|
|
21384
|
+
throw new Error(err.message || "Radfi signature request failed");
|
|
21385
|
+
}
|
|
21386
|
+
return res.json().then((r) => r.data.txId);
|
|
21387
|
+
}
|
|
21388
|
+
/**
|
|
21389
|
+
* Fetch expired (or near-expiry) UTXOs for a trading wallet address from UMS API.
|
|
21390
|
+
*/
|
|
21391
|
+
async getExpiredUtxos(tradingAddress, params) {
|
|
21392
|
+
if (!this.config.umsUrl) {
|
|
21393
|
+
throw new Error("RadfiConfig.umsUrl is required for getExpiredUtxos");
|
|
21394
|
+
}
|
|
21395
|
+
const page = params?.page ?? 1;
|
|
21396
|
+
const pageSize = params?.pageSize ?? 100;
|
|
21397
|
+
const url = `${this.config.umsUrl}/utxos?address_eq=${tradingAddress}&isSpent_eq=false&isExpired_eq=true&page=${page}&pageSize=${pageSize}`;
|
|
21398
|
+
const res = await fetch(url, {
|
|
21399
|
+
method: "GET",
|
|
21400
|
+
headers: { "Content-Type": "application/json" }
|
|
21401
|
+
});
|
|
21402
|
+
if (!res.ok) {
|
|
21403
|
+
throw new Error("Failed to fetch expired UTXOs");
|
|
21404
|
+
}
|
|
21405
|
+
return res.json();
|
|
21406
|
+
}
|
|
21407
|
+
/**
|
|
21408
|
+
* Build a renew-utxo transaction via the Radfi API.
|
|
21409
|
+
* Returns a PSBT that needs to be signed by the user.
|
|
21410
|
+
*/
|
|
21411
|
+
async buildRenewUtxoTransaction(params, accessToken) {
|
|
21412
|
+
const res = await this.request("/transactions", {
|
|
21413
|
+
method: "POST",
|
|
21414
|
+
headers: {
|
|
21415
|
+
Authorization: `Bearer ${accessToken}`
|
|
21416
|
+
},
|
|
21417
|
+
body: JSON.stringify({
|
|
21418
|
+
type: "renew-utxo",
|
|
21419
|
+
params: {
|
|
21420
|
+
userAddress: params.userAddress,
|
|
21421
|
+
txIdVouts: params.txIdVouts
|
|
21422
|
+
}
|
|
21423
|
+
})
|
|
21424
|
+
});
|
|
21425
|
+
if (!res.ok) {
|
|
21426
|
+
const err = await res.json();
|
|
21427
|
+
throw new Error(err.message || "Failed to build renew-utxo transaction");
|
|
21428
|
+
}
|
|
21429
|
+
return res.json().then((r) => r.data);
|
|
21430
|
+
}
|
|
21431
|
+
/**
|
|
21432
|
+
* Sign and broadcast a renew-utxo transaction via the Radfi API.
|
|
21433
|
+
* The user signs the PSBT first, then Radfi co-signs and broadcasts.
|
|
21434
|
+
*/
|
|
21435
|
+
async signAndBroadcastRenewUtxo(params, accessToken) {
|
|
21436
|
+
const res = await this.request("/transactions/sign", {
|
|
21437
|
+
method: "POST",
|
|
21438
|
+
headers: {
|
|
21439
|
+
Authorization: `Bearer ${accessToken}`
|
|
21440
|
+
},
|
|
21441
|
+
body: JSON.stringify({
|
|
21442
|
+
type: "renew-utxo",
|
|
21443
|
+
params
|
|
21444
|
+
})
|
|
21445
|
+
});
|
|
21446
|
+
if (!res.ok) {
|
|
21447
|
+
const err = await res.json();
|
|
21448
|
+
throw new Error(err.message || "Failed to sign and broadcast renew-utxo transaction");
|
|
21449
|
+
}
|
|
21450
|
+
return res.json().then((r) => r.data.txId);
|
|
21451
|
+
}
|
|
21452
|
+
async request(endpoint, options) {
|
|
21453
|
+
return fetch(`${this.config.url}${endpoint}`, {
|
|
21454
|
+
...options,
|
|
21455
|
+
headers: {
|
|
21456
|
+
"Content-Type": "application/json",
|
|
21457
|
+
...options?.headers || {}
|
|
21458
|
+
}
|
|
21459
|
+
});
|
|
21460
|
+
}
|
|
21461
|
+
};
|
|
21462
|
+
bitcoin.initEccLib(ecc);
|
|
21463
|
+
var BITCOIN_DEFAULT_FEE_RATE = 3;
|
|
21464
|
+
var DUST_THRESHOLD = 546;
|
|
21465
|
+
function normalizePsbtToBase64(signedPsbt) {
|
|
21466
|
+
const isHex = /^[0-9a-fA-F]+$/.test(signedPsbt);
|
|
21467
|
+
return isHex ? Buffer.from(signedPsbt, "hex").toString("base64") : signedPsbt;
|
|
21468
|
+
}
|
|
21469
|
+
var BitcoinBaseSpokeProvider = class _BitcoinBaseSpokeProvider {
|
|
21470
|
+
rpcUrl;
|
|
21471
|
+
network;
|
|
21472
|
+
chainConfig;
|
|
21473
|
+
radfi;
|
|
21474
|
+
walletMode;
|
|
21475
|
+
radfiAccessToken = "";
|
|
21476
|
+
constructor(config, radfiConfig, walletMode = "USER", rpcURL) {
|
|
21477
|
+
this.chainConfig = config;
|
|
21478
|
+
this.rpcUrl = rpcURL ?? config.rpcUrl;
|
|
21479
|
+
this.network = config.network === "TESTNET" ? bitcoin.networks.testnet : bitcoin.networks.bitcoin;
|
|
21480
|
+
this.radfi = new RadfiProvider(radfiConfig);
|
|
21481
|
+
this.walletMode = walletMode;
|
|
21482
|
+
}
|
|
21483
|
+
setRadfiAccessToken(token) {
|
|
21484
|
+
this.radfiAccessToken = token;
|
|
21485
|
+
}
|
|
21486
|
+
/**
|
|
21487
|
+
* Get current fee estimates
|
|
21488
|
+
*/
|
|
21489
|
+
async getFeeEstimate(targetBlocks = 6) {
|
|
21490
|
+
try {
|
|
21491
|
+
const response = await fetch(`${this.rpcUrl}/fee-estimates`);
|
|
21492
|
+
if (!response.ok) {
|
|
21493
|
+
return BITCOIN_DEFAULT_FEE_RATE;
|
|
21494
|
+
}
|
|
21495
|
+
const feeEstimates = await response.json();
|
|
21496
|
+
return feeEstimates[targetBlocks] ?? BITCOIN_DEFAULT_FEE_RATE;
|
|
21497
|
+
} catch {
|
|
21498
|
+
return BITCOIN_DEFAULT_FEE_RATE;
|
|
21499
|
+
}
|
|
21500
|
+
}
|
|
21501
|
+
static async getBalance(tokenAddress, provider) {
|
|
21502
|
+
const walletAddress = await provider.walletProvider.getWalletAddress();
|
|
21503
|
+
if (!tokenAddress || tokenAddress === "0x" || tokenAddress === "BTC") {
|
|
21504
|
+
const utxos = await provider.fetchUTXOs(walletAddress);
|
|
21505
|
+
const totalBalance = utxos.reduce((sum, utxo) => sum + utxo.value, 0);
|
|
21506
|
+
return BigInt(totalBalance);
|
|
21507
|
+
}
|
|
21508
|
+
throw new Error("Token balance queries not yet implemented for non-BTC assets");
|
|
21509
|
+
}
|
|
21510
|
+
async fetchScriptPubKey(utxo, provider) {
|
|
21511
|
+
const txHex = await provider.fetchRawTransaction(utxo.txid);
|
|
21512
|
+
const tx = bitcoin.Transaction.fromHex(txHex);
|
|
21513
|
+
const out = tx.outs[utxo.vout];
|
|
21514
|
+
if (!out) {
|
|
21515
|
+
throw new Error(`UTXO not found: ${utxo.txid}:${utxo.vout}`);
|
|
21516
|
+
}
|
|
21517
|
+
return out.script.toString("hex");
|
|
21518
|
+
}
|
|
21519
|
+
/**
|
|
21520
|
+
* Build a priority Bitcoin transaction with proper fee calculation
|
|
21521
|
+
*/
|
|
21522
|
+
static async buildBitcoinTransaction(utxos, outputs, changeAddress, provider, feeRate) {
|
|
21523
|
+
const psbt = new bitcoin.Psbt({ network: provider.network });
|
|
21524
|
+
const effectiveFeeRate = feeRate ?? await provider.getFeeEstimate();
|
|
21525
|
+
let inputSum = 0;
|
|
21526
|
+
const outputSum = outputs.reduce((sum, o) => sum + o.value, 0);
|
|
21527
|
+
for (const utxo of utxos) {
|
|
21528
|
+
if (!utxo.status.confirmed) continue;
|
|
21529
|
+
const scriptPubKey = await provider.fetchScriptPubKey(utxo, provider);
|
|
21530
|
+
const isTaproot = scriptPubKey.startsWith("51");
|
|
21531
|
+
const isSegwitV0 = scriptPubKey.startsWith("00");
|
|
21532
|
+
if (isTaproot) {
|
|
21533
|
+
if (!provider.walletProvider.getPublicKey) {
|
|
21534
|
+
throw new Error("Missing public key for P2TR input");
|
|
21535
|
+
}
|
|
21536
|
+
const tapInternalKey = await provider.walletProvider.getPublicKey();
|
|
21537
|
+
psbt.addInput({
|
|
21538
|
+
hash: utxo.txid,
|
|
21539
|
+
index: utxo.vout,
|
|
21540
|
+
witnessUtxo: {
|
|
21541
|
+
script: Buffer.from(scriptPubKey, "hex"),
|
|
21542
|
+
value: utxo.value
|
|
21543
|
+
},
|
|
21544
|
+
tapInternalKey: Buffer.from(tapInternalKey, "hex")
|
|
21545
|
+
});
|
|
21546
|
+
} else if (isSegwitV0) {
|
|
21547
|
+
psbt.addInput({
|
|
21548
|
+
hash: utxo.txid,
|
|
21549
|
+
index: utxo.vout,
|
|
21550
|
+
witnessUtxo: {
|
|
21551
|
+
script: Buffer.from(scriptPubKey, "hex"),
|
|
21552
|
+
value: utxo.value
|
|
21553
|
+
}
|
|
21554
|
+
});
|
|
21555
|
+
} else {
|
|
21556
|
+
const txHex = await provider.fetchRawTransaction(utxo.txid);
|
|
21557
|
+
psbt.addInput({
|
|
21558
|
+
hash: utxo.txid,
|
|
21559
|
+
index: utxo.vout,
|
|
21560
|
+
nonWitnessUtxo: Buffer.from(txHex, "hex")
|
|
21561
|
+
});
|
|
21562
|
+
}
|
|
21563
|
+
inputSum += utxo.value;
|
|
21564
|
+
const estimatedSize = provider.estimateTxSize(psbt.inputCount, outputs.length);
|
|
21565
|
+
const estimatedFee = Math.ceil(effectiveFeeRate * estimatedSize);
|
|
21566
|
+
if (inputSum >= outputSum + estimatedFee + DUST_THRESHOLD) {
|
|
21567
|
+
break;
|
|
21568
|
+
}
|
|
21569
|
+
}
|
|
21570
|
+
for (const output of outputs) {
|
|
21571
|
+
psbt.addOutput({
|
|
21572
|
+
address: output.address,
|
|
21573
|
+
value: output.value
|
|
21574
|
+
});
|
|
21575
|
+
}
|
|
21576
|
+
const sizeWithChange = provider.estimateTxSize(psbt.inputCount, outputs.length + 1);
|
|
21577
|
+
const sizeWithoutChange = provider.estimateTxSize(psbt.inputCount, outputs.length);
|
|
21578
|
+
const feeWithChange = Math.ceil(effectiveFeeRate * sizeWithChange);
|
|
21579
|
+
const feeWithoutChange = Math.ceil(effectiveFeeRate * sizeWithoutChange);
|
|
21580
|
+
let change = inputSum - outputSum - feeWithChange;
|
|
21581
|
+
if (change < 0) {
|
|
21582
|
+
const confirmedCount = utxos.filter((u) => u.status.confirmed).length;
|
|
21583
|
+
const unconfirmedCount = utxos.length - confirmedCount;
|
|
21584
|
+
const hint = unconfirmedCount > 0 ? ` (${unconfirmedCount} unconfirmed UTXO(s) skipped \u2014 wait for confirmation)` : "";
|
|
21585
|
+
throw new Error(`Insufficient funds. Need ${outputSum + feeWithChange} satoshis, have ${inputSum}${hint}`);
|
|
21586
|
+
}
|
|
21587
|
+
if (change > DUST_THRESHOLD) {
|
|
21588
|
+
psbt.addOutput({
|
|
21589
|
+
address: changeAddress,
|
|
21590
|
+
value: change
|
|
21591
|
+
});
|
|
21592
|
+
} else {
|
|
21593
|
+
const finalFee = feeWithoutChange;
|
|
21594
|
+
change = inputSum - outputSum - finalFee;
|
|
21595
|
+
if (change < 0) {
|
|
21596
|
+
throw new Error(`Insufficient funds after dust handling. Need ${outputSum + finalFee}`);
|
|
21597
|
+
}
|
|
21598
|
+
}
|
|
21599
|
+
return psbt;
|
|
21600
|
+
}
|
|
21601
|
+
/**
|
|
21602
|
+
* Deposit operation - transfer BTC to the asset manager
|
|
21603
|
+
*/
|
|
21604
|
+
static async deposit(token, amount, data, provider, raw, accessToken = "") {
|
|
21605
|
+
try {
|
|
21606
|
+
const walletAddress = await provider.walletProvider.getWalletAddress();
|
|
21607
|
+
const returnRawTx = (psbtBase64) => ({
|
|
21608
|
+
from: walletAddress,
|
|
21609
|
+
to: provider.chainConfig.addresses.assetManager,
|
|
21610
|
+
value: amount,
|
|
21611
|
+
data: psbtBase64
|
|
21612
|
+
});
|
|
21613
|
+
if (provider.walletMode === "TRADING") {
|
|
21614
|
+
const tokenId = Object.values(provider.chainConfig.supportedTokens).find((t) => t.address === token)?.address;
|
|
21615
|
+
if (!tokenId) {
|
|
21616
|
+
throw new Error(`Unsupported token: ${token}`);
|
|
21617
|
+
}
|
|
21618
|
+
data = data.startsWith("0x") ? data.slice(2) : data;
|
|
21619
|
+
data = data.length === 64 ? data : keccak256(`0x${data}`).slice(2);
|
|
21620
|
+
accessToken = accessToken || provider.radfiAccessToken;
|
|
21621
|
+
const withdrawTx = await provider.radfi.createWithdrawTransaction(
|
|
21622
|
+
{
|
|
21623
|
+
token: tokenId,
|
|
21624
|
+
amount,
|
|
21625
|
+
recipient: provider.chainConfig.addresses.assetManager,
|
|
21626
|
+
userAddress: walletAddress,
|
|
21627
|
+
data
|
|
21628
|
+
},
|
|
21629
|
+
accessToken
|
|
21630
|
+
);
|
|
21631
|
+
if (raw || isBitcoinRawSpokeProvider(provider)) {
|
|
21632
|
+
return returnRawTx(withdrawTx.base64Psbt);
|
|
21633
|
+
}
|
|
21634
|
+
const signedTx = await provider.walletProvider.signTransaction(withdrawTx.base64Psbt, false);
|
|
21635
|
+
const signedBase64Tx = normalizePsbtToBase64(signedTx);
|
|
21636
|
+
return await provider.radfi.requestRadfiSignature(
|
|
21637
|
+
{
|
|
21638
|
+
userAddress: walletAddress,
|
|
21639
|
+
signedBase64Tx
|
|
21640
|
+
},
|
|
21641
|
+
accessToken
|
|
21642
|
+
);
|
|
21643
|
+
}
|
|
21644
|
+
const utxos = await provider.fetchUTXOs(walletAddress);
|
|
21645
|
+
if (!utxos?.length) {
|
|
21646
|
+
throw new Error("No UTXOs available for deposit");
|
|
21647
|
+
}
|
|
21648
|
+
const depositPsbt = await _BitcoinBaseSpokeProvider.buildDepositPsbt(
|
|
21649
|
+
walletAddress,
|
|
21650
|
+
token,
|
|
21651
|
+
amount,
|
|
21652
|
+
data,
|
|
21653
|
+
utxos,
|
|
21654
|
+
provider
|
|
21655
|
+
);
|
|
21656
|
+
if (raw || isBitcoinRawSpokeProvider(provider)) {
|
|
21657
|
+
return returnRawTx(depositPsbt.toBase64());
|
|
21658
|
+
}
|
|
21659
|
+
return await provider.signAndBroadcastTransaction(depositPsbt);
|
|
21660
|
+
} catch (error) {
|
|
21661
|
+
console.error("Error during deposit:", error);
|
|
21662
|
+
throw error;
|
|
21663
|
+
}
|
|
21664
|
+
}
|
|
21665
|
+
/**
|
|
21666
|
+
* Build deposit PSBT with embedded cross-chain data
|
|
21667
|
+
*/
|
|
21668
|
+
static async buildDepositPsbt(walletAddress, token, amount, data, utxos, provider) {
|
|
21669
|
+
const assetManagerAddress = provider.chainConfig.addresses.assetManager;
|
|
21670
|
+
if (token.toLocaleLowerCase() === "btc") {
|
|
21671
|
+
const outputs = [
|
|
21672
|
+
{
|
|
21673
|
+
address: assetManagerAddress,
|
|
21674
|
+
value: Number(amount)
|
|
21675
|
+
}
|
|
21676
|
+
];
|
|
21677
|
+
const psbt = await _BitcoinBaseSpokeProvider.buildBitcoinTransaction(utxos, outputs, walletAddress, provider);
|
|
21678
|
+
const OP_RADFI_SODAX_DATA = 49;
|
|
21679
|
+
const payload = Buffer.concat([Buffer.from([OP_RADFI_SODAX_DATA]), Buffer.from(data.slice(2), "hex")]);
|
|
21680
|
+
const OP_RETURN = bitcoin.opcodes.OP_RETURN;
|
|
21681
|
+
const OP_12 = bitcoin.opcodes.OP_12;
|
|
21682
|
+
if (OP_RETURN === void 0 || OP_12 === void 0) {
|
|
21683
|
+
throw new Error("bitcoinjs-lib opcodes OP_RETURN or OP_12 are undefined");
|
|
21684
|
+
}
|
|
21685
|
+
const script2 = bitcoin.script.compile([OP_RETURN, OP_12, payload]);
|
|
21686
|
+
psbt.addOutput({
|
|
21687
|
+
script: script2,
|
|
21688
|
+
value: 0
|
|
21689
|
+
});
|
|
21690
|
+
return psbt;
|
|
21691
|
+
}
|
|
21692
|
+
throw new Error(`Non-BTC token deposits not yet implemented (token: ${token})`);
|
|
21693
|
+
}
|
|
21694
|
+
/**
|
|
21695
|
+
* Fetch UTXOs for an address
|
|
21696
|
+
*/
|
|
21697
|
+
async fetchUTXOs(address) {
|
|
21698
|
+
const response = await fetch(`${this.rpcUrl}/address/${address}/utxo`);
|
|
21699
|
+
if (!response.ok) {
|
|
21700
|
+
throw new Error(`Failed to fetch UTXOs: ${response.statusText}`);
|
|
21701
|
+
}
|
|
21702
|
+
return await response.json();
|
|
21703
|
+
}
|
|
21704
|
+
/**
|
|
21705
|
+
* Fetch raw transaction hex
|
|
21706
|
+
*/
|
|
21707
|
+
async fetchRawTransaction(txid) {
|
|
21708
|
+
const response = await fetch(`${this.rpcUrl}/tx/${txid}/hex`);
|
|
21709
|
+
if (!response.ok) {
|
|
21710
|
+
throw new Error(`Failed to fetch transaction: ${response.statusText}`);
|
|
21711
|
+
}
|
|
21712
|
+
return await response.text();
|
|
21713
|
+
}
|
|
21714
|
+
/**
|
|
21715
|
+
* Estimate transaction size in vbytes
|
|
21716
|
+
*/
|
|
21717
|
+
estimateTxSize(inputCount, outputCount) {
|
|
21718
|
+
return Math.ceil(10.5 + 44 + inputCount * 68 + outputCount * 31);
|
|
21719
|
+
}
|
|
21720
|
+
getAddressType(address) {
|
|
21721
|
+
return detectBitcoinAddressType(address);
|
|
21722
|
+
}
|
|
21723
|
+
encodePayloadToBytes(payload) {
|
|
21724
|
+
const ordered = {
|
|
21725
|
+
src_address: payload.src_address.toLowerCase(),
|
|
21726
|
+
data: payload.data.toLowerCase(),
|
|
21727
|
+
src_chain_id: payload.src_chain_id,
|
|
21728
|
+
dst_chain_id: payload.dst_chain_id,
|
|
21729
|
+
wallet_used: payload.wallet_used,
|
|
21730
|
+
timestamp: payload.timestamp,
|
|
21731
|
+
address_type: payload.address_type
|
|
21732
|
+
};
|
|
21733
|
+
const json = JSON.stringify(ordered);
|
|
21734
|
+
return json;
|
|
21735
|
+
}
|
|
21736
|
+
static async encodeWithdrawalData(dstChainId, data, provider, raw) {
|
|
21737
|
+
let srcAddress = await provider.walletProvider.getWalletAddress();
|
|
21738
|
+
const addressType = provider.getAddressType(srcAddress);
|
|
21739
|
+
if (provider.walletMode === "TRADING") {
|
|
21740
|
+
srcAddress = await provider.radfi.getTradingWallet(srcAddress).then((res) => res.tradingAddress).catch(() => srcAddress);
|
|
21741
|
+
}
|
|
21742
|
+
const payload = {
|
|
21743
|
+
src_address: srcAddress,
|
|
21744
|
+
data,
|
|
21745
|
+
src_chain_id: Number(getIntentRelayChainId(provider.chainConfig.chain.id)),
|
|
21746
|
+
dst_chain_id: Number(getIntentRelayChainId(dstChainId)),
|
|
21747
|
+
wallet_used: provider.walletMode,
|
|
21748
|
+
timestamp: Date.now(),
|
|
21749
|
+
address_type: addressType
|
|
21750
|
+
};
|
|
21751
|
+
const orderedPayload = provider.encodePayloadToBytes(payload);
|
|
21752
|
+
const onDemandWithdraw = {
|
|
21753
|
+
payload_hex: Buffer.from(orderedPayload).toString("hex"),
|
|
21754
|
+
signature: void 0
|
|
21755
|
+
};
|
|
21756
|
+
if (raw || isBitcoinRawSpokeProvider(provider)) {
|
|
21757
|
+
return JSON.stringify(onDemandWithdraw);
|
|
21758
|
+
}
|
|
21759
|
+
const signature = await provider.walletProvider.signEcdsaMessage(orderedPayload);
|
|
21760
|
+
onDemandWithdraw.signature = signature;
|
|
21761
|
+
return JSON.stringify(onDemandWithdraw);
|
|
21762
|
+
}
|
|
21763
|
+
};
|
|
21764
|
+
var BitcoinRawSpokeProvider = class extends BitcoinBaseSpokeProvider {
|
|
21765
|
+
walletProvider;
|
|
21766
|
+
raw = true;
|
|
21767
|
+
constructor(walletAddress, publicKey, chainConfig, radfiConfig, walletMode = "USER", rpcUrl) {
|
|
21768
|
+
super(chainConfig, radfiConfig, walletMode, rpcUrl);
|
|
21769
|
+
this.walletProvider = {
|
|
21770
|
+
getWalletAddress: async () => walletAddress,
|
|
21771
|
+
getPublicKey: async () => publicKey
|
|
21772
|
+
};
|
|
21773
|
+
}
|
|
21774
|
+
};
|
|
21775
|
+
var BitcoinSpokeProvider = class extends BitcoinBaseSpokeProvider {
|
|
21776
|
+
walletProvider;
|
|
21777
|
+
constructor(walletProvider, chainConfig, radfiConfig, walletMode = "USER", rpcUrl) {
|
|
21778
|
+
super(chainConfig, radfiConfig, walletMode, rpcUrl);
|
|
21779
|
+
this.walletProvider = walletProvider;
|
|
21780
|
+
}
|
|
21781
|
+
/**
|
|
21782
|
+
* Authenticate with Radfi: BIP322-sign a login message, then call the Radfi API.
|
|
21783
|
+
* Returns accessToken, refreshToken, and tradingAddress.
|
|
21784
|
+
*/
|
|
21785
|
+
async authenticateWithWallet(cachedPublicKey) {
|
|
21786
|
+
const address = await this.walletProvider.getWalletAddress();
|
|
21787
|
+
let publicKey = cachedPublicKey;
|
|
21788
|
+
if (!publicKey) {
|
|
21789
|
+
if (!this.walletProvider.getPublicKey) {
|
|
21790
|
+
throw new Error("Wallet provider does not support getPublicKey");
|
|
21791
|
+
}
|
|
21792
|
+
publicKey = await this.walletProvider.getPublicKey();
|
|
21793
|
+
}
|
|
21794
|
+
if (!publicKey) {
|
|
21795
|
+
throw new Error("Failed to retrieve public key from wallet. Please unlock your wallet and try again.");
|
|
21796
|
+
}
|
|
21797
|
+
const message = `Login to Radfi via Sodax: ${Date.now()}`;
|
|
21798
|
+
const signature = await this.walletProvider.signBip322Message(message);
|
|
21799
|
+
const result = await this.radfi.authenticate({ message, signature, address, publicKey });
|
|
21800
|
+
this.setRadfiAccessToken(result.accessToken);
|
|
21801
|
+
return { ...result, publicKey };
|
|
21802
|
+
}
|
|
21803
|
+
/**
|
|
21804
|
+
* Ensure a valid Radfi access token is set on this provider.
|
|
21805
|
+
* No-op if a token is already present.
|
|
21806
|
+
*/
|
|
21807
|
+
async ensureRadfiAccessToken() {
|
|
21808
|
+
if (this.radfiAccessToken) return;
|
|
21809
|
+
await this.authenticateWithWallet();
|
|
21810
|
+
}
|
|
21811
|
+
/**
|
|
21812
|
+
* Sign and broadcast a Bitcoin transaction
|
|
21813
|
+
*/
|
|
21814
|
+
async signAndBroadcastTransaction(psbt) {
|
|
21815
|
+
const psbtBase64 = typeof psbt === "string" ? psbt : psbt.toBase64();
|
|
21816
|
+
const signedPsbtHex = await this.walletProvider.signTransaction(psbtBase64);
|
|
21817
|
+
const txHash = await this.broadcastTransaction(signedPsbtHex);
|
|
21818
|
+
return txHash;
|
|
21819
|
+
}
|
|
21820
|
+
/**
|
|
21821
|
+
* Broadcast a signed transaction
|
|
21822
|
+
*/
|
|
21823
|
+
async broadcastTransaction(txHex) {
|
|
21824
|
+
const response = await fetch(`${this.rpcUrl}/tx`, {
|
|
21825
|
+
method: "POST",
|
|
21826
|
+
body: txHex
|
|
21827
|
+
});
|
|
21828
|
+
if (!response.ok) {
|
|
21829
|
+
const errorText = await response.text();
|
|
21830
|
+
throw new Error(`Failed to broadcast transaction: ${errorText}`);
|
|
21831
|
+
}
|
|
21832
|
+
return await response.text();
|
|
21833
|
+
}
|
|
21834
|
+
};
|
|
21835
|
+
|
|
21836
|
+
// src/shared/services/spoke/BitcoinSpokeService.ts
|
|
21837
|
+
var BitcoinSpokeService = class _BitcoinSpokeService {
|
|
21838
|
+
constructor() {
|
|
21839
|
+
}
|
|
21840
|
+
/**
|
|
21841
|
+
* Estimate transaction fee for a Bitcoin transaction
|
|
21842
|
+
*
|
|
21843
|
+
* @param {Hex} rawTx - The raw transaction parameters
|
|
21844
|
+
* @param {BitcoinSpokeProviderType} spokeProvider - The Bitcoin spoke provider
|
|
21845
|
+
* @returns {Promise<bigint>} Estimated fee in satoshis
|
|
21846
|
+
*/
|
|
21847
|
+
static async estimateGas(rawTx, spokeProvider) {
|
|
21848
|
+
const txBytes = Buffer.from(rawTx, "hex");
|
|
21849
|
+
const vsize = Math.ceil(txBytes.length);
|
|
21850
|
+
const feeRate = await spokeProvider.getFeeEstimate();
|
|
21851
|
+
const feeRateBigInt = typeof feeRate === "bigint" ? feeRate : BigInt(Math.ceil(feeRate));
|
|
21852
|
+
return BigInt(vsize) * feeRateBigInt;
|
|
21853
|
+
}
|
|
21854
|
+
/**
|
|
21855
|
+
* Deposit tokens to the spoke chain and bridge to hub
|
|
21856
|
+
*
|
|
21857
|
+
* @param {BitcoinSpokeDepositParams} params - Deposit parameters
|
|
21858
|
+
* @param {BitcoinSpokeProviderType} spokeProvider - The Bitcoin spoke provider
|
|
21859
|
+
* @param {EvmHubProvider} EvmHubProvider - The hub chain provider
|
|
21860
|
+
* @param {boolean} raw - Whether to return raw PSBT or transaction hash
|
|
21861
|
+
* @returns {Promise<TxReturnType<BitcoinSpokeProviderType, R>>} Transaction hash or raw PSBT
|
|
21862
|
+
*/
|
|
21863
|
+
static async deposit(params, spokeProvider, raw) {
|
|
21864
|
+
return _BitcoinSpokeService.transfer(
|
|
21865
|
+
{
|
|
21866
|
+
token: params.token,
|
|
21867
|
+
amount: params.amount,
|
|
21868
|
+
data: params.data ?? "0x",
|
|
21869
|
+
accessToken: params.accessToken
|
|
21870
|
+
},
|
|
21871
|
+
spokeProvider,
|
|
21872
|
+
raw
|
|
21873
|
+
);
|
|
21874
|
+
}
|
|
21875
|
+
/**
|
|
21876
|
+
* Get the balance of deposited tokens in the asset manager
|
|
21877
|
+
*
|
|
21878
|
+
* @param {string} token - Token identifier ('BTC' for native Bitcoin)
|
|
21879
|
+
* @param {BitcoinSpokeProviderType} spokeProvider - The Bitcoin spoke provider
|
|
21880
|
+
* @returns {Promise<bigint>} Balance in satoshis
|
|
21881
|
+
*/
|
|
21882
|
+
static async getDeposit(token, spokeProvider) {
|
|
21883
|
+
const assetManagerAddress = spokeProvider.chainConfig.addresses.assetManager;
|
|
21884
|
+
const utxos = await spokeProvider.fetchUTXOs(assetManagerAddress);
|
|
21885
|
+
const totalBalance = utxos.reduce((sum, utxo) => sum + utxo.value, 0);
|
|
21886
|
+
return BigInt(totalBalance);
|
|
21887
|
+
}
|
|
21888
|
+
/**
|
|
21889
|
+
* Generate simulation parameters for deposit
|
|
21890
|
+
*
|
|
21891
|
+
* @param {BitcoinSpokeDepositParams} params - Deposit parameters
|
|
21892
|
+
* @param {BitcoinSpokeProviderType} spokeProvider - The Bitcoin spoke provider
|
|
21893
|
+
* @param {EvmHubProvider} EvmHubProvider - The hub chain provider
|
|
21894
|
+
* @returns {Promise<DepositSimulationParams>} Simulation parameters
|
|
21895
|
+
*/
|
|
21896
|
+
static async getSimulateDepositParams(params, spokeProvider, EvmHubProvider2) {
|
|
21897
|
+
const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
21898
|
+
spokeProvider.chainConfig.chain.id,
|
|
21899
|
+
encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
|
|
21900
|
+
EvmHubProvider2
|
|
21901
|
+
);
|
|
21902
|
+
const tokenEntry = Object.values(spokeProvider.chainConfig.supportedTokens).find((t) => t.address === params.token);
|
|
21903
|
+
const token = tokenEntry?.address ?? params.token;
|
|
21904
|
+
return {
|
|
21905
|
+
spokeChainID: spokeProvider.chainConfig.chain.id,
|
|
21906
|
+
token: encodeAddress(spokeProvider.chainConfig.chain.id, token),
|
|
21907
|
+
from: encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
|
|
21908
|
+
to,
|
|
21909
|
+
amount: params.amount,
|
|
21910
|
+
data: params.data,
|
|
21911
|
+
srcAddress: encodeAddress(spokeProvider.chainConfig.chain.id, spokeProvider.chainConfig.addresses.assetManager)
|
|
21912
|
+
};
|
|
21913
|
+
}
|
|
21914
|
+
/**
|
|
21915
|
+
* Fund the Radfi trading wallet by sending BTC from the user's personal wallet
|
|
21916
|
+
*
|
|
21917
|
+
* @param {bigint} amount - Amount in satoshis to send
|
|
21918
|
+
* @param {BitcoinSpokeProvider} spokeProvider - The Bitcoin spoke provider (must have signing capability)
|
|
21919
|
+
* @returns {Promise<string>} Transaction ID of the funding transaction
|
|
21920
|
+
*/
|
|
21921
|
+
static async fundTradingWallet(amount, spokeProvider) {
|
|
21922
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
21923
|
+
const { tradingAddress } = await spokeProvider.radfi.getTradingWallet(walletAddress);
|
|
21924
|
+
return spokeProvider.walletProvider.sendBitcoin(tradingAddress, amount);
|
|
21925
|
+
}
|
|
21926
|
+
/**
|
|
21927
|
+
* Call a contract on the hub chain from Bitcoin spoke
|
|
21928
|
+
*
|
|
21929
|
+
* @param {HubAddress} from - The hub wallet address
|
|
21930
|
+
* @param {Hex} payload - The payload to send
|
|
21931
|
+
* @param {BitcoinSpokeProviderType} spokeProvider - The Bitcoin spoke provider
|
|
21932
|
+
* @param {EvmHubProvider} EvmHubProvider - The hub chain provider
|
|
21933
|
+
* @param {boolean} raw - Whether to return raw PSBT or transaction hash
|
|
21934
|
+
* @returns {Promise<TxReturnType<BitcoinSpokeProviderType, R>>} Stringified JSON for payload and signature
|
|
21935
|
+
*/
|
|
21936
|
+
static async callWallet(from, payload, spokeProvider, EvmHubProvider2, raw) {
|
|
21937
|
+
return _BitcoinSpokeService.call(EvmHubProvider2.chainConfig.chain.id, from, payload, spokeProvider, raw);
|
|
21938
|
+
}
|
|
21939
|
+
/**
|
|
21940
|
+
* Transfer tokens to the hub chain
|
|
21941
|
+
*
|
|
21942
|
+
* @param {BitcoinTransferToHubParams} params - Transfer parameters
|
|
21943
|
+
* @param {BitcoinSpokeProviderType} spokeProvider - The Bitcoin spoke provider
|
|
21944
|
+
* @param {boolean} raw - Whether to return raw PSBT or transaction hash
|
|
21945
|
+
* @returns {Promise<TxReturnType<BitcoinSpokeProviderType, R>>} Transaction hash or raw PSBT
|
|
21946
|
+
*/
|
|
21947
|
+
static async transfer({ token, amount, data = "0x", accessToken }, spokeProvider, raw) {
|
|
21948
|
+
return await BitcoinBaseSpokeProvider.deposit(token, amount, data, spokeProvider, raw, accessToken);
|
|
21949
|
+
}
|
|
21950
|
+
/**
|
|
21951
|
+
* Send a message to the hub chain
|
|
21952
|
+
*
|
|
21953
|
+
* @param {HubChainId} dstChainId - Destination chain ID
|
|
21954
|
+
* @param {HubAddress} dstAddress - Destination address on hub
|
|
21955
|
+
* @param {Hex} payload - Message payload
|
|
21956
|
+
* @param {BitcoinSpokeProviderType} spokeProvider - The Bitcoin spoke provider
|
|
21957
|
+
* @param {boolean} raw - Whether to return raw PSBT or transaction hash
|
|
21958
|
+
* @returns {Promise<TxReturnType<BitcoinSpokeProviderType, R>>} Transaction hash or raw PSBT
|
|
21959
|
+
*/
|
|
21960
|
+
static async call(dstChainId, dstAddress, payload, spokeProvider, raw) {
|
|
21961
|
+
return await BitcoinBaseSpokeProvider.encodeWithdrawalData(
|
|
21962
|
+
dstChainId,
|
|
21963
|
+
payload,
|
|
21964
|
+
spokeProvider,
|
|
21965
|
+
raw
|
|
21966
|
+
);
|
|
21967
|
+
}
|
|
21968
|
+
};
|
|
21180
21969
|
var NearSpokeService = class _NearSpokeService {
|
|
21181
21970
|
constructor() {
|
|
21182
21971
|
}
|
|
@@ -21535,6 +22324,14 @@ var SpokeService = class _SpokeService {
|
|
|
21535
22324
|
raw
|
|
21536
22325
|
);
|
|
21537
22326
|
}
|
|
22327
|
+
if (isBitcoinSpokeProviderType(spokeProvider)) {
|
|
22328
|
+
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
22329
|
+
return BitcoinSpokeService.deposit(
|
|
22330
|
+
params,
|
|
22331
|
+
spokeProvider,
|
|
22332
|
+
raw
|
|
22333
|
+
);
|
|
22334
|
+
}
|
|
21538
22335
|
if (isNearSpokeProviderType(spokeProvider)) {
|
|
21539
22336
|
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
21540
22337
|
return NearSpokeService.deposit(
|
|
@@ -21589,6 +22386,13 @@ var SpokeService = class _SpokeService {
|
|
|
21589
22386
|
hubProvider
|
|
21590
22387
|
);
|
|
21591
22388
|
}
|
|
22389
|
+
if (isBitcoinSpokeProviderType(spokeProvider)) {
|
|
22390
|
+
return BitcoinSpokeService.getSimulateDepositParams(
|
|
22391
|
+
params,
|
|
22392
|
+
spokeProvider,
|
|
22393
|
+
hubProvider
|
|
22394
|
+
);
|
|
22395
|
+
}
|
|
21592
22396
|
if (isNearSpokeProviderType(spokeProvider)) {
|
|
21593
22397
|
return NearSpokeService.getSimulateDepositParams(
|
|
21594
22398
|
params,
|
|
@@ -21635,6 +22439,9 @@ var SpokeService = class _SpokeService {
|
|
|
21635
22439
|
if (isSonicSpokeProviderType(spokeProvider)) {
|
|
21636
22440
|
return SonicSpokeService.getDeposit(token, spokeProvider);
|
|
21637
22441
|
}
|
|
22442
|
+
if (isBitcoinSpokeProviderType(spokeProvider)) {
|
|
22443
|
+
return BitcoinSpokeService.getDeposit(token, spokeProvider);
|
|
22444
|
+
}
|
|
21638
22445
|
if (isNearSpokeProviderType(spokeProvider)) {
|
|
21639
22446
|
return NearSpokeService.getDeposit(token, spokeProvider);
|
|
21640
22447
|
}
|
|
@@ -21652,15 +22459,24 @@ var SpokeService = class _SpokeService {
|
|
|
21652
22459
|
if (isSonicSpokeProviderType(spokeProvider)) {
|
|
21653
22460
|
return await SonicSpokeService.callWallet(payload, spokeProvider, raw);
|
|
21654
22461
|
}
|
|
22462
|
+
let srcAddress = encodeAddress(
|
|
22463
|
+
spokeProvider.chainConfig.chain.id,
|
|
22464
|
+
await spokeProvider.walletProvider.getWalletAddress()
|
|
22465
|
+
);
|
|
22466
|
+
if (isBitcoinSpokeProvider(spokeProvider)) {
|
|
22467
|
+
if (spokeProvider.walletMode === "TRADING") {
|
|
22468
|
+
const tradingWalletAddress = await spokeProvider.radfi.getTradingWallet(
|
|
22469
|
+
await spokeProvider.walletProvider.getWalletAddress()
|
|
22470
|
+
);
|
|
22471
|
+
srcAddress = encodeAddress(spokeProvider.chainConfig.chain.id, tradingWalletAddress.tradingAddress);
|
|
22472
|
+
}
|
|
22473
|
+
}
|
|
21655
22474
|
if (!skipSimulation) {
|
|
21656
22475
|
const result = await _SpokeService.simulateRecvMessage(
|
|
21657
22476
|
{
|
|
21658
22477
|
target: from,
|
|
21659
22478
|
srcChainId: getIntentRelayChainId(spokeProvider.chainConfig.chain.id),
|
|
21660
|
-
srcAddress
|
|
21661
|
-
spokeProvider.chainConfig.chain.id,
|
|
21662
|
-
await spokeProvider.walletProvider.getWalletAddress()
|
|
21663
|
-
),
|
|
22479
|
+
srcAddress,
|
|
21664
22480
|
payload
|
|
21665
22481
|
},
|
|
21666
22482
|
hubProvider
|
|
@@ -21711,6 +22527,16 @@ var SpokeService = class _SpokeService {
|
|
|
21711
22527
|
raw
|
|
21712
22528
|
);
|
|
21713
22529
|
}
|
|
22530
|
+
if (isBitcoinSpokeProviderType(spokeProvider)) {
|
|
22531
|
+
await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
|
|
22532
|
+
return await BitcoinSpokeService.callWallet(
|
|
22533
|
+
from,
|
|
22534
|
+
payload,
|
|
22535
|
+
spokeProvider,
|
|
22536
|
+
hubProvider,
|
|
22537
|
+
raw
|
|
22538
|
+
);
|
|
22539
|
+
}
|
|
21714
22540
|
if (isNearSpokeProviderType(spokeProvider)) {
|
|
21715
22541
|
await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
|
|
21716
22542
|
return await NearSpokeService.callWallet(from, payload, spokeProvider, hubProvider, raw);
|
|
@@ -21719,14 +22545,26 @@ var SpokeService = class _SpokeService {
|
|
|
21719
22545
|
}
|
|
21720
22546
|
static async verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation) {
|
|
21721
22547
|
if (!skipSimulation) {
|
|
22548
|
+
let srcAddress = encodeAddress(
|
|
22549
|
+
spokeProvider.chainConfig.chain.id,
|
|
22550
|
+
await spokeProvider.walletProvider.getWalletAddress()
|
|
22551
|
+
);
|
|
22552
|
+
if (isBitcoinSpokeProvider(spokeProvider)) {
|
|
22553
|
+
if (spokeProvider.walletMode === "TRADING") {
|
|
22554
|
+
const tradingWalletAddress = await spokeProvider.radfi.getTradingWallet(
|
|
22555
|
+
await spokeProvider.walletProvider.getWalletAddress()
|
|
22556
|
+
);
|
|
22557
|
+
srcAddress = encodeAddress(
|
|
22558
|
+
spokeProvider.chainConfig.chain.id,
|
|
22559
|
+
tradingWalletAddress.tradingAddress
|
|
22560
|
+
);
|
|
22561
|
+
}
|
|
22562
|
+
}
|
|
21722
22563
|
const result = await _SpokeService.simulateRecvMessage(
|
|
21723
22564
|
{
|
|
21724
22565
|
target: from,
|
|
21725
22566
|
srcChainId: getIntentRelayChainId(spokeProvider.chainConfig.chain.id),
|
|
21726
|
-
srcAddress
|
|
21727
|
-
spokeProvider.chainConfig.chain.id,
|
|
21728
|
-
await spokeProvider.walletProvider.getWalletAddress()
|
|
21729
|
-
),
|
|
22567
|
+
srcAddress,
|
|
21730
22568
|
payload
|
|
21731
22569
|
},
|
|
21732
22570
|
hubProvider
|
|
@@ -22160,7 +22998,7 @@ var SwapService = class {
|
|
|
22160
22998
|
let dstIntentTxHash;
|
|
22161
22999
|
if (spokeProvider.chainConfig.chain.id !== this.hubProvider.chainConfig.chain.id) {
|
|
22162
23000
|
const intentRelayChainId = getIntentRelayChainId(params.srcChain).toString();
|
|
22163
|
-
const submitPayload = params.srcChain === SOLANA_MAINNET_CHAIN_ID && data ? {
|
|
23001
|
+
const submitPayload = (params.srcChain === SOLANA_MAINNET_CHAIN_ID || params.srcChain === BITCOIN_MAINNET_CHAIN_ID) && data ? {
|
|
22164
23002
|
action: "submit",
|
|
22165
23003
|
params: {
|
|
22166
23004
|
chain_id: intentRelayChainId,
|
|
@@ -22485,17 +23323,51 @@ var SwapService = class {
|
|
|
22485
23323
|
this.configService.isValidSpokeChainId(params.dstChain),
|
|
22486
23324
|
`Invalid spoke chain (params.dstChain): ${params.dstChain}`
|
|
22487
23325
|
);
|
|
23326
|
+
if (params.dstChain === BITCOIN_MAINNET_CHAIN_ID && params.outputToken === "BTC") {
|
|
23327
|
+
invariant6(
|
|
23328
|
+
params.minOutputAmount >= 546n,
|
|
23329
|
+
`Invalid minOutputAmount (params.minOutputAmount): ${params.minOutputAmount}`
|
|
23330
|
+
);
|
|
23331
|
+
}
|
|
22488
23332
|
try {
|
|
22489
|
-
|
|
23333
|
+
console.log("[SwapService.createIntent] start", {
|
|
23334
|
+
srcChain: params.srcChain,
|
|
23335
|
+
dstChain: params.dstChain,
|
|
23336
|
+
inputToken: params.inputToken,
|
|
23337
|
+
inputAmount: params.inputAmount.toString()
|
|
23338
|
+
});
|
|
23339
|
+
let walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
23340
|
+
console.log("[SwapService.createIntent] walletAddress", walletAddress, "srcAddress", params.srcAddress);
|
|
22490
23341
|
invariant6(
|
|
22491
23342
|
params.srcAddress.toLowerCase() === walletAddress.toLowerCase(),
|
|
22492
23343
|
"srcAddress must be the same as wallet address"
|
|
22493
23344
|
);
|
|
23345
|
+
if (isBitcoinSpokeProvider(spokeProvider)) {
|
|
23346
|
+
console.log(
|
|
23347
|
+
"[SwapService.createIntent] Bitcoin detected, walletMode:",
|
|
23348
|
+
spokeProvider.walletMode,
|
|
23349
|
+
"hasToken:",
|
|
23350
|
+
!!spokeProvider.radfiAccessToken
|
|
23351
|
+
);
|
|
23352
|
+
await spokeProvider.ensureRadfiAccessToken();
|
|
23353
|
+
console.log(
|
|
23354
|
+
"[SwapService.createIntent] ensureRadfiAccessToken done, hasToken:",
|
|
23355
|
+
!!spokeProvider.radfiAccessToken
|
|
23356
|
+
);
|
|
23357
|
+
if (spokeProvider.walletMode === "TRADING") {
|
|
23358
|
+
const tradingWalletAddress = await spokeProvider.radfi.getTradingWallet(
|
|
23359
|
+
await spokeProvider.walletProvider.getWalletAddress()
|
|
23360
|
+
);
|
|
23361
|
+
console.log("[SwapService.createIntent] tradingWalletAddress", tradingWalletAddress);
|
|
23362
|
+
walletAddress = tradingWalletAddress.tradingAddress;
|
|
23363
|
+
}
|
|
23364
|
+
}
|
|
22494
23365
|
const creatorHubWalletAddress = await deriveUserWalletAddress(
|
|
22495
23366
|
this.hubProvider,
|
|
22496
23367
|
spokeProvider.chainConfig.chain.id,
|
|
22497
23368
|
walletAddress
|
|
22498
23369
|
);
|
|
23370
|
+
console.log("[SwapService.createIntent] creatorHubWalletAddress", creatorHubWalletAddress);
|
|
22499
23371
|
if (spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id && isSonicSpokeProviderType(spokeProvider)) {
|
|
22500
23372
|
const [txResult, intent, feeAmount, data] = await SonicSpokeService.createSwapIntent(
|
|
22501
23373
|
params,
|
|
@@ -22526,6 +23398,11 @@ var SwapService = class {
|
|
|
22526
23398
|
this.configService,
|
|
22527
23399
|
fee
|
|
22528
23400
|
);
|
|
23401
|
+
console.log("[SwapService.createIntent] intent data constructed", {
|
|
23402
|
+
data,
|
|
23403
|
+
intentId: intent.intentId?.toString()
|
|
23404
|
+
});
|
|
23405
|
+
console.log("[SwapService.createIntent] calling SpokeService.deposit...");
|
|
22529
23406
|
const txResult = await SpokeService.deposit(
|
|
22530
23407
|
{
|
|
22531
23408
|
from: walletAddress,
|
|
@@ -22539,12 +23416,14 @@ var SwapService = class {
|
|
|
22539
23416
|
raw,
|
|
22540
23417
|
skipSimulation
|
|
22541
23418
|
);
|
|
23419
|
+
console.log("[SwapService.createIntent] SpokeService.deposit done, txResult:", txResult);
|
|
22542
23420
|
return {
|
|
22543
23421
|
ok: true,
|
|
22544
23422
|
value: [txResult, { ...intent, feeAmount }, data]
|
|
22545
23423
|
};
|
|
22546
23424
|
}
|
|
22547
23425
|
} catch (error) {
|
|
23426
|
+
console.error("[SwapService.createIntent] FAILED", error);
|
|
22548
23427
|
return {
|
|
22549
23428
|
ok: false,
|
|
22550
23429
|
error: {
|
|
@@ -25603,9 +26482,15 @@ function isNearSpokeProvider(value) {
|
|
|
25603
26482
|
function isStellarSpokeProviderType(value) {
|
|
25604
26483
|
return typeof value === "object" && value !== null && (isStellarSpokeProvider(value) || isStellarRawSpokeProvider(value));
|
|
25605
26484
|
}
|
|
26485
|
+
function isBitcoinSpokeProviderType(value) {
|
|
26486
|
+
return typeof value === "object" && value !== null && (isBitcoinSpokeProvider(value) || isBitcoinRawSpokeProvider(value));
|
|
26487
|
+
}
|
|
25606
26488
|
function isStellarSpokeProvider(value) {
|
|
25607
26489
|
return typeof value === "object" && value !== null && value instanceof StellarSpokeProvider && !("raw" in value) && value.chainConfig.chain.type === "STELLAR";
|
|
25608
26490
|
}
|
|
26491
|
+
function isBitcoinSpokeProvider(value) {
|
|
26492
|
+
return typeof value === "object" && value !== null && value instanceof BitcoinSpokeProvider && !("raw" in value) && value.chainConfig.chain.type === "BITCOIN";
|
|
26493
|
+
}
|
|
25609
26494
|
function isNearSpokeProviderType(value) {
|
|
25610
26495
|
return typeof value === "object" && value !== null && (isNearSpokeProvider(value) || isNearRawSpokeProvider(value));
|
|
25611
26496
|
}
|
|
@@ -25702,6 +26587,9 @@ function isSolanaRawSpokeProvider(value) {
|
|
|
25702
26587
|
function isStellarRawSpokeProvider(value) {
|
|
25703
26588
|
return isRawSpokeProvider(value) && value.chainConfig.chain.type === "STELLAR";
|
|
25704
26589
|
}
|
|
26590
|
+
function isBitcoinRawSpokeProvider(value) {
|
|
26591
|
+
return isRawSpokeProvider(value) && value.chainConfig.chain.type === "BITCOIN";
|
|
26592
|
+
}
|
|
25705
26593
|
function isIconRawSpokeProvider(value) {
|
|
25706
26594
|
return isRawSpokeProvider(value) && value.chainConfig.chain.type === "ICON";
|
|
25707
26595
|
}
|
|
@@ -25810,8 +26698,6 @@ function encodeAddress(spokeChainId, address) {
|
|
|
25810
26698
|
case "0xa4b1.arbitrum":
|
|
25811
26699
|
case "sonic":
|
|
25812
26700
|
return address;
|
|
25813
|
-
case "injective-1":
|
|
25814
|
-
return toHex(Buffer.from(address, "utf-8"));
|
|
25815
26701
|
case "0x1.icon":
|
|
25816
26702
|
return toHex(Buffer.from(address.replace("cx", "01").replace("hx", "00") ?? "f8", "hex"));
|
|
25817
26703
|
case "sui":
|
|
@@ -25820,7 +26706,9 @@ function encodeAddress(spokeChainId, address) {
|
|
|
25820
26706
|
return toHex(Buffer.from(new PublicKey(address).toBytes()));
|
|
25821
26707
|
case "stellar":
|
|
25822
26708
|
return `0x${Address.fromString(address).toScVal().toXDR("hex")}`;
|
|
26709
|
+
case "bitcoin":
|
|
25823
26710
|
case "near":
|
|
26711
|
+
case "injective-1":
|
|
25824
26712
|
return toHex(Buffer.from(address, "utf-8"));
|
|
25825
26713
|
default:
|
|
25826
26714
|
return address;
|
|
@@ -26444,7 +27332,7 @@ var BridgeService = class {
|
|
|
26444
27332
|
}
|
|
26445
27333
|
const packetResult = await relayTxAndWaitPacket(
|
|
26446
27334
|
txResult.value,
|
|
26447
|
-
spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
|
|
27335
|
+
spokeProvider instanceof SolanaSpokeProvider || spokeProvider instanceof BitcoinSpokeProvider ? txResult.data : void 0,
|
|
26448
27336
|
spokeProvider,
|
|
26449
27337
|
this.relayerApiEndpoint,
|
|
26450
27338
|
timeout
|
|
@@ -26517,7 +27405,11 @@ var BridgeService = class {
|
|
|
26517
27405
|
const dstAssetInfo = this.configService.getHubAssetInfo(params.dstChainId, params.dstAsset);
|
|
26518
27406
|
invariant6(srcAssetInfo, `Unsupported spoke chain (${params.srcChainId}) token: ${params.srcAsset}`);
|
|
26519
27407
|
invariant6(dstAssetInfo, `Unsupported spoke chain (${params.dstChainId}) token: ${params.dstAsset}`);
|
|
26520
|
-
|
|
27408
|
+
let walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
27409
|
+
if (spokeProvider instanceof BitcoinSpokeProvider && spokeProvider.walletMode === "TRADING") {
|
|
27410
|
+
const tradingWallet = await spokeProvider.radfi.getTradingWallet(walletAddress);
|
|
27411
|
+
walletAddress = tradingWallet.tradingAddress;
|
|
27412
|
+
}
|
|
26521
27413
|
const hubWallet = await WalletAbstractionService.getUserAbstractedWalletAddress(
|
|
26522
27414
|
walletAddress,
|
|
26523
27415
|
spokeProvider,
|
|
@@ -30048,6 +30940,6 @@ var BalnSwapService = class {
|
|
|
30048
30940
|
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
30049
30941
|
*/
|
|
30050
30942
|
|
|
30051
|
-
export { ARBITRUM_MAINNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, BASE_MAINNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, BackendApiService, BalnSwapService, BigIntToHex, BigNumberZeroDecimal, BnUSDMigrationService, BridgeService, CHAIN_IDS, CONFIG_VERSION, ChainIdToIntentRelayChainId, ChainTypeArr, ConfigService, CustomSorobanServer, CustomStellarAccount, DEFAULT_BACKEND_API_ENDPOINT, DEFAULT_BACKEND_API_HEADERS, DEFAULT_BACKEND_API_TIMEOUT, DEFAULT_DEADLINE_OFFSET, DEFAULT_MAX_RETRY, DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, DEFAULT_RETRY_DELAY_MS, ETHEREUM_MAINNET_CHAIN_ID, EVM_CHAIN_IDS, Erc20Service, EvmAssetManagerService, EvmBaseSpokeProvider, EvmHubProvider, EvmRawSpokeProvider, EvmSolverService, EvmSpokeProvider, EvmSpokeService, EvmVaultTokenService, EvmWalletAbstraction, FEE_PERCENTAGE_SCALE, HALF_RAY, HALF_WAD, HUB_CHAIN_IDS, HYPEREVM_MAINNET_CHAIN_ID, HubService, HubVaultSymbols, ICON_MAINNET_CHAIN_ID, ICON_TX_RESULT_WAIT_MAX_RETRY, INJECTIVE_MAINNET_CHAIN_ID, IconBaseSpokeProvider, IconRawSpokeProvider, IconSpokeProvider, IconSpokeService, IcxMigrationService, Injective20Token, InjectiveBaseSpokeProvider, InjectiveExecuteResponse, InjectiveRawSpokeProvider, InjectiveSpokeProvider, InjectiveSpokeService, IntentCreatedEventAbi, IntentDataType, IntentFilledEventAbi, IntentsAbi, KAIA_MAINNET_CHAIN_ID, LIGHTLINK_MAINNET_CHAIN_ID, LTV_PRECISION, LendingPoolService, LockupMultiplier, LockupPeriod, MAX_UINT256, MigrationService, MoneyMarketDataService, MoneyMarketService, NEAR_MAINNET_CHAIN_ID, NearBaseSpokeProvider, NearRawSpokeProvider, NearSpokeProvider, OPTIMISM_MAINNET_CHAIN_ID, POLYGON_MAINNET_CHAIN_ID, PartnerFeeClaimService, PartnerService, ProtocolIntentsAbi, RAY, RAY_DECIMALS, REDBELLY_MAINNET_CHAIN_ID, SECONDS_PER_YEAR, SOLANA_MAINNET_CHAIN_ID, SONIC_MAINNET_CHAIN_ID, STELLAR_DEFAULT_TX_TIMEOUT_SECONDS, STELLAR_MAINNET_CHAIN_ID, STELLAR_PRIORITY_FEE, SUI_MAINNET_CHAIN_ID, SodaTokens, SodaTokensAsHubAssets, Sodax, SolanaBaseSpokeProvider, SolanaRawSpokeProvider, SolanaSpokeProvider, SolanaSpokeService, SolverApiService, SolverIntentErrorCode, SolverIntentStatusCode, SonicBaseSpokeProvider, SonicRawSpokeProvider, SonicSpokeProvider, SonicSpokeService, SpokeService, StakingLogic, StakingService, StellarBaseSpokeProvider, StellarRawSpokeProvider, StellarSpokeProvider, StellarSpokeService, SuiBaseSpokeProvider, SuiRawSpokeProvider, SuiSpokeProvider, SuiSpokeService, SupportedMigrationTokens, SwapService, USD_DECIMALS, UiPoolDataProviderService, VAULT_TOKEN_DECIMALS, WAD, WAD_RAY_RATIO, WEI_DECIMALS, WalletAbstractionService, adjustAmountByFee, assetManagerAbi, balnSwapAbi, baseChainInfo, binomialApproximatedRayPow, bnUSDLegacySpokeChainIds, bnUSDLegacyTokens, bnUSDNewTokens, calculateAllReserveIncentives, calculateAllUserIncentives, calculateAvailableBorrowsMarketReferenceCurrency, calculateCompoundedInterest, calculateCompoundedRate, calculateFeeAmount, calculateHealthFactorFromBalances, calculateHealthFactorFromBalancesBigUnits, calculateLinearInterest, calculatePercentageFeeAmount, connectionAbi, constructRawSpokeProvider, convertTransactionInstructionToRaw, defaultSharedConfig, defaultSodaxConfig, deriveUserWalletAddress, encodeAddress, encodeContractCalls, erc20Abi, formatBasisPoints, formatEModeCategory, formatEModes, formatPercentage, formatReserve, formatReserveUSD, formatReserves, formatReservesAndIncentives, formatUserSummary, formatUserSummaryAndIncentives, getAllLegacybnUSDTokens, getAndFormatReserveEModes, getCompoundedBalance, getEvmViemChain, getHubChainConfig, getIconAddressBytes, getIntentRelayChainId, getLinearBalance, getMarketReferenceCurrencyAndUsdBalance, getMoneyMarketConfig, getPacket, getRandomBytes, getReserveNormalizedIncome, getReservesEModes, getSolanaAddressBytes, getSolverConfig, getSupportedSolverTokens, getTransactionPackets, hexToBigInt, hexToSolanaAddress, hubAssets, hubChainConfig, hyper, isAddressString, isBalnMigrateParams, isConfiguredMoneyMarketConfig, isConfiguredSolverConfig, isCreateIntentAutoSwapError, isEvmHubChainConfig, isEvmInitializedConfig, isEvmRawSpokeProvider, isEvmRawSpokeProviderConfig, isEvmSpokeChainConfig, isEvmSpokeProvider, isEvmSpokeProviderType, isEvmUninitializedBrowserConfig, isEvmUninitializedConfig, isEvmUninitializedPrivateKeyConfig, isHubSpokeProvider, isIconAddress, isIconRawSpokeProvider, isIconSpokeProvider, isIconSpokeProviderType, isIcxCreateRevertMigrationParams, isIcxMigrateParams, isInjectiveRawSpokeProvider, isInjectiveSpokeProvider, isInjectiveSpokeProviderType, isIntentCreationFailedError, isIntentCreationUnknownError, isIntentPostExecutionFailedError, isIntentRelayChainId, isIntentSubmitTxFailedError, isJsonRpcPayloadResponse, isLegacybnUSDChainId, isLegacybnUSDToken, isMoneyMarketBorrowUnknownError, isMoneyMarketCreateBorrowIntentFailedError, isMoneyMarketCreateRepayIntentFailedError, isMoneyMarketCreateSupplyIntentFailedError, isMoneyMarketCreateWithdrawIntentFailedError, isMoneyMarketRelayTimeoutError, isMoneyMarketRepayUnknownError, isMoneyMarketSubmitTxFailedError, isMoneyMarketSupplyUnknownError, isMoneyMarketWithdrawUnknownError, isNearRawSpokeProvider, isNearRawSpokeProviderConfig, isNearSpokeProvider, isNearSpokeProviderType, isNewbnUSDChainId, isNewbnUSDToken, isPartnerFeeAmount, isPartnerFeePercentage, isRawSpokeProvider, isResponseAddressType, isResponseSigningType, isSetSwapPreferenceError, isSolanaNativeToken, isSolanaRawSpokeProvider, isSolanaRawSpokeProviderConfig, isSolanaSpokeProvider, isSolanaSpokeProviderType, isSolverErrorResponse, isSonicRawSpokeProvider, isSonicRawSpokeProviderConfig, isSonicSpokeProvider, isSonicSpokeProviderType, isStellarRawSpokeProvider, isStellarRawSpokeProviderConfig, isStellarSpokeProvider, isStellarSpokeProviderType, isSuiRawSpokeProvider, isSuiSpokeProvider, isSuiSpokeProviderType, isSwapSupportedToken, isUnifiedBnUSDMigrateParams, isUnknownIntentAutoSwapError, isWaitIntentAutoSwapError, isWaitUntilIntentExecutedFailed, moneyMarketReserveAssets, moneyMarketSupportedTokens, nativeToUSD, newbnUSDSpokeChainIds, normalize, normalizeBN, normalizedToUsd, parseToStroops, parseTokenArrayFromJson, poolAbi, randomUint256, rayDiv, rayMul, rayPow, rayToWad, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, retry, sleep, solverConfig, sonicWalletFactoryAbi, spokeAssetManagerAbi, spokeChainConfig, stakedSodaAbi, stakingRouterAbi, submitTransaction, supportedSpokeChains, swapSupportedTokens, uiPoolDataAbi, valueToBigNumber, valueToZDBigNumber, variableDebtTokenAbi, vaultTokenAbi, wadToRay, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
|
|
30943
|
+
export { ARBITRUM_MAINNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, BASE_MAINNET_CHAIN_ID, BITCOIN_MAINNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, BackendApiService, BalnSwapService, BigIntToHex, BigNumberZeroDecimal, BitcoinBaseSpokeProvider, BitcoinRawSpokeProvider, BitcoinSpokeProvider, BitcoinSpokeService, BnUSDMigrationService, BridgeService, CHAIN_IDS, CONFIG_VERSION, ChainIdToIntentRelayChainId, ChainTypeArr, ConfigService, CustomSorobanServer, CustomStellarAccount, DEFAULT_BACKEND_API_ENDPOINT, DEFAULT_BACKEND_API_HEADERS, DEFAULT_BACKEND_API_TIMEOUT, DEFAULT_DEADLINE_OFFSET, DEFAULT_MAX_RETRY, DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, DEFAULT_RETRY_DELAY_MS, ETHEREUM_MAINNET_CHAIN_ID, EVM_CHAIN_IDS, Erc20Service, EvmAssetManagerService, EvmBaseSpokeProvider, EvmHubProvider, EvmRawSpokeProvider, EvmSolverService, EvmSpokeProvider, EvmSpokeService, EvmVaultTokenService, EvmWalletAbstraction, FEE_PERCENTAGE_SCALE, HALF_RAY, HALF_WAD, HUB_CHAIN_IDS, HYPEREVM_MAINNET_CHAIN_ID, HubService, HubVaultSymbols, ICON_MAINNET_CHAIN_ID, ICON_TX_RESULT_WAIT_MAX_RETRY, INJECTIVE_MAINNET_CHAIN_ID, IconBaseSpokeProvider, IconRawSpokeProvider, IconSpokeProvider, IconSpokeService, IcxMigrationService, Injective20Token, InjectiveBaseSpokeProvider, InjectiveExecuteResponse, InjectiveRawSpokeProvider, InjectiveSpokeProvider, InjectiveSpokeService, IntentCreatedEventAbi, IntentDataType, IntentFilledEventAbi, IntentsAbi, KAIA_MAINNET_CHAIN_ID, LIGHTLINK_MAINNET_CHAIN_ID, LTV_PRECISION, LendingPoolService, LockupMultiplier, LockupPeriod, MAX_UINT256, MigrationService, MoneyMarketDataService, MoneyMarketService, NEAR_MAINNET_CHAIN_ID, NearBaseSpokeProvider, NearRawSpokeProvider, NearSpokeProvider, OPTIMISM_MAINNET_CHAIN_ID, POLYGON_MAINNET_CHAIN_ID, PartnerFeeClaimService, PartnerService, ProtocolIntentsAbi, RAY, RAY_DECIMALS, REDBELLY_MAINNET_CHAIN_ID, RadfiProvider, SECONDS_PER_YEAR, SOLANA_MAINNET_CHAIN_ID, SONIC_MAINNET_CHAIN_ID, STELLAR_DEFAULT_TX_TIMEOUT_SECONDS, STELLAR_MAINNET_CHAIN_ID, STELLAR_PRIORITY_FEE, SUI_MAINNET_CHAIN_ID, SodaTokens, SodaTokensAsHubAssets, Sodax, SolanaBaseSpokeProvider, SolanaRawSpokeProvider, SolanaSpokeProvider, SolanaSpokeService, SolverApiService, SolverIntentErrorCode, SolverIntentStatusCode, SonicBaseSpokeProvider, SonicRawSpokeProvider, SonicSpokeProvider, SonicSpokeService, SpokeService, StakingLogic, StakingService, StellarBaseSpokeProvider, StellarRawSpokeProvider, StellarSpokeProvider, StellarSpokeService, SuiBaseSpokeProvider, SuiRawSpokeProvider, SuiSpokeProvider, SuiSpokeService, SupportedMigrationTokens, SwapService, USD_DECIMALS, UiPoolDataProviderService, VAULT_TOKEN_DECIMALS, WAD, WAD_RAY_RATIO, WEI_DECIMALS, WalletAbstractionService, adjustAmountByFee, assetManagerAbi, balnSwapAbi, baseChainInfo, binomialApproximatedRayPow, bnUSDLegacySpokeChainIds, bnUSDLegacyTokens, bnUSDNewTokens, calculateAllReserveIncentives, calculateAllUserIncentives, calculateAvailableBorrowsMarketReferenceCurrency, calculateCompoundedInterest, calculateCompoundedRate, calculateFeeAmount, calculateHealthFactorFromBalances, calculateHealthFactorFromBalancesBigUnits, calculateLinearInterest, calculatePercentageFeeAmount, connectionAbi, constructRawSpokeProvider, convertTransactionInstructionToRaw, defaultSharedConfig, defaultSodaxConfig, deriveUserWalletAddress, detectBitcoinAddressType, encodeAddress, encodeContractCalls, erc20Abi, formatBasisPoints, formatEModeCategory, formatEModes, formatPercentage, formatReserve, formatReserveUSD, formatReserves, formatReservesAndIncentives, formatUserSummary, formatUserSummaryAndIncentives, getAllLegacybnUSDTokens, getAndFormatReserveEModes, getCompoundedBalance, getEvmViemChain, getHubChainConfig, getIconAddressBytes, getIntentRelayChainId, getLinearBalance, getMarketReferenceCurrencyAndUsdBalance, getMoneyMarketConfig, getPacket, getRandomBytes, getReserveNormalizedIncome, getReservesEModes, getSolanaAddressBytes, getSolverConfig, getSupportedSolverTokens, getTransactionPackets, hexToBigInt, hexToSolanaAddress, hubAssets, hubChainConfig, hyper, isAddressString, isBalnMigrateParams, isBitcoinRawSpokeProvider, isBitcoinSpokeProvider, isBitcoinSpokeProviderType, isConfiguredMoneyMarketConfig, isConfiguredSolverConfig, isCreateIntentAutoSwapError, isEvmHubChainConfig, isEvmInitializedConfig, isEvmRawSpokeProvider, isEvmRawSpokeProviderConfig, isEvmSpokeChainConfig, isEvmSpokeProvider, isEvmSpokeProviderType, isEvmUninitializedBrowserConfig, isEvmUninitializedConfig, isEvmUninitializedPrivateKeyConfig, isHubSpokeProvider, isIconAddress, isIconRawSpokeProvider, isIconSpokeProvider, isIconSpokeProviderType, isIcxCreateRevertMigrationParams, isIcxMigrateParams, isInjectiveRawSpokeProvider, isInjectiveSpokeProvider, isInjectiveSpokeProviderType, isIntentCreationFailedError, isIntentCreationUnknownError, isIntentPostExecutionFailedError, isIntentRelayChainId, isIntentSubmitTxFailedError, isJsonRpcPayloadResponse, isLegacybnUSDChainId, isLegacybnUSDToken, isMoneyMarketBorrowUnknownError, isMoneyMarketCreateBorrowIntentFailedError, isMoneyMarketCreateRepayIntentFailedError, isMoneyMarketCreateSupplyIntentFailedError, isMoneyMarketCreateWithdrawIntentFailedError, isMoneyMarketRelayTimeoutError, isMoneyMarketRepayUnknownError, isMoneyMarketSubmitTxFailedError, isMoneyMarketSupplyUnknownError, isMoneyMarketWithdrawUnknownError, isNearRawSpokeProvider, isNearRawSpokeProviderConfig, isNearSpokeProvider, isNearSpokeProviderType, isNewbnUSDChainId, isNewbnUSDToken, isPartnerFeeAmount, isPartnerFeePercentage, isRawSpokeProvider, isResponseAddressType, isResponseSigningType, isSetSwapPreferenceError, isSolanaNativeToken, isSolanaRawSpokeProvider, isSolanaRawSpokeProviderConfig, isSolanaSpokeProvider, isSolanaSpokeProviderType, isSolverErrorResponse, isSonicRawSpokeProvider, isSonicRawSpokeProviderConfig, isSonicSpokeProvider, isSonicSpokeProviderType, isStellarRawSpokeProvider, isStellarRawSpokeProviderConfig, isStellarSpokeProvider, isStellarSpokeProviderType, isSuiRawSpokeProvider, isSuiSpokeProvider, isSuiSpokeProviderType, isSwapSupportedToken, isUnifiedBnUSDMigrateParams, isUnknownIntentAutoSwapError, isWaitIntentAutoSwapError, isWaitUntilIntentExecutedFailed, moneyMarketReserveAssets, moneyMarketSupportedTokens, nativeToUSD, newbnUSDSpokeChainIds, normalize, normalizeBN, normalizePsbtToBase64, normalizedToUsd, parseToStroops, parseTokenArrayFromJson, poolAbi, randomUint256, rayDiv, rayMul, rayPow, rayToWad, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, retry, sleep, solverConfig, sonicWalletFactoryAbi, spokeAssetManagerAbi, spokeChainConfig, stakedSodaAbi, stakingRouterAbi, submitTransaction, supportedSpokeChains, swapSupportedTokens, uiPoolDataAbi, valueToBigNumber, valueToZDBigNumber, variableDebtTokenAbi, vaultTokenAbi, wadToRay, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
|
|
30052
30944
|
//# sourceMappingURL=index.mjs.map
|
|
30053
30945
|
//# sourceMappingURL=index.mjs.map
|