-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathsimple.ts
44 lines (37 loc) · 1.09 KB
/
simple.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* eslint-disable @typescript-eslint/no-unused-vars */
import axios from 'axios';
import { ethers, Wallet } from 'ethersV5';
import {
constructSimpleSDK,
ContractMethod,
SwapSide,
SimpleSDKProviderOptions,
} from '..';
const provider = ethers.getDefaultProvider(1);
const signer = Wallet.createRandom().connect(provider);
// only methods that fetch from API
const simpleFetchOnlySDK = constructSimpleSDK({ chainId: 1, axios });
const DAI_TOKEN = '0x6b175474e89094c44da98b954eedeac495271d0f';
const PSP_TOKEN = '0xcafe001067cdef266afb7eb5a286dcfd277f3de5';
const account = signer.address;
// type Promise<OptimalRate>
const rateRes = simpleFetchOnlySDK.swap.getRate({
srcToken: DAI_TOKEN,
destToken: PSP_TOKEN,
amount: '1000000000000',
userAddress: account,
side: SwapSide.SELL,
});
const providerOptions: SimpleSDKProviderOptions = {
ethersProviderOrSigner: signer,
EthersContract: ethers.Contract,
account,
};
const SDKwithApprove = constructSimpleSDK(
{ chainId: 1, axios },
providerOptions
);
const approveTxHash = SDKwithApprove.swap.approveToken(
'1000000000000',
DAI_TOKEN
);