@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.
@@ -0,0 +1,5 @@
1
+ import ERC20 from "./ERC20.json";
2
+ import XSwapRouter from "./XSwapRouter.json";
3
+
4
+ export const ERC20Abi = ERC20;
5
+ export const XSwapRouterAbi = XSwapRouter;
@@ -0,0 +1 @@
1
+ export * from "./abi";
@@ -0,0 +1,3 @@
1
+ export type ApiOverrides = {
2
+ apiUrl?: string;
3
+ };
@@ -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,4 @@
1
+ export type CoinTypeAddress = {
2
+ coinType: number;
3
+ address: string;
4
+ };
@@ -0,0 +1,4 @@
1
+ export type CollectFees = {
2
+ integratorAddress: string;
3
+ fee: number;
4
+ };
@@ -0,0 +1,10 @@
1
+ import { XSwapCallType } from "./XSwapCallType";
2
+
3
+ export type ContractCall = {
4
+ callType: XSwapCallType;
5
+ target: string;
6
+ value: string;
7
+ callData: string;
8
+ payload: string;
9
+ estimatedGas?: string;
10
+ };
@@ -0,0 +1,3 @@
1
+ export enum Ecosystem {
2
+ EVM = "evm",
3
+ }
@@ -0,0 +1,5 @@
1
+ export enum Environment {
2
+ PROD = "production",
3
+ DEV = "develop",
4
+ LOCAL = "local",
5
+ }
@@ -0,0 +1,6 @@
1
+ export type Protocol = {
2
+ name: string;
3
+ part: number;
4
+ fromTokenAddress: string;
5
+ toTokenAddress: string;
6
+ };
@@ -0,0 +1,10 @@
1
+ export type Referral = {
2
+ address: string;
3
+ code: string;
4
+ referrals: ReferralInfo[];
5
+ };
6
+
7
+ export type ReferralInfo = {
8
+ address: string;
9
+ ipAddress: string;
10
+ };
@@ -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,10 @@
1
+ export type Token = {
2
+ address: string;
3
+ name: string;
4
+ symbol: string;
5
+ decimals: number;
6
+ image: string;
7
+ priority: number;
8
+ quickPick?: boolean;
9
+ supported?: boolean;
10
+ };
@@ -0,0 +1,5 @@
1
+ export enum Web3Environment {
2
+ DEVNET = "devnet",
3
+ TESTNET = "testnet",
4
+ MAINNET = "mainnet",
5
+ }
@@ -0,0 +1,6 @@
1
+ export enum XSwapCallType {
2
+ DEFAULT = 0,
3
+ FULL_TOKEN_BALANCE = 1,
4
+ FULL_NATIVE_BALANCE = 2,
5
+ COLLECT_TOKEN_BALANCE = 3,
6
+ }
@@ -0,0 +1,4 @@
1
+ export type XSwapFee = {
2
+ tokenFee: string;
3
+ nativeFee: string;
4
+ };
@@ -0,0 +1,7 @@
1
+ import { XSwapFee } from "./XSwapFee";
2
+
3
+ export type XSwapFees = {
4
+ ccipFee: string;
5
+ xSwapFee: XSwapFee;
6
+ expressDeliveryFee: string;
7
+ };
@@ -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,4 @@
1
+ export type AddReferralPayload = {
2
+ code: string;
3
+ address: string;
4
+ };
@@ -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
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./GetRoutePayload";
2
+ export * from "./AddReferralPayload";
@@ -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 "@xswap-link/common";
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
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./bigNumbers";
2
+ export * from "./contracts";