@xswap-link/sdk 0.0.4 → 0.0.6
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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +321 -3
- package/dist/index.d.ts +321 -3
- package/dist/index.js +1558 -6
- package/dist/index.mjs +1543 -6
- package/index.ts +4 -1
- package/package.json +10 -9
- package/src/constants/index.ts +7 -0
- package/src/contracts/abi/ERC20.json +222 -0
- package/src/contracts/abi/XSwapRouter.json +1242 -0
- package/src/contracts/abi/index.ts +5 -0
- package/src/contracts/index.ts +1 -0
- package/src/models/ApiOverrides.ts +3 -0
- package/src/models/Chain.ts +14 -0
- package/src/models/CoinTypeAddress.ts +4 -0
- package/src/models/CollectFees.ts +4 -0
- package/src/models/ContractCall.ts +10 -0
- package/src/models/Ecosystem.ts +3 -0
- package/src/models/Environment.ts +5 -0
- package/src/models/Protocol.ts +6 -0
- package/src/models/Referral.ts +10 -0
- package/src/models/Route.ts +24 -0
- package/src/models/Token.ts +10 -0
- package/src/models/Web3Environment.ts +5 -0
- package/src/models/XSwapCallType.ts +6 -0
- package/src/models/XSwapFee.ts +4 -0
- package/src/models/XSwapFees.ts +7 -0
- package/src/models/index.ts +16 -0
- package/src/models/payloads/AddReferralPayload.ts +4 -0
- package/src/models/payloads/GetRoutePayload.ts +24 -0
- package/src/models/payloads/index.ts +2 -0
- package/src/services/api.ts +3 -5
- package/src/utils/bigNumbers.ts +7 -0
- package/src/utils/contracts.ts +19 -0
- package/src/utils/index.ts +2 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./abi";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Web3Environment } from "./Web3Environment";
|
|
2
|
+
import { Token } from "./Token";
|
|
3
|
+
|
|
4
|
+
export type Chain = {
|
|
5
|
+
ecosystem: string;
|
|
6
|
+
chainId: string;
|
|
7
|
+
name: string;
|
|
8
|
+
displayName: string;
|
|
9
|
+
web3Environment: Web3Environment;
|
|
10
|
+
transactionExplorer: string;
|
|
11
|
+
rpcUrls?: Array<string>;
|
|
12
|
+
ccipChainId: string;
|
|
13
|
+
tokens: Token[];
|
|
14
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BigNumberish } from "ethers";
|
|
2
|
+
import { TransactionRequest } from "@ethersproject/providers";
|
|
3
|
+
import { ContractCall } from "./ContractCall";
|
|
4
|
+
import { XSwapFees } from "./XSwapFees";
|
|
5
|
+
import { Protocol } from "./Protocol";
|
|
6
|
+
|
|
7
|
+
export type Route = {
|
|
8
|
+
originChainXSwapCalls: ContractCall[];
|
|
9
|
+
originProtocols: Protocol[][][];
|
|
10
|
+
destinationChainXSwapCalls: ContractCall[];
|
|
11
|
+
destinationProtocols: Protocol[][][];
|
|
12
|
+
originCrossChainTransferToken: string;
|
|
13
|
+
destinationCrossChainTransferToken: string;
|
|
14
|
+
amountToTransferCrossChain: BigNumberish;
|
|
15
|
+
estAmountOut: string;
|
|
16
|
+
minAmountOut: string;
|
|
17
|
+
estimatedGasDestination: number;
|
|
18
|
+
transactions: {
|
|
19
|
+
approve: TransactionRequest;
|
|
20
|
+
swap: TransactionRequest;
|
|
21
|
+
};
|
|
22
|
+
xSwapFees: XSwapFees;
|
|
23
|
+
message?: string;
|
|
24
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "./ApiOverrides";
|
|
2
|
+
export * from "./Chain";
|
|
3
|
+
export * from "./CoinTypeAddress";
|
|
4
|
+
export * from "./CollectFees";
|
|
5
|
+
export * from "./ContractCall";
|
|
6
|
+
export * from "./Ecosystem";
|
|
7
|
+
export * from "./Environment";
|
|
8
|
+
export * from "./payloads";
|
|
9
|
+
export * from "./Protocol";
|
|
10
|
+
export * from "./Route";
|
|
11
|
+
export * from "./Token";
|
|
12
|
+
export * from "./Web3Environment";
|
|
13
|
+
export * from "./XSwapCallType";
|
|
14
|
+
export * from "./XSwapFee";
|
|
15
|
+
export * from "./XSwapFees";
|
|
16
|
+
export * from "./Referral";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CoinTypeAddress } from "../CoinTypeAddress";
|
|
2
|
+
import { CollectFees } from "../CollectFees";
|
|
3
|
+
import { ContractCall } from "../ContractCall";
|
|
4
|
+
|
|
5
|
+
export type GetRoutePayload = {
|
|
6
|
+
fromChain: string;
|
|
7
|
+
toChain: string;
|
|
8
|
+
fromToken: string;
|
|
9
|
+
toToken: string;
|
|
10
|
+
fromAmount: string;
|
|
11
|
+
fromAddress: string;
|
|
12
|
+
toAddress: string;
|
|
13
|
+
paymentToken: string;
|
|
14
|
+
slippage: number;
|
|
15
|
+
expressDelivery: boolean;
|
|
16
|
+
quoteOnly?: boolean;
|
|
17
|
+
enableExpress?: boolean;
|
|
18
|
+
customContractCalls?: ContractCall[];
|
|
19
|
+
sourceChainDexes?: string[];
|
|
20
|
+
destinationChainDexes?: string[];
|
|
21
|
+
receiveGasOnDestination?: boolean;
|
|
22
|
+
collectFees?: CollectFees;
|
|
23
|
+
fallbackAddresses?: CoinTypeAddress[];
|
|
24
|
+
};
|
package/src/services/api.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ApiOverrides,
|
|
2
3
|
Chain,
|
|
3
|
-
DEFAULT_API_URL,
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
|
-
DEFAULT_ECOSYSTEM,
|
|
6
4
|
Ecosystem,
|
|
7
5
|
GetRoutePayload,
|
|
8
|
-
ApiOverrides,
|
|
9
6
|
Route,
|
|
10
7
|
Token,
|
|
11
|
-
} from "
|
|
8
|
+
} from "../models";
|
|
9
|
+
import { DEFAULT_API_URL } from "../constants";
|
|
12
10
|
|
|
13
11
|
async function _sendRequest<T>(
|
|
14
12
|
urlPath: string,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BigNumber as BigNumberJS } from "bignumber.js";
|
|
2
|
+
import { BigNumber } from "ethers";
|
|
3
|
+
|
|
4
|
+
export const safeBigNumberFrom = (value: string) => {
|
|
5
|
+
BigNumberJS.config({ DECIMAL_PLACES: 0 });
|
|
6
|
+
return BigNumber.from(new BigNumberJS(value).div(1).toFixed());
|
|
7
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BigNumberish, ethers } from "ethers";
|
|
2
|
+
import { ERC20Abi } from "../contracts";
|
|
3
|
+
import { safeBigNumberFrom } from "./bigNumbers";
|
|
4
|
+
|
|
5
|
+
const erc20Interface = new ethers.utils.Interface(ERC20Abi);
|
|
6
|
+
|
|
7
|
+
export const generateApproveTxData = (
|
|
8
|
+
tokenAddress: string,
|
|
9
|
+
spender: string,
|
|
10
|
+
amount: BigNumberish
|
|
11
|
+
) => {
|
|
12
|
+
const data = erc20Interface.encodeFunctionData("approve", [spender, amount]);
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
to: tokenAddress,
|
|
16
|
+
value: safeBigNumberFrom("0"),
|
|
17
|
+
data,
|
|
18
|
+
};
|
|
19
|
+
};
|