Skip to content

Commit 24391f4

Browse files
authored
Merge pull request #3080 from DFXswiss/develop
Release: develop -> main
2 parents f042bf5 + a8d1118 commit 24391f4

11 files changed

Lines changed: 455 additions & 39 deletions

File tree

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
[
2+
{
3+
"inputs": [
4+
{
5+
"components": [
6+
{ "internalType": "uint32", "name": "dstEid", "type": "uint32" },
7+
{ "internalType": "bytes32", "name": "to", "type": "bytes32" },
8+
{ "internalType": "uint256", "name": "amountLD", "type": "uint256" },
9+
{ "internalType": "uint256", "name": "minAmountLD", "type": "uint256" },
10+
{ "internalType": "bytes", "name": "extraOptions", "type": "bytes" },
11+
{ "internalType": "bytes", "name": "composeMsg", "type": "bytes" },
12+
{ "internalType": "bytes", "name": "oftCmd", "type": "bytes" }
13+
],
14+
"internalType": "struct SendParam",
15+
"name": "_sendParam",
16+
"type": "tuple"
17+
},
18+
{ "internalType": "bool", "name": "_payInLzToken", "type": "bool" }
19+
],
20+
"name": "quoteSend",
21+
"outputs": [
22+
{
23+
"components": [
24+
{ "internalType": "uint256", "name": "nativeFee", "type": "uint256" },
25+
{ "internalType": "uint256", "name": "lzTokenFee", "type": "uint256" }
26+
],
27+
"internalType": "struct MessagingFee",
28+
"name": "msgFee",
29+
"type": "tuple"
30+
}
31+
],
32+
"stateMutability": "view",
33+
"type": "function"
34+
},
35+
{
36+
"inputs": [
37+
{
38+
"components": [
39+
{ "internalType": "uint32", "name": "dstEid", "type": "uint32" },
40+
{ "internalType": "bytes32", "name": "to", "type": "bytes32" },
41+
{ "internalType": "uint256", "name": "amountLD", "type": "uint256" },
42+
{ "internalType": "uint256", "name": "minAmountLD", "type": "uint256" },
43+
{ "internalType": "bytes", "name": "extraOptions", "type": "bytes" },
44+
{ "internalType": "bytes", "name": "composeMsg", "type": "bytes" },
45+
{ "internalType": "bytes", "name": "oftCmd", "type": "bytes" }
46+
],
47+
"internalType": "struct SendParam",
48+
"name": "_sendParam",
49+
"type": "tuple"
50+
},
51+
{
52+
"components": [
53+
{ "internalType": "uint256", "name": "nativeFee", "type": "uint256" },
54+
{ "internalType": "uint256", "name": "lzTokenFee", "type": "uint256" }
55+
],
56+
"internalType": "struct MessagingFee",
57+
"name": "_fee",
58+
"type": "tuple"
59+
},
60+
{ "internalType": "address", "name": "_refundAddress", "type": "address" }
61+
],
62+
"name": "send",
63+
"outputs": [
64+
{
65+
"components": [
66+
{ "internalType": "bytes32", "name": "guid", "type": "bytes32" },
67+
{ "internalType": "uint64", "name": "nonce", "type": "uint64" },
68+
{
69+
"components": [
70+
{ "internalType": "uint256", "name": "nativeFee", "type": "uint256" },
71+
{ "internalType": "uint256", "name": "lzTokenFee", "type": "uint256" }
72+
],
73+
"internalType": "struct MessagingFee",
74+
"name": "fee",
75+
"type": "tuple"
76+
}
77+
],
78+
"internalType": "struct MessagingReceipt",
79+
"name": "msgReceipt",
80+
"type": "tuple"
81+
},
82+
{
83+
"components": [
84+
{ "internalType": "uint256", "name": "amountSentLD", "type": "uint256" },
85+
{ "internalType": "uint256", "name": "amountReceivedLD", "type": "uint256" }
86+
],
87+
"internalType": "struct OFTReceipt",
88+
"name": "oftReceipt",
89+
"type": "tuple"
90+
}
91+
],
92+
"stateMutability": "payable",
93+
"type": "function"
94+
},
95+
{
96+
"inputs": [],
97+
"name": "token",
98+
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
99+
"stateMutability": "view",
100+
"type": "function"
101+
},
102+
{
103+
"inputs": [],
104+
"name": "approvalRequired",
105+
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
106+
"stateMutability": "view",
107+
"type": "function"
108+
}
109+
]

src/integration/blockchain/shared/evm/evm-client.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ export abstract class EvmClient extends BlockchainClient {
447447
return EvmUtil.getGasPriceLimitFromHex(txHex, currentGasPrice);
448448
}
449449

450-
async approveContract(asset: Asset, contractAddress: string): Promise<string> {
450+
async approveContract(asset: Asset, contractAddress: string, wait = false): Promise<string> {
451451
const contract = this.getERC20ContractForDex(asset.chainId);
452452

453453
const transaction = await contract.populateTransaction.approve(contractAddress, ethers.constants.MaxInt256);
@@ -464,9 +464,20 @@ export abstract class EvmClient extends BlockchainClient {
464464

465465
this.setNonce(this.walletAddress, nonce + 1);
466466

467+
if (wait) await tx.wait();
468+
467469
return tx.hash;
468470
}
469471

472+
async checkAndApproveContract(asset: Asset, contractAddress: string, amount: EthersNumber): Promise<string | null> {
473+
const contract = this.getERC20ContractForDex(asset.chainId);
474+
const allowance = await contract.allowance(this.walletAddress, contractAddress);
475+
476+
if (allowance.gte(amount)) return null;
477+
478+
return this.approveContract(asset, contractAddress, true);
479+
}
480+
470481
// --- PUBLIC API - SWAPS --- //
471482

472483
async getUniswapLiquidity(nftContract: string, positionId: number): Promise<[number, number]> {

0 commit comments

Comments
 (0)