@stableflow/bridges 3.0.3 → 3.1.0-rc-d2d5e08ec7-20260706
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.d.mts +148 -11
- package/dist/index.d.ts +148 -11
- package/dist/index.js +366 -44
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +365 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Big from 'big.js';
|
|
2
|
-
import { usdt0Chains, usdcChains, frxusdChains, Service, ExecTime, OpenAPI, getRequest, Csl, numberRemoveEndZero, getPrice, SendType, DefaultAddresses, postRequest, tokens, ServiceBackend, TransactionStatus, StableflowStatus, LayerZeroStatus, OneClickStatus, getRouteStatus } from '@stableflow/core';
|
|
2
|
+
import { usdt0Chains, usdcChains, frxusdChains, Service, ExecTime, OpenAPI, getRequest, Csl, numberRemoveEndZero, getPrice, SendType, DefaultAddresses, postRequest, erc20Abi, tokens, ServiceBackend, TransactionStatus, StableflowStatus, LayerZeroStatus, OneClickStatus, getRouteStatus } from '@stableflow/core';
|
|
3
3
|
import bs58 from 'bs58';
|
|
4
4
|
import { Buffer } from 'buffer';
|
|
5
5
|
import { evmRpcFallbackProvider } from '@stableflow/utils-evm';
|
|
@@ -182,6 +182,7 @@ var OneClickService = class {
|
|
|
182
182
|
appFees = [],
|
|
183
183
|
swapType = "EXACT_INPUT",
|
|
184
184
|
isProxy = true,
|
|
185
|
+
slippageTolerance,
|
|
185
186
|
...restParams
|
|
186
187
|
} = params;
|
|
187
188
|
const _quoteType = `OneClickService ${fromToken?.chainName}->${toToken?.chainName}`;
|
|
@@ -199,7 +200,8 @@ var OneClickService = class {
|
|
|
199
200
|
...appFees
|
|
200
201
|
],
|
|
201
202
|
referral: "stableflow",
|
|
202
|
-
amount: amountWei
|
|
203
|
+
amount: amountWei,
|
|
204
|
+
slippageTolerance: slippageTolerance * 100
|
|
203
205
|
};
|
|
204
206
|
if (swapType === "EXACT_OUTPUT") {
|
|
205
207
|
quoteParams.amount = Big(amountWei || 0).div(10 ** fromToken.decimals).times(10 ** toToken.decimals).toFixed(0);
|
|
@@ -4839,6 +4841,7 @@ var FraxZero2OneClickService = class extends FraxZeroService {
|
|
|
4839
4841
|
refundTo: middleChainRecipientAddress,
|
|
4840
4842
|
wallet: middleChainWallet,
|
|
4841
4843
|
appFees: [
|
|
4844
|
+
...params.appFees || [],
|
|
4842
4845
|
{
|
|
4843
4846
|
recipient: "reffer.near",
|
|
4844
4847
|
// No bridge fee will be charged temporarily
|
|
@@ -5058,6 +5061,7 @@ var OneClick2FraxZeroService = class extends FraxZeroService {
|
|
|
5058
5061
|
isProxy: true,
|
|
5059
5062
|
recipient: middleChainRecipientAddress,
|
|
5060
5063
|
appFees: [
|
|
5064
|
+
...params.appFees || [],
|
|
5061
5065
|
{
|
|
5062
5066
|
recipient: "reffer.near",
|
|
5063
5067
|
// No bridge fee will be charged temporarily
|
|
@@ -5413,6 +5417,7 @@ var OneClickUsdt0Service = class {
|
|
|
5413
5417
|
isProxy: true,
|
|
5414
5418
|
recipient: middleChainRecipientAddress,
|
|
5415
5419
|
appFees: [
|
|
5420
|
+
...params.appFees || [],
|
|
5416
5421
|
{
|
|
5417
5422
|
recipient: "reffer.near",
|
|
5418
5423
|
// No bridge fee will be charged temporarily
|
|
@@ -5660,11 +5665,228 @@ var ServiceMap = {
|
|
|
5660
5665
|
[Service.OneClickUsdt0]: from_oneclick_default2,
|
|
5661
5666
|
[Service.Native]: native_default
|
|
5662
5667
|
};
|
|
5668
|
+
var OVERRIDE_KEYS = /* @__PURE__ */ new Set([
|
|
5669
|
+
"value",
|
|
5670
|
+
"gasLimit",
|
|
5671
|
+
"gasPrice",
|
|
5672
|
+
"maxFeePerGas",
|
|
5673
|
+
"maxPriorityFeePerGas",
|
|
5674
|
+
"nonce",
|
|
5675
|
+
"from",
|
|
5676
|
+
"type",
|
|
5677
|
+
"accessList",
|
|
5678
|
+
"chainId",
|
|
5679
|
+
"customData",
|
|
5680
|
+
"blockTag"
|
|
5681
|
+
]);
|
|
5682
|
+
var toDecimalString = (v) => {
|
|
5683
|
+
if (v === void 0 || v === null) {
|
|
5684
|
+
return "0";
|
|
5685
|
+
}
|
|
5686
|
+
if (typeof v === "bigint") {
|
|
5687
|
+
return v.toString();
|
|
5688
|
+
}
|
|
5689
|
+
if (typeof v === "number") {
|
|
5690
|
+
return Math.trunc(v).toString();
|
|
5691
|
+
}
|
|
5692
|
+
return String(v);
|
|
5693
|
+
};
|
|
5694
|
+
var assertEvm = (token) => {
|
|
5695
|
+
if (!token || token.chainType !== "evm") {
|
|
5696
|
+
throw new Error("API-driven custody currently supports EVM chains only");
|
|
5697
|
+
}
|
|
5698
|
+
};
|
|
5699
|
+
var getSendAmountWei = (serviceType, quote) => {
|
|
5700
|
+
const { isExactOutput } = getQuoteModes({
|
|
5701
|
+
quoteData: quote,
|
|
5702
|
+
bridgeStore: { quoteDataService: serviceType }
|
|
5703
|
+
});
|
|
5704
|
+
if (isExactOutput) {
|
|
5705
|
+
return quote?.quote?.minAmountIn;
|
|
5706
|
+
}
|
|
5707
|
+
return quote?.quoteParam?.amountWei;
|
|
5708
|
+
};
|
|
5709
|
+
var encodeContractCall = (sendParam) => {
|
|
5710
|
+
const { contract, method, param } = sendParam;
|
|
5711
|
+
if (!contract?.interface || contract?.target === void 0) {
|
|
5712
|
+
throw new Error("Invalid sendParam: missing contract interface/target");
|
|
5713
|
+
}
|
|
5714
|
+
const to = typeof contract.target === "string" ? contract.target : String(contract.target);
|
|
5715
|
+
let args = Array.isArray(param) ? param : [];
|
|
5716
|
+
let value;
|
|
5717
|
+
let gasLimit;
|
|
5718
|
+
if (args.length > 0) {
|
|
5719
|
+
const last = args[args.length - 1];
|
|
5720
|
+
const isOverride = last !== null && typeof last === "object" && !Array.isArray(last) && Object.keys(last).length > 0 && Object.keys(last).every((k) => OVERRIDE_KEYS.has(k));
|
|
5721
|
+
if (isOverride) {
|
|
5722
|
+
args = args.slice(0, -1);
|
|
5723
|
+
value = last.value;
|
|
5724
|
+
gasLimit = last.gasLimit;
|
|
5725
|
+
}
|
|
5726
|
+
}
|
|
5727
|
+
const data = contract.interface.encodeFunctionData(method, args);
|
|
5728
|
+
return {
|
|
5729
|
+
to,
|
|
5730
|
+
data,
|
|
5731
|
+
value: toDecimalString(value),
|
|
5732
|
+
gasLimit: gasLimit === void 0 || gasLimit === null ? void 0 : toDecimalString(gasLimit)
|
|
5733
|
+
};
|
|
5734
|
+
};
|
|
5735
|
+
var buildTransferTx = (params) => {
|
|
5736
|
+
const { chainId, from, fromToken, depositAddress, amountWei } = params;
|
|
5737
|
+
if (!depositAddress) {
|
|
5738
|
+
throw new Error("Quote has no depositAddress to build transfer transaction");
|
|
5739
|
+
}
|
|
5740
|
+
if (fromToken.contractAddress === "eth") {
|
|
5741
|
+
return {
|
|
5742
|
+
chainId,
|
|
5743
|
+
from,
|
|
5744
|
+
to: depositAddress,
|
|
5745
|
+
data: "0x",
|
|
5746
|
+
value: toDecimalString(amountWei)
|
|
5747
|
+
};
|
|
5748
|
+
}
|
|
5749
|
+
const iface = new ethers.Interface(erc20Abi);
|
|
5750
|
+
const data = iface.encodeFunctionData("transfer", [depositAddress, amountWei]);
|
|
5751
|
+
return {
|
|
5752
|
+
chainId,
|
|
5753
|
+
from,
|
|
5754
|
+
to: fromToken.contractAddress,
|
|
5755
|
+
data,
|
|
5756
|
+
value: "0"
|
|
5757
|
+
};
|
|
5758
|
+
};
|
|
5759
|
+
var buildSendTx = (serviceType, quote) => {
|
|
5760
|
+
const fromToken = quote?.quoteParam?.fromToken;
|
|
5761
|
+
assertEvm(fromToken);
|
|
5762
|
+
const chainId = fromToken.chainId;
|
|
5763
|
+
const from = quote?.quoteParam?.refundTo;
|
|
5764
|
+
const sendParam = quote?.sendParam;
|
|
5765
|
+
if (sendParam?.txRequest) {
|
|
5766
|
+
const txRequest = sendParam.txRequest;
|
|
5767
|
+
return {
|
|
5768
|
+
chainId,
|
|
5769
|
+
from,
|
|
5770
|
+
to: txRequest.target,
|
|
5771
|
+
data: txRequest.calldata,
|
|
5772
|
+
value: toDecimalString(txRequest.value),
|
|
5773
|
+
gasLimit: txRequest.gasLimit === void 0 || txRequest.gasLimit === null ? void 0 : toDecimalString(txRequest.gasLimit)
|
|
5774
|
+
};
|
|
5775
|
+
}
|
|
5776
|
+
const { isOneClickService } = getQuoteModes({
|
|
5777
|
+
quoteData: quote,
|
|
5778
|
+
bridgeStore: { quoteDataService: serviceType }
|
|
5779
|
+
});
|
|
5780
|
+
if (isOneClickService) {
|
|
5781
|
+
if (sendParam) {
|
|
5782
|
+
return { chainId, from, ...encodeContractCall(sendParam) };
|
|
5783
|
+
}
|
|
5784
|
+
return buildTransferTx({
|
|
5785
|
+
chainId,
|
|
5786
|
+
from,
|
|
5787
|
+
fromToken,
|
|
5788
|
+
depositAddress: quote?.quote?.depositAddress,
|
|
5789
|
+
amountWei: getSendAmountWei(serviceType, quote)
|
|
5790
|
+
});
|
|
5791
|
+
}
|
|
5792
|
+
if (!sendParam) {
|
|
5793
|
+
throw new Error("Quote has no sendParam to build transaction");
|
|
5794
|
+
}
|
|
5795
|
+
return { chainId, from, ...encodeContractCall(sendParam) };
|
|
5796
|
+
};
|
|
5797
|
+
var buildApproveTx = (serviceType, quote) => {
|
|
5798
|
+
if (!quote?.needApprove) {
|
|
5799
|
+
return {};
|
|
5800
|
+
}
|
|
5801
|
+
const fromToken = quote?.quoteParam?.fromToken;
|
|
5802
|
+
assertEvm(fromToken);
|
|
5803
|
+
if (fromToken.contractAddress === "eth") {
|
|
5804
|
+
return {};
|
|
5805
|
+
}
|
|
5806
|
+
const chainId = fromToken.chainId;
|
|
5807
|
+
const from = quote?.quoteParam?.refundTo;
|
|
5808
|
+
const spender = quote?.approveSpender;
|
|
5809
|
+
if (!spender) {
|
|
5810
|
+
throw new Error("Quote requires approval but has no approveSpender");
|
|
5811
|
+
}
|
|
5812
|
+
const amountWei = getSendAmountWei(serviceType, quote);
|
|
5813
|
+
const iface = new ethers.Interface(erc20Abi);
|
|
5814
|
+
const approveTx = {
|
|
5815
|
+
chainId,
|
|
5816
|
+
from,
|
|
5817
|
+
to: fromToken.contractAddress,
|
|
5818
|
+
data: iface.encodeFunctionData("approve", [spender, amountWei]),
|
|
5819
|
+
value: "0"
|
|
5820
|
+
};
|
|
5821
|
+
const result = { approveTx };
|
|
5822
|
+
if (fromToken.chainName === "Ethereum") {
|
|
5823
|
+
result.approveResetTx = {
|
|
5824
|
+
chainId,
|
|
5825
|
+
from,
|
|
5826
|
+
to: fromToken.contractAddress,
|
|
5827
|
+
data: iface.encodeFunctionData("approve", [spender, "0"]),
|
|
5828
|
+
value: "0"
|
|
5829
|
+
};
|
|
5830
|
+
}
|
|
5831
|
+
return result;
|
|
5832
|
+
};
|
|
5833
|
+
var buildPermitTypedData = async (params) => {
|
|
5834
|
+
const { permitToken, permitAmountWei, permitSpender, owner } = params;
|
|
5835
|
+
assertEvm(permitToken);
|
|
5836
|
+
if (!owner) {
|
|
5837
|
+
throw new Error("buildPermitTypedData requires the permit owner address");
|
|
5838
|
+
}
|
|
5839
|
+
const provider = evmRpcFallbackProvider(permitToken);
|
|
5840
|
+
const erc20 = new ethers.Contract(permitToken.contractAddress, erc20Abi, provider);
|
|
5841
|
+
const [nonce, name] = await Promise.all([
|
|
5842
|
+
erc20.nonces(owner),
|
|
5843
|
+
erc20.name()
|
|
5844
|
+
]);
|
|
5845
|
+
const version = permitToken.symbol === "USDC" ? "2" : "1";
|
|
5846
|
+
const deadline = Math.floor(Date.now() / 1e3) + 60 * 60 * 24 * 3;
|
|
5847
|
+
const domain = {
|
|
5848
|
+
name,
|
|
5849
|
+
version,
|
|
5850
|
+
chainId: Number(permitToken.chainId),
|
|
5851
|
+
verifyingContract: permitToken.contractAddress
|
|
5852
|
+
};
|
|
5853
|
+
const types = {
|
|
5854
|
+
Permit: [
|
|
5855
|
+
{ name: "owner", type: "address" },
|
|
5856
|
+
{ name: "spender", type: "address" },
|
|
5857
|
+
{ name: "value", type: "uint256" },
|
|
5858
|
+
{ name: "nonce", type: "uint256" },
|
|
5859
|
+
{ name: "deadline", type: "uint256" }
|
|
5860
|
+
]
|
|
5861
|
+
};
|
|
5862
|
+
const values = {
|
|
5863
|
+
owner,
|
|
5864
|
+
spender: permitSpender,
|
|
5865
|
+
value: toDecimalString(permitAmountWei),
|
|
5866
|
+
nonce: nonce.toString(),
|
|
5867
|
+
deadline
|
|
5868
|
+
};
|
|
5869
|
+
return {
|
|
5870
|
+
domain,
|
|
5871
|
+
types,
|
|
5872
|
+
values,
|
|
5873
|
+
deadline,
|
|
5874
|
+
nonce: Number(nonce),
|
|
5875
|
+
token: permitToken.contractAddress,
|
|
5876
|
+
spender: permitSpender,
|
|
5877
|
+
owner
|
|
5878
|
+
};
|
|
5879
|
+
};
|
|
5880
|
+
|
|
5881
|
+
// src/sfa.ts
|
|
5663
5882
|
var submitOthersTx = (requestBody) => {
|
|
5664
5883
|
return postRequest("/v0/trade/add", requestBody);
|
|
5665
5884
|
};
|
|
5666
|
-
var BridgeSFA = class {
|
|
5885
|
+
var BridgeSFA = class _BridgeSFA {
|
|
5667
5886
|
static async getAllQuote(params) {
|
|
5887
|
+
const cs = new Csl(OpenAPI.DEBUG);
|
|
5888
|
+
const csl = cs.log;
|
|
5889
|
+
csl("BridgeSFA.getAllQuote", "blue-400", "params: %o", params);
|
|
5668
5890
|
const results = [];
|
|
5669
5891
|
let { minInputAmount = "1", disabledServices } = params;
|
|
5670
5892
|
if (Big(minInputAmount).lte(0)) {
|
|
@@ -5694,7 +5916,6 @@ var BridgeSFA = class {
|
|
|
5694
5916
|
Service.FraxZeroOneClick,
|
|
5695
5917
|
Service.OneClickFraxZero
|
|
5696
5918
|
].includes(service)) {
|
|
5697
|
-
_params.slippageTolerance = params.slippageTolerance * 100;
|
|
5698
5919
|
_params.originAsset = params.fromToken.assetId;
|
|
5699
5920
|
_params.destinationAsset = params.toToken.assetId;
|
|
5700
5921
|
_params.refundType = "ORIGIN_CHAIN";
|
|
@@ -5727,6 +5948,7 @@ var BridgeSFA = class {
|
|
|
5727
5948
|
return;
|
|
5728
5949
|
}
|
|
5729
5950
|
const quoteParams = formatQuoteParams(_service);
|
|
5951
|
+
csl("BridgeSFA.getAllQuote", "blue-400", "%s quoteParams: %o", _service, quoteParams);
|
|
5730
5952
|
quoteServices.push({
|
|
5731
5953
|
service: _service,
|
|
5732
5954
|
quote: () => {
|
|
@@ -5779,6 +6001,7 @@ var BridgeSFA = class {
|
|
|
5779
6001
|
}
|
|
5780
6002
|
return results;
|
|
5781
6003
|
}
|
|
6004
|
+
csl("BridgeSFA.getAllQuote", "blue-400", "quoteServices: %o", quoteServices);
|
|
5782
6005
|
const promises = [];
|
|
5783
6006
|
for (const quoteService of quoteServices) {
|
|
5784
6007
|
const promise = (async () => {
|
|
@@ -5820,12 +6043,11 @@ var BridgeSFA = class {
|
|
|
5820
6043
|
const sendParams = {
|
|
5821
6044
|
wallet
|
|
5822
6045
|
};
|
|
5823
|
-
const { isExactOutput, isOneClickService
|
|
6046
|
+
const { isExactOutput, isOneClickService } = getQuoteModes({
|
|
5824
6047
|
quoteData: quote,
|
|
5825
6048
|
bridgeStore: { quoteDataService: serviceType }
|
|
5826
6049
|
});
|
|
5827
6050
|
const fromToken = quote.quoteParam.fromToken;
|
|
5828
|
-
const toToken = quote.quoteParam.toToken;
|
|
5829
6051
|
const depositAddress = quote.quote?.depositAddress;
|
|
5830
6052
|
const sendParam = quote.sendParam;
|
|
5831
6053
|
let _amountWei = quote.quoteParam?.amountWei;
|
|
@@ -5845,45 +6067,11 @@ var BridgeSFA = class {
|
|
|
5845
6067
|
csl("BridgeSFA.send", "blue-400", "sendParams: %o", sendParams);
|
|
5846
6068
|
const txhash = await service.send(sendParams);
|
|
5847
6069
|
try {
|
|
5848
|
-
const reportData = {
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
|
-
|
|
5853
|
-
deposit_address: isOneClickService ? quote.quote?.depositAddress : "",
|
|
5854
|
-
receive_address: quote.quoteParam?.recipient,
|
|
5855
|
-
from_chain: fromToken.blockchain,
|
|
5856
|
-
symbol: /^USD₮0$/i.test(fromToken.symbol) ? "USDT" : fromToken.symbol,
|
|
5857
|
-
to_chain: toToken.blockchain,
|
|
5858
|
-
to_symbol: /^USD₮0$/i.test(toToken.symbol) ? "USDT" : toToken.symbol,
|
|
5859
|
-
tx_hash: ""
|
|
5860
|
-
};
|
|
5861
|
-
if (permitSignature) {
|
|
5862
|
-
if ([Service.OneClickUsdt0].includes(serviceType)) {
|
|
5863
|
-
reportData.layer_zero_permit = {
|
|
5864
|
-
...permitSignature,
|
|
5865
|
-
...quote.permitAdditionalData
|
|
5866
|
-
};
|
|
5867
|
-
}
|
|
5868
|
-
if ([Service.OneClickFraxZero, Service.FraxZeroOneClick].includes(serviceType)) {
|
|
5869
|
-
reportData.frax_zero_permit = {
|
|
5870
|
-
...permitSignature,
|
|
5871
|
-
...quote.permitAdditionalData
|
|
5872
|
-
};
|
|
5873
|
-
}
|
|
5874
|
-
}
|
|
5875
|
-
reportData.tx_hash = txhash;
|
|
5876
|
-
let _depositAddress = txhash;
|
|
5877
|
-
if (isQuoteParamDepositAddress) {
|
|
5878
|
-
_depositAddress = quote.quoteParam?.depositAddress || txhash;
|
|
5879
|
-
}
|
|
5880
|
-
if (!reportData.deposit_address) {
|
|
5881
|
-
reportData.deposit_address = _depositAddress;
|
|
5882
|
-
}
|
|
5883
|
-
if (serviceType === Service.Native) {
|
|
5884
|
-
const quoteIds = quote?.orders?.map?.((order) => order.quoteId) || [];
|
|
5885
|
-
reportData.quoteIds = quoteIds;
|
|
5886
|
-
}
|
|
6070
|
+
const reportData = _BridgeSFA.buildReportData(serviceType, {
|
|
6071
|
+
quote,
|
|
6072
|
+
txhash,
|
|
6073
|
+
permitSignature
|
|
6074
|
+
});
|
|
5887
6075
|
csl("BridgeSFA.send", "blue-400", "reportData: %o", reportData);
|
|
5888
6076
|
submitOthersTx(reportData);
|
|
5889
6077
|
} catch (error) {
|
|
@@ -5891,6 +6079,137 @@ var BridgeSFA = class {
|
|
|
5891
6079
|
}
|
|
5892
6080
|
return txhash;
|
|
5893
6081
|
}
|
|
6082
|
+
/**
|
|
6083
|
+
* Build the backend report payload for a submitted source-chain transaction.
|
|
6084
|
+
* Shared by `send` (fire-and-forget) and `report` (awaited).
|
|
6085
|
+
*/
|
|
6086
|
+
static buildReportData(serviceType, params) {
|
|
6087
|
+
const { quote, txhash, permitSignature } = params;
|
|
6088
|
+
const { isExactOutput, isOneClickService, isQuoteParamDepositAddress } = getQuoteModes({
|
|
6089
|
+
quoteData: quote,
|
|
6090
|
+
bridgeStore: { quoteDataService: serviceType }
|
|
6091
|
+
});
|
|
6092
|
+
const fromToken = quote.quoteParam.fromToken;
|
|
6093
|
+
const toToken = quote.quoteParam.toToken;
|
|
6094
|
+
let _amountWei = quote.quoteParam?.amountWei;
|
|
6095
|
+
if (isExactOutput) {
|
|
6096
|
+
_amountWei = quote.quote?.minAmountIn;
|
|
6097
|
+
}
|
|
6098
|
+
const reportData = {
|
|
6099
|
+
project: ServiceBackend[serviceType],
|
|
6100
|
+
address: quote.quoteParam?.refundTo,
|
|
6101
|
+
amount: isExactOutput ? quote.quote.amountInFormatted : Big(_amountWei || 0).div(10 ** (fromToken?.decimals || 6)).toFixed(fromToken?.decimals || 6, 0),
|
|
6102
|
+
out_amount: quote.outputAmount,
|
|
6103
|
+
deposit_address: isOneClickService ? quote.quote?.depositAddress : "",
|
|
6104
|
+
receive_address: quote.quoteParam?.recipient,
|
|
6105
|
+
from_chain: fromToken.blockchain,
|
|
6106
|
+
symbol: /^USD₮0$/i.test(fromToken.symbol) ? "USDT" : fromToken.symbol,
|
|
6107
|
+
to_chain: toToken.blockchain,
|
|
6108
|
+
to_symbol: /^USD₮0$/i.test(toToken.symbol) ? "USDT" : toToken.symbol,
|
|
6109
|
+
tx_hash: ""
|
|
6110
|
+
};
|
|
6111
|
+
if (permitSignature) {
|
|
6112
|
+
if ([Service.OneClickUsdt0].includes(serviceType)) {
|
|
6113
|
+
reportData.layer_zero_permit = {
|
|
6114
|
+
...permitSignature,
|
|
6115
|
+
...quote.permitAdditionalData
|
|
6116
|
+
};
|
|
6117
|
+
}
|
|
6118
|
+
if ([Service.OneClickFraxZero, Service.FraxZeroOneClick].includes(serviceType)) {
|
|
6119
|
+
reportData.frax_zero_permit = {
|
|
6120
|
+
...permitSignature,
|
|
6121
|
+
...quote.permitAdditionalData
|
|
6122
|
+
};
|
|
6123
|
+
}
|
|
6124
|
+
}
|
|
6125
|
+
reportData.tx_hash = txhash;
|
|
6126
|
+
let _depositAddress = txhash;
|
|
6127
|
+
if (isQuoteParamDepositAddress) {
|
|
6128
|
+
_depositAddress = quote.quoteParam?.depositAddress || txhash;
|
|
6129
|
+
}
|
|
6130
|
+
if (!reportData.deposit_address) {
|
|
6131
|
+
reportData.deposit_address = _depositAddress;
|
|
6132
|
+
}
|
|
6133
|
+
if (serviceType === Service.Native) {
|
|
6134
|
+
const quoteIds = quote?.orders?.map?.((order) => order.quoteId) || [];
|
|
6135
|
+
reportData.quoteIds = quoteIds;
|
|
6136
|
+
}
|
|
6137
|
+
return reportData;
|
|
6138
|
+
}
|
|
6139
|
+
/**
|
|
6140
|
+
* API-driven custody: build the serializable, unsigned transaction data for a
|
|
6141
|
+
* route WITHOUT a signer. Intended for MPC wallets (e.g. Fireblocks) that sign
|
|
6142
|
+
* and broadcast through their own infrastructure.
|
|
6143
|
+
*
|
|
6144
|
+
* Returns any required `approveTx` (and `approveResetTx` on Ethereum), the
|
|
6145
|
+
* `permitTypedData` to sign off-chain when `quote.needPermit`, and the main
|
|
6146
|
+
* `tx`. After the integrator broadcasts `tx`, call `BridgeSFA.report` with the
|
|
6147
|
+
* resulting hash (and the permit signature, if any) so StableFlow can execute
|
|
6148
|
+
* the destination leg.
|
|
6149
|
+
*
|
|
6150
|
+
* EVM only for now; non-EVM source chains throw.
|
|
6151
|
+
*/
|
|
6152
|
+
static async buildTransaction(serviceType, params) {
|
|
6153
|
+
const service = ServiceMap[serviceType];
|
|
6154
|
+
if (!service) {
|
|
6155
|
+
throw new Error(`Invalid service type: ${serviceType}`);
|
|
6156
|
+
}
|
|
6157
|
+
const { quote } = params;
|
|
6158
|
+
if (!quote) {
|
|
6159
|
+
throw new Error("Quote data is required");
|
|
6160
|
+
}
|
|
6161
|
+
const tx = buildSendTx(serviceType, quote);
|
|
6162
|
+
const { approveTx, approveResetTx } = buildApproveTx(serviceType, quote);
|
|
6163
|
+
const result = {
|
|
6164
|
+
chainId: tx.chainId,
|
|
6165
|
+
from: tx.from,
|
|
6166
|
+
tx
|
|
6167
|
+
};
|
|
6168
|
+
if (approveTx) {
|
|
6169
|
+
result.approveTx = approveTx;
|
|
6170
|
+
}
|
|
6171
|
+
if (approveResetTx) {
|
|
6172
|
+
result.approveResetTx = approveResetTx;
|
|
6173
|
+
}
|
|
6174
|
+
if (quote.needPermit) {
|
|
6175
|
+
result.permitTypedData = await buildPermitTypedData({
|
|
6176
|
+
permitToken: quote.permitToken,
|
|
6177
|
+
permitAmountWei: quote.permitAmountWei,
|
|
6178
|
+
permitSpender: quote.permitSpender,
|
|
6179
|
+
owner: quote.quoteParam?.evmAddress || quote.quoteParam?.refundTo
|
|
6180
|
+
});
|
|
6181
|
+
}
|
|
6182
|
+
return result;
|
|
6183
|
+
}
|
|
6184
|
+
/**
|
|
6185
|
+
* API-driven custody: report an externally signed & broadcast source-chain
|
|
6186
|
+
* transaction back to StableFlow so it can track and execute the destination
|
|
6187
|
+
* leg. Pair with `BridgeSFA.buildTransaction`.
|
|
6188
|
+
*
|
|
6189
|
+
* When `quote.needPermit === true`, `permitSignature` is required.
|
|
6190
|
+
*/
|
|
6191
|
+
static report(serviceType, params) {
|
|
6192
|
+
const service = ServiceMap[serviceType];
|
|
6193
|
+
if (!service) {
|
|
6194
|
+
throw new Error(`Invalid service type: ${serviceType}`);
|
|
6195
|
+
}
|
|
6196
|
+
const { quote, hash, permitSignature } = params;
|
|
6197
|
+
if (!quote) {
|
|
6198
|
+
throw new Error("Quote data is required");
|
|
6199
|
+
}
|
|
6200
|
+
if (!hash) {
|
|
6201
|
+
throw new Error("Transaction hash is required");
|
|
6202
|
+
}
|
|
6203
|
+
if (quote.needPermit && !permitSignature) {
|
|
6204
|
+
throw new Error("Permit signature is required");
|
|
6205
|
+
}
|
|
6206
|
+
const reportData = _BridgeSFA.buildReportData(serviceType, {
|
|
6207
|
+
quote,
|
|
6208
|
+
txhash: hash,
|
|
6209
|
+
permitSignature
|
|
6210
|
+
});
|
|
6211
|
+
return submitOthersTx(reportData);
|
|
6212
|
+
}
|
|
5894
6213
|
static async getStatus(serviceType, params) {
|
|
5895
6214
|
const cs = new Csl(OpenAPI.DEBUG);
|
|
5896
6215
|
const csl = cs.log;
|
|
@@ -5998,6 +6317,6 @@ var getHopMsgFee = async (params) => {
|
|
|
5998
6317
|
}
|
|
5999
6318
|
};
|
|
6000
6319
|
|
|
6001
|
-
export { BridgeSFA, DATA_HEX_PROTOBUF_EXTRA, FRAXZERO_MIDDLE_TOKEN_FRXUSD, FRAXZERO_MIDDLE_TOKEN_USDC, LZ_RECEIVE_VALUE, OFT_ABI, SIGNATURE_SIZE, ServiceMap, USDT0_CONFIG, USDT0_LEGACY_MESH_TRANSFTER_FEE, addressToBytes32, formatNumber, formatQuoteError, getHopMsgFee, getQuoteModes, quoteSignature };
|
|
6320
|
+
export { BridgeSFA, DATA_HEX_PROTOBUF_EXTRA, FRAXZERO_MIDDLE_TOKEN_FRXUSD, FRAXZERO_MIDDLE_TOKEN_USDC, LZ_RECEIVE_VALUE, OFT_ABI, SIGNATURE_SIZE, ServiceMap, USDT0_CONFIG, USDT0_LEGACY_MESH_TRANSFTER_FEE, addressToBytes32, buildApproveTx, buildPermitTypedData, buildSendTx, formatNumber, formatQuoteError, getHopMsgFee, getQuoteModes, quoteSignature };
|
|
6002
6321
|
//# sourceMappingURL=index.mjs.map
|
|
6003
6322
|
//# sourceMappingURL=index.mjs.map
|