@cryptorubic/web3 0.2.8 → 0.2.10
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/package.json +3 -3
- package/src/lib/adapter/adapters/constants/uni-v3-permit-abi.d.ts +2 -0
- package/src/lib/adapter/adapters/constants/uni-v3-permit-abi.js +72 -0
- package/src/lib/adapter/adapters/evm-adapter.d.ts +3 -0
- package/src/lib/adapter/adapters/evm-adapter.js +20 -0
- package/src/lib/adapter/adapters/models/permit2-contract-types.d.ts +5 -0
- package/src/lib/adapter/adapters/models/permit2-contract-types.js +2 -0
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cryptorubic/web3",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"tslib": "^2.3.0",
|
|
6
6
|
"bignumber.js": "9.1.2",
|
|
7
|
-
"@cryptorubic/core": "0.2.
|
|
7
|
+
"@cryptorubic/core": "0.2.10",
|
|
8
8
|
"viem": "^2.19.1",
|
|
9
9
|
"web3-utils": "^4.3.1",
|
|
10
10
|
"@ton/ton": "^15.1.0",
|
|
11
11
|
"@solana/web3.js": "1.95.3",
|
|
12
12
|
"@solflare-wallet/utl-sdk": "^1.4.0",
|
|
13
13
|
"@ethersproject/bignumber": "^5.7.0",
|
|
14
|
-
"@cryptorubic/tron-types": "0.2.
|
|
14
|
+
"@cryptorubic/tron-types": "0.2.10",
|
|
15
15
|
"bitcoin-address-validation": "^2.2.3",
|
|
16
16
|
"axios": "0.27.2",
|
|
17
17
|
"crc-32": "^1.2.2",
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UNI_V3_PERMIT_2_ABI = void 0;
|
|
4
|
+
exports.UNI_V3_PERMIT_2_ABI = [
|
|
5
|
+
{
|
|
6
|
+
inputs: [
|
|
7
|
+
{
|
|
8
|
+
internalType: 'address',
|
|
9
|
+
name: 'owner',
|
|
10
|
+
type: 'address',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
internalType: 'address',
|
|
14
|
+
name: 'token',
|
|
15
|
+
type: 'address',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
internalType: 'address',
|
|
19
|
+
name: 'spender',
|
|
20
|
+
type: 'address',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
name: 'allowance',
|
|
24
|
+
outputs: [
|
|
25
|
+
{
|
|
26
|
+
internalType: 'uint160',
|
|
27
|
+
name: 'amount',
|
|
28
|
+
type: 'uint160',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
internalType: 'uint48',
|
|
32
|
+
name: 'expiration',
|
|
33
|
+
type: 'uint48',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
internalType: 'uint48',
|
|
37
|
+
name: 'nonce',
|
|
38
|
+
type: 'uint48',
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
stateMutability: 'view',
|
|
42
|
+
type: 'function',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
inputs: [
|
|
46
|
+
{
|
|
47
|
+
internalType: 'address',
|
|
48
|
+
name: 'token',
|
|
49
|
+
type: 'address',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
internalType: 'address',
|
|
53
|
+
name: 'spender',
|
|
54
|
+
type: 'address',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
internalType: 'uint160',
|
|
58
|
+
name: 'amount',
|
|
59
|
+
type: 'uint160',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
internalType: 'uint48',
|
|
63
|
+
name: 'expiration',
|
|
64
|
+
type: 'uint48',
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
name: 'approve',
|
|
68
|
+
outputs: [],
|
|
69
|
+
stateMutability: 'nonpayable',
|
|
70
|
+
type: 'function',
|
|
71
|
+
},
|
|
72
|
+
];
|
|
@@ -33,6 +33,9 @@ export declare class EvmAdapter extends AbstractAdapter<PublicActions & PublicCl
|
|
|
33
33
|
encodeApprove(tokenAddress: string, spenderAddress: string, amount?: string): EvmTransactionConfig;
|
|
34
34
|
needApprove(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string): Promise<boolean>;
|
|
35
35
|
approve(fromAddress: string, tokenAddress: string, spenderAddress: string, amount?: string): Promise<string>;
|
|
36
|
+
needPermit2Approve(token: TokenAmount, permit2Address: string, walletAddress: string, spenderAddress: string): Promise<boolean>;
|
|
37
|
+
encodePermit2Approve(tokenAddress: string, spenderAddress: string, permit2Address: string, expiration: string, amount: string): EvmTransactionConfig;
|
|
38
|
+
approveOnPermit2(fromAddress: string, tokenAddress: string, permit2Address: string, spenderAddress: string, deadline?: BigNumber, amount?: BigNumber): Promise<string>;
|
|
36
39
|
/**
|
|
37
40
|
* Calculates EIP-1559 specific gas details.
|
|
38
41
|
* @see {@link https://github.com/ethers-io/ethers.js/blob/master/packages/abstract-provider/src.ts/index.ts#L235}
|
|
@@ -9,6 +9,7 @@ const core_1 = require("@cryptorubic/core");
|
|
|
9
9
|
const bignumber_js_1 = require("bignumber.js");
|
|
10
10
|
const web3_pure_1 = require("../../utils/web3-pure");
|
|
11
11
|
const possible_errors_1 = require("./constants/possible-errors");
|
|
12
|
+
const uni_v3_permit_abi_1 = require("./constants/uni-v3-permit-abi");
|
|
12
13
|
class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
13
14
|
async needPreswapAction(token, contractAddress, walletAddress, amount) {
|
|
14
15
|
return this.needApprove(token, contractAddress, walletAddress, amount);
|
|
@@ -264,6 +265,25 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
264
265
|
const config = this.encodeApprove(tokenAddress, spenderAddress, amount);
|
|
265
266
|
return this.write(fromAddress, config.to, config.value, config.data);
|
|
266
267
|
}
|
|
268
|
+
async needPermit2Approve(token, permit2Address, walletAddress, spenderAddress) {
|
|
269
|
+
const res = await this.read(permit2Address, uni_v3_permit_abi_1.UNI_V3_PERMIT_2_ABI, 'allowance', [walletAddress, token.address, spenderAddress]);
|
|
270
|
+
return (token.weiAmount.gt(res.amount) ||
|
|
271
|
+
new bignumber_js_1.default(Date.now()).gt(res.expiration));
|
|
272
|
+
}
|
|
273
|
+
encodePermit2Approve(tokenAddress, spenderAddress, permit2Address, expiration, amount) {
|
|
274
|
+
const tx = EvmAdapter.encodeMethodCall(permit2Address, uni_v3_permit_abi_1.UNI_V3_PERMIT_2_ABI, 'approve', [tokenAddress, spenderAddress, amount, expiration]);
|
|
275
|
+
return {
|
|
276
|
+
data: tx.data,
|
|
277
|
+
value: tx.value,
|
|
278
|
+
to: tx.to,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
async approveOnPermit2(fromAddress, tokenAddress, permit2Address, spenderAddress, deadline = new bignumber_js_1.default(1000000), amount) {
|
|
282
|
+
const approveAmount = amount ? amount : new bignumber_js_1.default(2).pow(256).minus(1);
|
|
283
|
+
const expiration = new bignumber_js_1.default(Date.now()).plus(deadline).toFixed();
|
|
284
|
+
const tx = this.encodePermit2Approve(tokenAddress, spenderAddress, permit2Address, expiration, approveAmount.toFixed());
|
|
285
|
+
return this.write(fromAddress, tx.to, tx.value, tx.data);
|
|
286
|
+
}
|
|
267
287
|
/**
|
|
268
288
|
* Calculates EIP-1559 specific gas details.
|
|
269
289
|
* @see {@link https://github.com/ethers-io/ethers.js/blob/master/packages/abstract-provider/src.ts/index.ts#L235}
|