@sodax/sdk 0.0.1-rc.19 → 0.0.1-rc.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.cjs +180 -101
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +151 -93
- package/dist/index.d.ts +151 -93
- package/dist/index.mjs +180 -101
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -12425,7 +12425,7 @@ var SolverService = class {
|
|
|
12425
12425
|
* const fee: bigint = await solverService.getFee(1000000000000000n);
|
|
12426
12426
|
* console.log('Fee:', fee);
|
|
12427
12427
|
*/
|
|
12428
|
-
|
|
12428
|
+
getFee(inputAmount) {
|
|
12429
12429
|
if (!this.config.partnerFee) {
|
|
12430
12430
|
return 0n;
|
|
12431
12431
|
}
|
|
@@ -12535,29 +12535,37 @@ var SolverService = class {
|
|
|
12535
12535
|
}
|
|
12536
12536
|
}
|
|
12537
12537
|
/**
|
|
12538
|
-
*
|
|
12539
|
-
* @param {CreateIntentParams} payload - The intent to create
|
|
12540
|
-
* @param {ISpokeProvider} spokeProvider - The spoke provider
|
|
12541
|
-
* @param {number} timeout - The timeout in milliseconds for the transaction. Default is 60 seconds.
|
|
12542
|
-
* @returns {Promise<Result<[SolverExecutionResponse, Intent, PacketData], IntentError<IntentErrorCode>>>} The solver execution response, intent, and packet data
|
|
12538
|
+
* Syntactic sugar for createAndSubmitIntent: creates an intent and submits it to the Solver API and Relayer API.
|
|
12543
12539
|
*
|
|
12544
|
-
* @
|
|
12545
|
-
*
|
|
12546
|
-
*
|
|
12547
|
-
*
|
|
12548
|
-
*
|
|
12549
|
-
*
|
|
12550
|
-
*
|
|
12551
|
-
*
|
|
12552
|
-
* "srcChain": "0x38.bsc", // Chain ID where input tokens originate
|
|
12553
|
-
* "dstChain": "0xa4b1.arbitrum", // Chain ID where output tokens should be delivered
|
|
12554
|
-
* "srcAddress": "0x..", // Source address (original address on spoke chain)
|
|
12555
|
-
* "dstAddress": "0x...", // Destination address (original address on spoke chain)
|
|
12556
|
-
* "solver": "0x..", // Optional specific solver address (address(0) = any solver)
|
|
12557
|
-
* "data": "0x..", // Additional arbitrary data
|
|
12558
|
-
* } satisfies CreateIntentParams;
|
|
12540
|
+
* @param {Prettify<SwapParams<S> & OptionalTimeout>} params - Object containing:
|
|
12541
|
+
* - intentParams: The parameters for creating the intent.
|
|
12542
|
+
* - spokeProvider: The spoke provider instance.
|
|
12543
|
+
* - fee: (Optional) Partner fee configuration.
|
|
12544
|
+
* - timeout: (Optional) Timeout in milliseconds for the transaction (default: 60 seconds).
|
|
12545
|
+
* @returns {Promise<Result<[SolverExecutionResponse, Intent, Hex], IntentError<IntentErrorCode>>>}
|
|
12546
|
+
* A promise resolving to a Result containing a tuple of SolverExecutionResponse, Intent, and packet data (Hex),
|
|
12547
|
+
* or an IntentError if the operation fails.
|
|
12559
12548
|
*
|
|
12560
|
-
*
|
|
12549
|
+
* @example
|
|
12550
|
+
* const swapResult = await solverService.swap({
|
|
12551
|
+
* intentParams: {
|
|
12552
|
+
* inputToken: "0x2170Ed0880ac9A755fd29B2688956BD959F933F8",
|
|
12553
|
+
* outputToken: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f",
|
|
12554
|
+
* inputAmount: 1000000000000000n,
|
|
12555
|
+
* minOutputAmount: 900000000000000n,
|
|
12556
|
+
* deadline: 0n,
|
|
12557
|
+
* allowPartialFill: false,
|
|
12558
|
+
* srcChain: "0x38.bsc",
|
|
12559
|
+
* dstChain: "0xa4b1.arbitrum",
|
|
12560
|
+
* srcAddress: "0x..",
|
|
12561
|
+
* dstAddress: "0x...",
|
|
12562
|
+
* solver: "0x..",
|
|
12563
|
+
* data: "0x..",
|
|
12564
|
+
* },
|
|
12565
|
+
* spokeProvider,
|
|
12566
|
+
* fee, // optional
|
|
12567
|
+
* timeout, // optional
|
|
12568
|
+
* });
|
|
12561
12569
|
*
|
|
12562
12570
|
* if (swapResult.ok) {
|
|
12563
12571
|
* const [solverExecutionResponse, intent, packetData] = swapResult.value;
|
|
@@ -12568,33 +12576,51 @@ var SolverService = class {
|
|
|
12568
12576
|
* // handle error
|
|
12569
12577
|
* }
|
|
12570
12578
|
*/
|
|
12571
|
-
async swap(
|
|
12572
|
-
|
|
12579
|
+
async swap({
|
|
12580
|
+
intentParams: params,
|
|
12581
|
+
spokeProvider,
|
|
12582
|
+
fee = this.config.partnerFee,
|
|
12583
|
+
timeout = DEFAULT_RELAY_TX_TIMEOUT
|
|
12584
|
+
}) {
|
|
12585
|
+
return this.createAndSubmitIntent({
|
|
12586
|
+
intentParams: params,
|
|
12587
|
+
spokeProvider,
|
|
12588
|
+
fee,
|
|
12589
|
+
timeout
|
|
12590
|
+
});
|
|
12573
12591
|
}
|
|
12574
12592
|
/**
|
|
12575
12593
|
* Creates an intent and submits it to the Solver API and Relayer API
|
|
12576
|
-
* @param {
|
|
12577
|
-
*
|
|
12578
|
-
*
|
|
12579
|
-
*
|
|
12594
|
+
* @param {Prettify<SwapParams<S> & OptionalTimeout>} params - Object containing:
|
|
12595
|
+
* - intentParams: The parameters for creating the intent.
|
|
12596
|
+
* - spokeProvider: The spoke provider instance.
|
|
12597
|
+
* - fee: (Optional) Partner fee configuration.
|
|
12598
|
+
* - timeout: (Optional) Timeout in milliseconds for the transaction (default: 60 seconds).
|
|
12599
|
+
* @returns {Promise<Result<[SolverExecutionResponse, Intent, Hex], IntentError<IntentErrorCode>>>}
|
|
12600
|
+
* A promise resolving to a Result containing a tuple of SolverExecutionResponse, Intent, and packet data (Hex),
|
|
12601
|
+
* or an IntentError if the operation fails.
|
|
12580
12602
|
*
|
|
12581
12603
|
* @example
|
|
12582
|
-
* const
|
|
12583
|
-
*
|
|
12584
|
-
*
|
|
12585
|
-
* "
|
|
12586
|
-
*
|
|
12587
|
-
*
|
|
12588
|
-
*
|
|
12589
|
-
*
|
|
12590
|
-
*
|
|
12591
|
-
*
|
|
12592
|
-
*
|
|
12593
|
-
*
|
|
12594
|
-
*
|
|
12595
|
-
*
|
|
12604
|
+
* const createAndSubmitIntentResult = await solverService.createAndSubmitIntent({
|
|
12605
|
+
* intentParams: {
|
|
12606
|
+
* inputToken: "0x2170Ed0880ac9A755fd29B2688956BD959F933F8",
|
|
12607
|
+
* outputToken: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f",
|
|
12608
|
+
* inputAmount: 1000000000000000n,
|
|
12609
|
+
* minOutputAmount: 900000000000000n,
|
|
12610
|
+
* deadline: 0n,
|
|
12611
|
+
* allowPartialFill: false,
|
|
12612
|
+
* srcChain: "0x38.bsc",
|
|
12613
|
+
* dstChain: "0xa4b1.arbitrum",
|
|
12614
|
+
* srcAddress: "0x..",
|
|
12615
|
+
* dstAddress: "0x...",
|
|
12616
|
+
* solver: "0x..",
|
|
12617
|
+
* data: "0x..",
|
|
12618
|
+
* },
|
|
12619
|
+
* spokeProvider,
|
|
12620
|
+
* fee, // optional
|
|
12621
|
+
* timeout, // optional
|
|
12622
|
+
* });
|
|
12596
12623
|
*
|
|
12597
|
-
* const createAndSubmitIntentResult = await solverService.createAndSubmitIntent(payload, spokeProvider);
|
|
12598
12624
|
*
|
|
12599
12625
|
* if (createAndSubmitIntentResult.ok) {
|
|
12600
12626
|
* const [solverExecutionResponse, intent, packetData] = createAndSubmitIntentResult.value;
|
|
@@ -12605,17 +12631,27 @@ var SolverService = class {
|
|
|
12605
12631
|
* // handle error
|
|
12606
12632
|
* }
|
|
12607
12633
|
*/
|
|
12608
|
-
async createAndSubmitIntent(
|
|
12634
|
+
async createAndSubmitIntent({
|
|
12635
|
+
intentParams: params,
|
|
12636
|
+
spokeProvider,
|
|
12637
|
+
fee = this.config.partnerFee,
|
|
12638
|
+
timeout = DEFAULT_RELAY_TX_TIMEOUT
|
|
12639
|
+
}) {
|
|
12609
12640
|
try {
|
|
12610
|
-
const createIntentResult = await this.createIntent(
|
|
12641
|
+
const createIntentResult = await this.createIntent({
|
|
12642
|
+
intentParams: params,
|
|
12643
|
+
spokeProvider,
|
|
12644
|
+
fee,
|
|
12645
|
+
raw: false
|
|
12646
|
+
});
|
|
12611
12647
|
if (!createIntentResult.ok) {
|
|
12612
12648
|
return createIntentResult;
|
|
12613
12649
|
}
|
|
12614
12650
|
const [spokeTxHash, intent, data] = createIntentResult.value;
|
|
12615
12651
|
let intentTxHash = null;
|
|
12616
12652
|
if (spokeProvider.chainConfig.chain.id !== SONIC_MAINNET_CHAIN_ID) {
|
|
12617
|
-
const intentRelayChainId = getIntentRelayChainId(
|
|
12618
|
-
const submitPayload =
|
|
12653
|
+
const intentRelayChainId = getIntentRelayChainId(params.srcChain).toString();
|
|
12654
|
+
const submitPayload = params.srcChain === SOLANA_MAINNET_CHAIN_ID && data ? {
|
|
12619
12655
|
action: "submit",
|
|
12620
12656
|
params: {
|
|
12621
12657
|
chain_id: intentRelayChainId,
|
|
@@ -12674,7 +12710,7 @@ var SolverService = class {
|
|
|
12674
12710
|
error: {
|
|
12675
12711
|
code: "UNKNOWN",
|
|
12676
12712
|
data: {
|
|
12677
|
-
payload,
|
|
12713
|
+
payload: params,
|
|
12678
12714
|
error
|
|
12679
12715
|
}
|
|
12680
12716
|
}
|
|
@@ -12682,44 +12718,53 @@ var SolverService = class {
|
|
|
12682
12718
|
}
|
|
12683
12719
|
}
|
|
12684
12720
|
/**
|
|
12685
|
-
* Check whether
|
|
12686
|
-
* @param {
|
|
12687
|
-
*
|
|
12688
|
-
*
|
|
12721
|
+
* Check whether the Asset Manager contract is allowed to spend the specified amount of tokens
|
|
12722
|
+
* @param {Prettify<SwapParams<S>} params - Object containing:
|
|
12723
|
+
* - intentParams: The parameters for creating the intent.
|
|
12724
|
+
* - spokeProvider: The spoke provider instance.
|
|
12725
|
+
* - fee: (Optional) Partner fee configuration.
|
|
12726
|
+
* @returns {Promise<Result<boolean>>} - Returns true if allowance is sufficient, false if approval is needed
|
|
12689
12727
|
*
|
|
12690
12728
|
* @example
|
|
12691
|
-
* const
|
|
12692
|
-
*
|
|
12693
|
-
*
|
|
12694
|
-
*
|
|
12695
|
-
*
|
|
12696
|
-
*
|
|
12697
|
-
*
|
|
12698
|
-
*
|
|
12699
|
-
*
|
|
12700
|
-
*
|
|
12701
|
-
*
|
|
12702
|
-
*
|
|
12703
|
-
*
|
|
12729
|
+
* const createIntentParams = {
|
|
12730
|
+
* inputToken: '0x2170Ed0880ac9A755fd29B2688956BD959F933F8', // BSC ETH token address
|
|
12731
|
+
* outputToken: '0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f', // ARB WBTC token address
|
|
12732
|
+
* inputAmount: 1000000000000000n, // The amount of input tokens
|
|
12733
|
+
* minOutputAmount: 900000000000000n, // min amount you are expecting to receive
|
|
12734
|
+
* deadline: 0n, // Optional timestamp after which intent expires (0 = no deadline)
|
|
12735
|
+
* allowPartialFill: false, // Whether the intent can be partially filled
|
|
12736
|
+
* srcChain: BSC_MAINNET_CHAIN_ID, // Chain ID where input tokens originate
|
|
12737
|
+
* dstChain: ARBITRUM_MAINNET_CHAIN_ID, // Chain ID where output tokens should be delivered
|
|
12738
|
+
* srcAddress: '0x..', // Source address (original address on spoke chain)
|
|
12739
|
+
* dstAddress: '0x...', // Destination address (original address on spoke chain)
|
|
12740
|
+
* solver: '0x0000000000000000000000000000000000000000', // Optional specific solver address
|
|
12741
|
+
* data: '0x', // Additional arbitrary data
|
|
12704
12742
|
* } satisfies CreateIntentParams;
|
|
12705
12743
|
*
|
|
12706
|
-
* const isAllowanceValid = await
|
|
12744
|
+
* const isAllowanceValid = await sodax.solver.isAllowanceValid({
|
|
12745
|
+
* intentParams: createIntentParams,
|
|
12746
|
+
* spokeProvider: bscSpokeProvider,
|
|
12747
|
+
* });
|
|
12707
12748
|
*
|
|
12708
|
-
* if (!
|
|
12749
|
+
* if (!isAllowanceValid.ok) {
|
|
12709
12750
|
* // Handle error
|
|
12710
|
-
*
|
|
12711
|
-
*
|
|
12712
|
-
*
|
|
12713
|
-
*
|
|
12751
|
+
* console.error('Failed to check allowance:', isAllowanceValid.error);
|
|
12752
|
+
* } else if (!isAllowanceValid.value) {
|
|
12753
|
+
* // Need to approve tokens
|
|
12754
|
+
* console.log('Approval required');
|
|
12714
12755
|
* }
|
|
12715
12756
|
*/
|
|
12716
|
-
async isAllowanceValid(
|
|
12757
|
+
async isAllowanceValid({
|
|
12758
|
+
intentParams: params,
|
|
12759
|
+
spokeProvider,
|
|
12760
|
+
fee = this.config.partnerFee
|
|
12761
|
+
}) {
|
|
12717
12762
|
try {
|
|
12718
12763
|
if (spokeProvider instanceof EvmSpokeProvider || spokeProvider instanceof SonicSpokeProvider) {
|
|
12719
12764
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
12720
|
-
return Erc20Service.isAllowanceValid(
|
|
12765
|
+
return await Erc20Service.isAllowanceValid(
|
|
12721
12766
|
params.inputToken,
|
|
12722
|
-
params.inputAmount,
|
|
12767
|
+
params.inputAmount + calculateFeeAmount(params.inputAmount, fee),
|
|
12723
12768
|
walletAddress,
|
|
12724
12769
|
spokeProvider instanceof EvmSpokeProvider ? spokeProvider.chainConfig.addresses.assetManager : spokeProvider.chainConfig.addresses.walletRouter,
|
|
12725
12770
|
spokeProvider
|
|
@@ -12737,35 +12782,55 @@ var SolverService = class {
|
|
|
12737
12782
|
}
|
|
12738
12783
|
}
|
|
12739
12784
|
/**
|
|
12740
|
-
* Approve
|
|
12741
|
-
* @param
|
|
12742
|
-
*
|
|
12743
|
-
*
|
|
12744
|
-
*
|
|
12745
|
-
*
|
|
12746
|
-
* @returns {Promise<Result<TxReturnType<S, R>>>} - Returns
|
|
12785
|
+
* Approve the Asset Manager contract to spend tokens on behalf of the user (required for EVM chains)
|
|
12786
|
+
* @param {Prettify<SwapParams<S> & OptionalRaw<R>>} params - Object containing:
|
|
12787
|
+
* - intentParams: The parameters for creating the intent.
|
|
12788
|
+
* - spokeProvider: The spoke provider instance.
|
|
12789
|
+
* - fee: (Optional) Partner fee configuration.
|
|
12790
|
+
* - raw: (Optional) Whether to return the raw transaction data instead of executing it
|
|
12791
|
+
* @returns {Promise<Result<TxReturnType<S, R>>>} - Returns transaction hash or raw transaction data
|
|
12747
12792
|
*
|
|
12748
12793
|
* @example
|
|
12749
|
-
* const
|
|
12750
|
-
* '
|
|
12751
|
-
*
|
|
12752
|
-
*
|
|
12753
|
-
*
|
|
12754
|
-
*
|
|
12755
|
-
*
|
|
12794
|
+
* const createIntentParams = {
|
|
12795
|
+
* inputToken: '0x2170Ed0880ac9A755fd29B2688956BD959F933F8', // BSC ETH token address
|
|
12796
|
+
* outputToken: '0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f', // ARB WBTC token address
|
|
12797
|
+
* inputAmount: 1000000000000000n, // The amount of input tokens
|
|
12798
|
+
* minOutputAmount: 900000000000000n, // min amount you are expecting to receive
|
|
12799
|
+
* deadline: 0n, // Optional timestamp after which intent expires (0 = no deadline)
|
|
12800
|
+
* allowPartialFill: false, // Whether the intent can be partially filled
|
|
12801
|
+
* srcChain: BSC_MAINNET_CHAIN_ID, // Chain ID where input tokens originate
|
|
12802
|
+
* dstChain: ARBITRUM_MAINNET_CHAIN_ID, // Chain ID where output tokens should be delivered
|
|
12803
|
+
* srcAddress: '0x..', // Source address (original address on spoke chain)
|
|
12804
|
+
* dstAddress: '0x...', // Destination address (original address on spoke chain)
|
|
12805
|
+
* solver: '0x0000000000000000000000000000000000000000', // Optional specific solver address
|
|
12806
|
+
* data: '0x', // Additional arbitrary data
|
|
12807
|
+
* } satisfies CreateIntentParams;
|
|
12808
|
+
*
|
|
12809
|
+
* const approveResult = await sodax.solver.approve({
|
|
12810
|
+
* intentParams: createIntentParams,
|
|
12811
|
+
* spokeProvider: bscSpokeProvider,
|
|
12812
|
+
* });
|
|
12756
12813
|
*
|
|
12757
12814
|
* if (!approveResult.ok) {
|
|
12758
12815
|
* // Handle error
|
|
12816
|
+
* console.error('Failed to approve tokens:', approveResult.error);
|
|
12817
|
+
* } else {
|
|
12818
|
+
* // Transaction hash or raw transaction data
|
|
12819
|
+
* const txHash = approveResult.value;
|
|
12820
|
+
* console.log('Approval transaction:', txHash);
|
|
12759
12821
|
* }
|
|
12760
|
-
*
|
|
12761
|
-
* const txReceipt = approveResult.value;
|
|
12762
12822
|
*/
|
|
12763
|
-
async approve(
|
|
12823
|
+
async approve({
|
|
12824
|
+
intentParams: params,
|
|
12825
|
+
spokeProvider,
|
|
12826
|
+
fee = this.config.partnerFee,
|
|
12827
|
+
raw
|
|
12828
|
+
}) {
|
|
12764
12829
|
try {
|
|
12765
12830
|
if (spokeProvider instanceof EvmSpokeProvider || spokeProvider instanceof SonicSpokeProvider) {
|
|
12766
12831
|
const result = await Erc20Service.approve(
|
|
12767
|
-
|
|
12768
|
-
|
|
12832
|
+
params.inputToken,
|
|
12833
|
+
params.inputAmount + calculateFeeAmount(params.inputAmount, fee),
|
|
12769
12834
|
spokeProvider.chainConfig.addresses.assetManager,
|
|
12770
12835
|
spokeProvider,
|
|
12771
12836
|
raw
|
|
@@ -12789,11 +12854,12 @@ var SolverService = class {
|
|
|
12789
12854
|
/**
|
|
12790
12855
|
* Creates an intent by handling token approval and intent creation
|
|
12791
12856
|
* NOTE: This method does not submit the intent to the Solver API
|
|
12792
|
-
* @param {
|
|
12793
|
-
*
|
|
12794
|
-
*
|
|
12795
|
-
*
|
|
12796
|
-
*
|
|
12857
|
+
* @param {Prettify<SwapParams<S> & OptionalRaw<R>>} params - Object containing:
|
|
12858
|
+
* - intentParams: The parameters for creating the intent.
|
|
12859
|
+
* - spokeProvider: The spoke provider instance.
|
|
12860
|
+
* - fee: (Optional) Partner fee configuration.
|
|
12861
|
+
* - raw: (Optional) Whether to return the raw transaction data instead of executing it
|
|
12862
|
+
* @returns {Promise<Result<[TxReturnType<S, R>, Intent & FeeAmount], IntentError<'CREATION_FAILED'>>>} The encoded contract call or raw transaction data
|
|
12797
12863
|
*
|
|
12798
12864
|
* @example
|
|
12799
12865
|
* const payload = {
|
|
@@ -12811,14 +12877,27 @@ var SolverService = class {
|
|
|
12811
12877
|
* "data": "0x..", // Additional arbitrary data
|
|
12812
12878
|
* } satisfies CreateIntentParams;
|
|
12813
12879
|
*
|
|
12814
|
-
* const createIntentResult = await solverService.createIntent(
|
|
12880
|
+
* const createIntentResult = await solverService.createIntent({
|
|
12881
|
+
* intentParams: payload,
|
|
12882
|
+
* spokeProvider,
|
|
12883
|
+
* fee, // optional
|
|
12884
|
+
* raw, // optional
|
|
12885
|
+
* });
|
|
12815
12886
|
*
|
|
12816
12887
|
* if (createIntentResult.ok) {
|
|
12817
12888
|
* const [txResult, intent] = createIntentResult.value;
|
|
12818
12889
|
* console.log('Intent:', intent);
|
|
12819
|
-
*
|
|
12890
|
+
* console.log('Packet data:', packetData);
|
|
12891
|
+
* } else {
|
|
12892
|
+
* // handle error
|
|
12893
|
+
* }
|
|
12820
12894
|
*/
|
|
12821
|
-
async createIntent(
|
|
12895
|
+
async createIntent({
|
|
12896
|
+
intentParams: params,
|
|
12897
|
+
spokeProvider,
|
|
12898
|
+
fee = this.config.partnerFee,
|
|
12899
|
+
raw
|
|
12900
|
+
}) {
|
|
12822
12901
|
invariant2(
|
|
12823
12902
|
isValidOriginalAssetAddress(params.srcChain, params.inputToken),
|
|
12824
12903
|
`Unsupported spoke chain token (params.srcChain): ${params.srcChain}, params.inputToken): ${params.inputToken}`
|