impermax-sdk 1.2.112 → 2.1.0
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/lib/abis/contracts/IAllowanceTransfer.json +3772 -0
- package/lib/abis/contracts/IERC721.json +3515 -0
- package/lib/abis/contracts/ITokenizedUniswapV2Position.json +4167 -0
- package/lib/abis/contracts/ITokenizedUniswapV3Position.json +5539 -0
- package/lib/abis/contracts/IUniswapV3Pool.json +6606 -0
- package/lib/abis/contracts/ImpermaxV3Borrowable.json +22131 -0
- package/lib/abis/contracts/ImpermaxV3Collateral.json +22988 -0
- package/lib/abis/contracts/ImpermaxV3Factory.json +17645 -0
- package/lib/abis/contracts/ImpermaxV3UniV2Router01.json +32488 -0
- package/lib/abis/contracts/ImpermaxV3UniV3Router01.json +37742 -0
- package/lib/abis/contracts/PoolTokenRouter01.json +9058 -0
- package/lib/config/amms.d.ts +0 -2
- package/lib/config/amms.js +0 -3
- package/lib/config/chainId.d.ts +2 -0
- package/lib/config/chainId.js +26 -0
- package/lib/config/contracts/routers.d.ts +3 -2
- package/lib/config/contracts/routers.js +46 -22
- package/lib/config/factories.js +1 -0
- package/lib/config/farms.d.ts +0 -2
- package/lib/config/farms.js +0 -3
- package/lib/config/types.d.ts +14 -1
- package/lib/config/types.js +15 -1
- package/lib/index.d.ts +6 -5
- package/lib/index.js +11 -4
- package/lib/offchain/account/index.d.ts +4 -2
- package/lib/offchain/account/index.js +7 -3
- package/lib/offchain/account/lendingPool/index.d.ts +2 -1
- package/lib/offchain/account/lendingPool/index.js +3 -1
- package/lib/offchain/account/lendingPool/offchainAccountBorrowable.d.ts +0 -3
- package/lib/offchain/account/lendingPool/offchainAccountBorrowable.js +1 -27
- package/lib/offchain/account/lendingPool/offchainAccountCollateral.d.ts +0 -2
- package/lib/offchain/account/lendingPool/offchainAccountCollateral.js +2 -14
- package/lib/offchain/account/lendingPool/offchainAccountLendingPool.d.ts +11 -4
- package/lib/offchain/account/lendingPool/offchainAccountLendingPool.js +16 -15
- package/lib/offchain/account/lendingPool/offchainLeveragedPosition.d.ts +25 -0
- package/lib/offchain/account/lendingPool/offchainLeveragedPosition.js +116 -0
- package/lib/offchain/account/offchainAccount.d.ts +6 -6
- package/lib/offchain/account/offchainAccount.js +7 -7
- package/lib/offchain/account/offchainMultichainAccount.d.ts +34 -0
- package/lib/offchain/account/offchainMultichainAccount.js +66 -0
- package/lib/offchain/account/vault/index.d.ts +3 -0
- package/lib/offchain/account/vault/index.js +7 -0
- package/lib/offchain/account/vault/offchainAccountVault.d.ts +16 -0
- package/lib/offchain/account/{offchainAccountLendingVault.js → vault/offchainAccountVault.js} +14 -14
- package/lib/offchain/index.d.ts +3 -2
- package/lib/offchain/index.js +5 -3
- package/lib/offchain/lendingPool/offchainCollateral.d.ts +1 -0
- package/lib/offchain/lendingPool/offchainCollateral.js +6 -0
- package/lib/offchain/lendingPool/offchainLendingPool.d.ts +14 -1
- package/lib/offchain/lendingPool/offchainLendingPool.js +47 -0
- package/lib/offchain/offchain.d.ts +8 -15
- package/lib/offchain/offchain.js +16 -19
- package/lib/offchain/offchainAPRHelper.js +0 -1
- package/lib/offchain/offchainInitializer.d.ts +4 -4
- package/lib/offchain/offchainInitializer.js +4 -4
- package/lib/offchain/offchainMultichain.d.ts +50 -0
- package/lib/offchain/offchainMultichain.js +75 -0
- package/lib/offchain/offchainTypes.d.ts +1 -1
- package/lib/offchain/vault/index.d.ts +6 -0
- package/lib/offchain/vault/index.js +14 -0
- package/lib/offchain/vault/offchainHedgedVault.d.ts +9 -0
- package/lib/offchain/vault/offchainHedgedVault.js +57 -0
- package/lib/offchain/vault/offchainLendingVault.d.ts +16 -0
- package/lib/offchain/vault/offchainLendingVault.js +73 -0
- package/lib/offchain/vault/offchainLeveragedVault.d.ts +9 -0
- package/lib/offchain/vault/offchainLeveragedVault.js +57 -0
- package/lib/offchain/{offchainLendingVault.d.ts → vault/offchainVault.d.ts} +16 -7
- package/lib/offchain/{offchainLendingVault.js → vault/offchainVault.js} +33 -17
- package/lib/onchain/account/lendingPool/index.d.ts +8 -1
- package/lib/onchain/account/lendingPool/index.js +38 -1
- package/lib/onchain/account/lendingPool/nftlp/index.d.ts +4 -0
- package/lib/onchain/account/lendingPool/nftlp/index.js +11 -0
- package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlp.d.ts +7 -0
- package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlp.js +12 -0
- package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlpUniswapV3.d.ts +4 -0
- package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlpUniswapV3.js +13 -0
- package/lib/onchain/account/lendingPool/onchainAccountBorrowable.d.ts +12 -7
- package/lib/onchain/account/lendingPool/onchainAccountBorrowable.js +5 -50
- package/lib/onchain/account/lendingPool/onchainAccountBorrowableV2.d.ts +10 -0
- package/lib/onchain/account/lendingPool/onchainAccountBorrowableV2.js +55 -0
- package/lib/onchain/account/lendingPool/onchainAccountBorrowableV3.d.ts +10 -0
- package/lib/onchain/account/lendingPool/onchainAccountBorrowableV3.js +28 -0
- package/lib/onchain/account/lendingPool/onchainAccountCollateral.d.ts +6 -19
- package/lib/onchain/account/lendingPool/onchainAccountCollateral.js +7 -90
- package/lib/onchain/account/lendingPool/onchainAccountCollateralV2.d.ts +25 -0
- package/lib/onchain/account/lendingPool/onchainAccountCollateralV2.js +99 -0
- package/lib/onchain/account/lendingPool/onchainAccountCollateralV3.d.ts +18 -0
- package/lib/onchain/account/lendingPool/onchainAccountCollateralV3.js +44 -0
- package/lib/onchain/account/lendingPool/onchainAccountLendingPool.d.ts +19 -34
- package/lib/onchain/account/lendingPool/onchainAccountLendingPool.js +17 -227
- package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV2.d.ts +44 -0
- package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV2.js +285 -0
- package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV3.d.ts +27 -0
- package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV3.js +32 -0
- package/lib/onchain/account/onchainAccount.js +1 -2
- package/lib/onchain/account/onchainAccountLendingVault.d.ts +3 -3
- package/lib/onchain/impermaxFactory/index.d.ts +3 -1
- package/lib/onchain/impermaxFactory/index.js +5 -1
- package/lib/onchain/impermaxFactory/lendingPool/index.d.ts +8 -1
- package/lib/onchain/impermaxFactory/lendingPool/index.js +39 -1
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/index.d.ts +4 -0
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/index.js +11 -0
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlp.d.ts +22 -0
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlp.js +19 -0
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlpUniswapV3.d.ts +24 -0
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlpUniswapV3.js +90 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowable.d.ts +15 -11
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowable.js +5 -24
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV2.d.ts +9 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV2.js +36 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV3.d.ts +7 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV3.js +23 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateral.d.ts +5 -16
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateral.js +6 -43
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV2.d.ts +20 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV2.js +58 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV3.d.ts +13 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV3.js +36 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPool.d.ts +32 -47
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPool.js +28 -314
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPoolV2.d.ts +76 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPoolV2.js +338 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPoolV3.d.ts +42 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPoolV3.js +39 -0
- package/lib/onchain/impermaxFactory/onchainImpermaxFactory.d.ts +19 -9
- package/lib/onchain/impermaxFactory/onchainImpermaxFactory.js +16 -26
- package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV2.d.ts +16 -0
- package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV2.js +81 -0
- package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV3.d.ts +16 -0
- package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV3.js +88 -0
- package/lib/onchain/interactions/lendingPool/index.d.ts +8 -1
- package/lib/onchain/interactions/lendingPool/index.js +38 -1
- package/lib/onchain/interactions/lendingPool/nftlp/index.d.ts +4 -0
- package/lib/onchain/interactions/lendingPool/nftlp/index.js +11 -0
- package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlp.d.ts +7 -0
- package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlp.js +12 -0
- package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlpUniswapV3.d.ts +4 -0
- package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlpUniswapV3.js +13 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowable.d.ts +6 -10
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowable.js +5 -37
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV2.d.ts +15 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV2.js +63 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV3.d.ts +9 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV3.js +14 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateral.d.ts +3 -15
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateral.js +5 -37
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV2.d.ts +20 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV2.js +48 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV3.d.ts +13 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV3.js +20 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPool.d.ts +16 -31
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPool.js +12 -94
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV2.d.ts +42 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV2.js +114 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV3.d.ts +27 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV3.js +32 -0
- package/lib/onchain/interactions/onchainInteractions.js +3 -4
- package/lib/onchain/interactions/onchainInteractionsLendingVault.d.ts +1 -1
- package/lib/onchain/interactions/onchainInteractionsLendingVault.js +1 -1
- package/lib/onchain/interactions/onchainInteractionsPoolToken.d.ts +13 -13
- package/lib/onchain/interactions/onchainInteractionsPoolToken.js +33 -85
- package/lib/onchain/onchain.d.ts +3 -0
- package/lib/onchain/onchain.js +11 -3
- package/lib/onchain/onchainContractsHelper.d.ts +19 -8
- package/lib/onchain/onchainContractsHelper.js +55 -21
- package/lib/onchain/onchainLendingVault.d.ts +3 -3
- package/lib/onchain/onchainPermitHelper.d.ts +21 -0
- package/lib/onchain/onchainPermitHelper.js +198 -0
- package/lib/onchain/onchainTypes.d.ts +6 -0
- package/package.json +1 -1
- package/lib/offchain/account/offchainAccountLendingVault.d.ts +0 -16
|
@@ -10,9 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const ethers_1 = require("ethers");
|
|
13
|
-
const onchainTypes_1 = require("../onchainTypes");
|
|
14
13
|
const weths_1 = require("../../config/contracts/weths");
|
|
15
|
-
const general_1 = require("../../config/general");
|
|
16
14
|
const MAX_UINT256 = ethers_1.ethers.constants.MaxUint256;
|
|
17
15
|
const EIP712DOMAIN = [
|
|
18
16
|
{ name: "name", type: "string" },
|
|
@@ -38,6 +36,7 @@ class OnchainInteractionsPoolToken {
|
|
|
38
36
|
// Shortcuts
|
|
39
37
|
this.getAccountAddress = () => this.getInteractions().getAccountAddress();
|
|
40
38
|
this.getOnchain = () => this.getInteractions().getOnchain();
|
|
39
|
+
this.getPermitHelper = () => this.getOnchain().getPermitHelper();
|
|
41
40
|
}
|
|
42
41
|
send(method, onTransactionHash, value) {
|
|
43
42
|
return this.getInteractions().send(method, onTransactionHash, value);
|
|
@@ -46,7 +45,7 @@ class OnchainInteractionsPoolToken {
|
|
|
46
45
|
getOwnerSpender() {
|
|
47
46
|
return {
|
|
48
47
|
owner: this.getAccountAddress(),
|
|
49
|
-
spender: this.
|
|
48
|
+
spender: this.getPoolTokenRouter()._address,
|
|
50
49
|
};
|
|
51
50
|
}
|
|
52
51
|
isWETH() {
|
|
@@ -55,130 +54,79 @@ class OnchainInteractionsPoolToken {
|
|
|
55
54
|
return token._address.toLowerCase() == weths_1.WETH[this.getOnchain().network].toLowerCase();
|
|
56
55
|
});
|
|
57
56
|
}
|
|
58
|
-
|
|
57
|
+
getPoolTokenAllowance() {
|
|
59
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
59
|
const poolToken = yield this.poolToken.getPoolToken();
|
|
61
|
-
const token = yield this.poolToken.getToken();
|
|
62
|
-
if ((yield this.isWETH()) && approvalType == onchainTypes_1.ApprovalType.UNDERLYING)
|
|
63
|
-
return MAX_UINT256;
|
|
64
60
|
const { owner, spender } = this.getOwnerSpender();
|
|
65
|
-
const allowance =
|
|
66
|
-
(approvalType == onchainTypes_1.ApprovalType.UNDERLYING) ? yield token.methods.allowance(owner, spender).call() :
|
|
67
|
-
(approvalType == onchainTypes_1.ApprovalType.BORROW) ? yield poolToken.methods.borrowAllowance(owner, spender).call() : 0;
|
|
61
|
+
const allowance = yield poolToken.methods.allowance(owner, spender).call();
|
|
68
62
|
return ethers_1.BigNumber.from(allowance);
|
|
69
63
|
});
|
|
70
64
|
}
|
|
71
|
-
|
|
65
|
+
getUnderlyingAllowance() {
|
|
72
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
if (yield this.isWETH())
|
|
68
|
+
return MAX_UINT256;
|
|
75
69
|
const token = yield this.poolToken.getToken();
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (approvalType == onchainTypes_1.ApprovalType.UNDERLYING)
|
|
80
|
-
method = token.methods.approve(spender, amount);
|
|
81
|
-
if (approvalType == onchainTypes_1.ApprovalType.BORROW)
|
|
82
|
-
method = poolToken.methods.borrowApprove(spender, amount);
|
|
83
|
-
return this.send(method, onTransactionHash);
|
|
70
|
+
const { owner, spender } = this.getOwnerSpender();
|
|
71
|
+
const allowance = yield token.methods.allowance(owner, spender).call();
|
|
72
|
+
return ethers_1.BigNumber.from(allowance);
|
|
84
73
|
});
|
|
85
74
|
}
|
|
86
|
-
|
|
75
|
+
approvePoolToken(amount, onTransactionHash) {
|
|
87
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
const {
|
|
77
|
+
const { spender } = this.getOwnerSpender();
|
|
89
78
|
const poolToken = yield this.poolToken.getPoolToken();
|
|
90
|
-
|
|
91
|
-
const contract = approvalType == onchainTypes_1.ApprovalType.UNDERLYING ? token : poolToken;
|
|
92
|
-
const nonce = yield contract.methods.nonces(owner).call();
|
|
93
|
-
const name = yield contract.methods.name().call();
|
|
94
|
-
const deadline = deadlineArg ? deadlineArg : general_1.DEADLINE;
|
|
95
|
-
const data = JSON.stringify({
|
|
96
|
-
types: TYPES,
|
|
97
|
-
domain: {
|
|
98
|
-
name: name,
|
|
99
|
-
version: "1",
|
|
100
|
-
chainId: this.getOnchain().chainId,
|
|
101
|
-
verifyingContract: contract._address,
|
|
102
|
-
},
|
|
103
|
-
primaryType: approvalType == onchainTypes_1.ApprovalType.BORROW ? "BorrowPermit" : "Permit",
|
|
104
|
-
message: {
|
|
105
|
-
owner: owner,
|
|
106
|
-
spender: spender,
|
|
107
|
-
value: amount.toString(),
|
|
108
|
-
nonce: ethers_1.BigNumber.from(nonce).toHexString(),
|
|
109
|
-
deadline: deadline.toNumber(),
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
this.getOnchain().web3.currentProvider.send({
|
|
113
|
-
method: "eth_signTypedData_v4",
|
|
114
|
-
params: [owner, data],
|
|
115
|
-
from: owner
|
|
116
|
-
}, (err, data) => {
|
|
117
|
-
if (err) {
|
|
118
|
-
console.error(err);
|
|
119
|
-
return callBack(null);
|
|
120
|
-
}
|
|
121
|
-
const signature = data.result.substring(2);
|
|
122
|
-
const r = "0x" + signature.substring(0, 64);
|
|
123
|
-
const s = "0x" + signature.substring(64, 128);
|
|
124
|
-
let v = parseInt(signature.substring(128, 130), 16);
|
|
125
|
-
if (v == 0 || v == 1)
|
|
126
|
-
v = v + 27;
|
|
127
|
-
//console.log(v, r, s);
|
|
128
|
-
const permitData = ethers_1.ethers.utils.defaultAbiCoder.encode(['bool', 'uint8', 'bytes32', 'bytes32'], [false, v, r, s]);
|
|
129
|
-
callBack({ permitData, deadline, amount });
|
|
130
|
-
});
|
|
79
|
+
return this.send(poolToken.methods.approve(spender, amount), onTransactionHash);
|
|
131
80
|
});
|
|
132
81
|
}
|
|
133
|
-
|
|
82
|
+
approveUnderlying(amount, onTransactionHash) {
|
|
134
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
this.
|
|
84
|
+
const { spender } = this.getOwnerSpender();
|
|
85
|
+
const token = yield this.poolToken.getToken();
|
|
86
|
+
return this.send(token.methods.approve(spender, amount), onTransactionHash);
|
|
138
87
|
});
|
|
139
88
|
}
|
|
140
|
-
getSendData(
|
|
89
|
+
getSendData(permits) {
|
|
141
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
142
91
|
return {
|
|
143
|
-
router: this.
|
|
92
|
+
router: this.getPoolTokenRouter(),
|
|
144
93
|
ptAddress: (yield this.poolToken.getPoolToken())._address,
|
|
145
94
|
account: this.getInteractions().getAccountAddress(),
|
|
146
|
-
|
|
147
|
-
deadline: permitData ? permitData.deadline : general_1.DEADLINE,
|
|
95
|
+
permitsData: this.getPermitHelper().encodePermits(permits),
|
|
148
96
|
};
|
|
149
97
|
});
|
|
150
98
|
}
|
|
151
|
-
mintETH(amount,
|
|
99
|
+
mintETH(amount, onTransactionHash) {
|
|
152
100
|
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
-
const { router, ptAddress, account
|
|
154
|
-
return this.send(router.methods.mintETH(ptAddress, account
|
|
101
|
+
const { router, ptAddress, account } = yield this.getSendData([]);
|
|
102
|
+
return this.send(router.methods.mintETH(ptAddress, account), onTransactionHash, amount);
|
|
155
103
|
});
|
|
156
104
|
}
|
|
157
|
-
mint(amount,
|
|
105
|
+
mint(amount, permits, onTransactionHash) {
|
|
158
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
-
const { router, ptAddress, account,
|
|
160
|
-
return this.send(router.methods.mint(ptAddress, amount, account,
|
|
107
|
+
const { router, ptAddress, account, permitsData } = yield this.getSendData(permits);
|
|
108
|
+
return this.send(router.methods.mint(ptAddress, amount, account, permitsData), onTransactionHash);
|
|
161
109
|
});
|
|
162
110
|
}
|
|
163
111
|
;
|
|
164
|
-
deposit(amount,
|
|
112
|
+
deposit(amount, permits, onTransactionHash) {
|
|
165
113
|
return __awaiter(this, void 0, void 0, function* () {
|
|
166
114
|
if (yield this.isWETH()) {
|
|
167
|
-
return this.mintETH(amount,
|
|
115
|
+
return this.mintETH(amount, onTransactionHash);
|
|
168
116
|
}
|
|
169
117
|
else {
|
|
170
|
-
return this.mint(amount,
|
|
118
|
+
return this.mint(amount, permits, onTransactionHash);
|
|
171
119
|
}
|
|
172
120
|
});
|
|
173
121
|
}
|
|
174
|
-
withdraw(tokens,
|
|
122
|
+
withdraw(tokens, permits, onTransactionHash) {
|
|
175
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
-
const { router, ptAddress, account,
|
|
124
|
+
const { router, ptAddress, account, permitsData } = yield this.getSendData(permits);
|
|
177
125
|
if (yield this.isWETH()) {
|
|
178
|
-
return this.send(router.methods.redeemETH(ptAddress, tokens, account,
|
|
126
|
+
return this.send(router.methods.redeemETH(ptAddress, tokens, account, permitsData), onTransactionHash);
|
|
179
127
|
}
|
|
180
128
|
else {
|
|
181
|
-
return this.send(router.methods.redeem(ptAddress, tokens, account,
|
|
129
|
+
return this.send(router.methods.redeem(ptAddress, tokens, account, permitsData), onTransactionHash);
|
|
182
130
|
}
|
|
183
131
|
});
|
|
184
132
|
}
|
package/lib/onchain/onchain.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import OnchainAccount from './account';
|
|
|
7
7
|
import OnchainInteractions from './interactions';
|
|
8
8
|
import { OnchainConfig } from './onchainTypes';
|
|
9
9
|
import OnchainConfigManager from './configManager';
|
|
10
|
+
import OnchainPermitHelper from "./onchainPermitHelper";
|
|
10
11
|
export default class Onchain {
|
|
11
12
|
readonly network: Networks;
|
|
12
13
|
private readonly offchain;
|
|
@@ -17,6 +18,7 @@ export default class Onchain {
|
|
|
17
18
|
readonly liquidityBuffer: number;
|
|
18
19
|
priceInverted: boolean;
|
|
19
20
|
protected contractsHelper: OnchainContractsHelper;
|
|
21
|
+
protected permitHelper: OnchainPermitHelper;
|
|
20
22
|
protected configManager: OnchainConfigManager;
|
|
21
23
|
protected factories: FactoryIndex<OnchainImpermaxFactory>;
|
|
22
24
|
protected lendingVaults: AddressIndex<OnchainLendingVault>;
|
|
@@ -27,6 +29,7 @@ export default class Onchain {
|
|
|
27
29
|
setPriceInverted(priceInverted: boolean): void;
|
|
28
30
|
getOffchain: () => Offchain;
|
|
29
31
|
getContractHelper: () => OnchainContractsHelper;
|
|
32
|
+
getPermitHelper: () => OnchainPermitHelper;
|
|
30
33
|
getConfigManager: () => OnchainConfigManager;
|
|
31
34
|
getImpermaxFactory(factory: Factory): OnchainImpermaxFactory;
|
|
32
35
|
getLendingVault(vaultAddress: Address): OnchainLendingVault;
|
package/lib/onchain/onchain.js
CHANGED
|
@@ -3,16 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const types_1 = require("../config/types");
|
|
6
7
|
const onchainContractsHelper_1 = __importDefault(require("./onchainContractsHelper"));
|
|
7
|
-
const impermaxFactory_1 =
|
|
8
|
+
const impermaxFactory_1 = require("./impermaxFactory");
|
|
8
9
|
const onchainLendingVault_1 = __importDefault(require("./onchainLendingVault"));
|
|
9
10
|
const account_1 = __importDefault(require("./account"));
|
|
10
11
|
const interactions_1 = __importDefault(require("./interactions"));
|
|
11
12
|
const configManager_1 = __importDefault(require("./configManager"));
|
|
13
|
+
const onchainPermitHelper_1 = __importDefault(require("./onchainPermitHelper"));
|
|
12
14
|
class Onchain {
|
|
13
15
|
constructor(cfg) {
|
|
14
16
|
this.getOffchain = () => this.offchain;
|
|
15
17
|
this.getContractHelper = () => this.contractsHelper;
|
|
18
|
+
this.getPermitHelper = () => this.permitHelper;
|
|
16
19
|
this.getConfigManager = () => this.configManager;
|
|
17
20
|
this.network = cfg.network;
|
|
18
21
|
this.offchain = cfg.offchain;
|
|
@@ -23,6 +26,7 @@ class Onchain {
|
|
|
23
26
|
this.dust = 1.00000001;
|
|
24
27
|
this.priceInverted = cfg.priceInverted ? cfg.priceInverted : false;
|
|
25
28
|
this.contractsHelper = new onchainContractsHelper_1.default(this);
|
|
29
|
+
this.permitHelper = new onchainPermitHelper_1.default(this);
|
|
26
30
|
this.configManager = new configManager_1.default(this);
|
|
27
31
|
this.factories = {};
|
|
28
32
|
this.accounts = {};
|
|
@@ -47,8 +51,12 @@ class Onchain {
|
|
|
47
51
|
this.priceInverted = priceInverted;
|
|
48
52
|
}
|
|
49
53
|
getImpermaxFactory(factory) {
|
|
50
|
-
if (!this.factories[factory])
|
|
51
|
-
|
|
54
|
+
if (!this.factories[factory]) {
|
|
55
|
+
if (factory == types_1.Factory.V3)
|
|
56
|
+
this.factories[factory] = new impermaxFactory_1.OnchainImpermaxFactoryV3(this, factory);
|
|
57
|
+
else
|
|
58
|
+
this.factories[factory] = new impermaxFactory_1.OnchainImpermaxFactoryV2(this, factory);
|
|
59
|
+
}
|
|
52
60
|
return this.factories[factory];
|
|
53
61
|
}
|
|
54
62
|
getLendingVault(vaultAddress) {
|
|
@@ -10,15 +10,10 @@ export default class OnchainContractsHelper {
|
|
|
10
10
|
claimAggregator: Contract;
|
|
11
11
|
constructor(onchain: Onchain);
|
|
12
12
|
private newContract;
|
|
13
|
-
newRouter: (address: Address) => any;
|
|
14
|
-
newFactory: (address: Address) => any;
|
|
15
|
-
newSimpleUniswapOracle: (address: Address) => any;
|
|
16
|
-
newUniswapV2Pair: (address: Address) => any;
|
|
17
|
-
newUniswapV2Factory: (address: Address) => any;
|
|
18
13
|
newERC20: (address: Address) => any;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
newERC721: (address: Address) => any;
|
|
15
|
+
newPermit2: (address: Address) => any;
|
|
16
|
+
newPoolTokenRouter: (address: Address) => any;
|
|
22
17
|
newMerkleDistributor: (address: Address) => any;
|
|
23
18
|
newFarmingPool: (address: Address) => any;
|
|
24
19
|
newClaimAggregator: (address: Address) => any;
|
|
@@ -28,4 +23,20 @@ export default class OnchainContractsHelper {
|
|
|
28
23
|
newLendingVault: (address: Address) => any;
|
|
29
24
|
newLendingVaultWatcher: (address: Address) => any;
|
|
30
25
|
newImpermaxConfigManager: (address: Address) => any;
|
|
26
|
+
newFactoryV2: (address: Address) => any;
|
|
27
|
+
newSimpleUniswapOracle: (address: Address) => any;
|
|
28
|
+
newCollateralV2: (address: Address) => any;
|
|
29
|
+
newBorrowableV2: (address: Address) => any;
|
|
30
|
+
newStakedLPToken: (address: Address) => any;
|
|
31
|
+
newRouterV2: (address: Address) => any;
|
|
32
|
+
newFactoryV3: (address: Address) => any;
|
|
33
|
+
newBorrowableV3: (address: Address) => any;
|
|
34
|
+
newCollateralV3: (address: Address) => any;
|
|
35
|
+
newRouterUniV2: (address: Address) => any;
|
|
36
|
+
newRouterUniV3: (address: Address) => any;
|
|
37
|
+
newNftlpUniV2: (address: Address) => any;
|
|
38
|
+
newNftlpUniV3: (address: Address) => any;
|
|
39
|
+
newUniswapV2Pair: (address: Address) => any;
|
|
40
|
+
newUniswapV2Factory: (address: Address) => any;
|
|
41
|
+
newUniswapV3Pool: (address: Address) => any;
|
|
31
42
|
}
|
|
@@ -3,39 +3,53 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const impermax_chef_1 = require("../config/contracts/impermax-chef");
|
|
7
|
+
const claim_aggregators_1 = require("../config/contracts/claim-aggregators");
|
|
8
|
+
const merkle_distributors_1 = require("../config/contracts/merkle-distributors");
|
|
9
|
+
// Generic
|
|
6
10
|
const IERC20_json_1 = __importDefault(require("../abis/contracts/IERC20.json"));
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const IStakedLPToken_json_1 = __importDefault(require("../abis/contracts/IStakedLPToken.json"));
|
|
13
|
-
const IFactory_json_1 = __importDefault(require("../abis/contracts/IFactory.json"));
|
|
14
|
-
const ISimpleUniswapOracle_json_1 = __importDefault(require("../abis/contracts/ISimpleUniswapOracle.json"));
|
|
11
|
+
const IERC721_json_1 = __importDefault(require("../abis/contracts/IERC721.json"));
|
|
12
|
+
const IAllowanceTransfer_json_1 = __importDefault(require("../abis/contracts/IAllowanceTransfer.json"));
|
|
13
|
+
// Impermax
|
|
14
|
+
const PoolTokenRouter01_json_1 = __importDefault(require("../abis/contracts/PoolTokenRouter01.json"));
|
|
15
|
+
const ImpermaxChef_json_1 = __importDefault(require("../abis/contracts/ImpermaxChef.json"));
|
|
15
16
|
const IMerkleDistributor_json_1 = __importDefault(require("../abis/contracts/IMerkleDistributor.json"));
|
|
16
17
|
const IFarmingPool_json_1 = __importDefault(require("../abis/contracts/IFarmingPool.json"));
|
|
17
18
|
const ClaimAggregator_json_1 = __importDefault(require("../abis/contracts/ClaimAggregator.json"));
|
|
18
19
|
const IClaimable_json_1 = __importDefault(require("../abis/contracts/IClaimable.json"));
|
|
19
|
-
const IStakingRewards_json_1 = __importDefault(require("../abis/contracts/IStakingRewards.json"));
|
|
20
|
-
const ImpermaxChef_json_1 = __importDefault(require("../abis/contracts/ImpermaxChef.json"));
|
|
21
20
|
const ILendingVaultV1_json_1 = __importDefault(require("../abis/contracts/ILendingVaultV1.json"));
|
|
22
21
|
const LendingVaultWatcher01_json_1 = __importDefault(require("../abis/contracts/LendingVaultWatcher01.json"));
|
|
23
22
|
const ImpermaxConfigManager_json_1 = __importDefault(require("../abis/contracts/ImpermaxConfigManager.json"));
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
const
|
|
23
|
+
// Impermax V2
|
|
24
|
+
const IFactory_json_1 = __importDefault(require("../abis/contracts/IFactory.json"));
|
|
25
|
+
const ISimpleUniswapOracle_json_1 = __importDefault(require("../abis/contracts/ISimpleUniswapOracle.json"));
|
|
26
|
+
const IBorrowable_json_1 = __importDefault(require("../abis/contracts/IBorrowable.json"));
|
|
27
|
+
const ICollateral_json_1 = __importDefault(require("../abis/contracts/ICollateral.json"));
|
|
28
|
+
const IStakedLPToken_json_1 = __importDefault(require("../abis/contracts/IStakedLPToken.json"));
|
|
29
|
+
const IRouter02_json_1 = __importDefault(require("../abis/contracts/IRouter02.json"));
|
|
30
|
+
// Impermax V3
|
|
31
|
+
const ImpermaxV3Factory_json_1 = __importDefault(require("../abis/contracts/ImpermaxV3Factory.json"));
|
|
32
|
+
const ImpermaxV3Borrowable_json_1 = __importDefault(require("../abis/contracts/ImpermaxV3Borrowable.json"));
|
|
33
|
+
const ImpermaxV3Collateral_json_1 = __importDefault(require("../abis/contracts/ImpermaxV3Collateral.json"));
|
|
34
|
+
const ImpermaxV3UniV3Router01_json_1 = __importDefault(require("../abis/contracts/ImpermaxV3UniV3Router01.json"));
|
|
35
|
+
const ImpermaxV3UniV2Router01_json_1 = __importDefault(require("../abis/contracts/ImpermaxV3UniV2Router01.json"));
|
|
36
|
+
// Nftlps
|
|
37
|
+
const ITokenizedUniswapV2Position_json_1 = __importDefault(require("../abis/contracts/ITokenizedUniswapV2Position.json"));
|
|
38
|
+
const ITokenizedUniswapV3Position_json_1 = __importDefault(require("../abis/contracts/ITokenizedUniswapV3Position.json"));
|
|
39
|
+
// External
|
|
40
|
+
const IStakingRewards_json_1 = __importDefault(require("../abis/contracts/IStakingRewards.json"));
|
|
41
|
+
const IUniswapV2Pair_json_1 = __importDefault(require("../abis/contracts/IUniswapV2Pair.json"));
|
|
42
|
+
const IUniswapV2Factory_json_1 = __importDefault(require("../abis/contracts/IUniswapV2Factory.json"));
|
|
43
|
+
const IUniswapV3Pool_json_1 = __importDefault(require("../abis/contracts/IUniswapV3Pool.json"));
|
|
27
44
|
class OnchainContractsHelper {
|
|
28
45
|
constructor(onchain) {
|
|
29
46
|
this.newContract = (abi, address) => new this.onchain.web3.eth.Contract(abi, address);
|
|
30
|
-
|
|
31
|
-
this.newFactory = (address) => this.newContract(IFactory_json_1.default.abi, address);
|
|
32
|
-
this.newSimpleUniswapOracle = (address) => this.newContract(ISimpleUniswapOracle_json_1.default.abi, address);
|
|
33
|
-
this.newUniswapV2Pair = (address) => this.newContract(IUniswapV2Pair_json_1.default.abi, address);
|
|
34
|
-
this.newUniswapV2Factory = (address) => this.newContract(IUniswapV2Factory_json_1.default.abi, address);
|
|
47
|
+
// Generic
|
|
35
48
|
this.newERC20 = (address) => this.newContract(IERC20_json_1.default.abi, address);
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
38
|
-
|
|
49
|
+
this.newERC721 = (address) => this.newContract(IERC721_json_1.default.abi, address);
|
|
50
|
+
this.newPermit2 = (address) => this.newContract(IAllowanceTransfer_json_1.default.abi, address);
|
|
51
|
+
// Impermax
|
|
52
|
+
this.newPoolTokenRouter = (address) => this.newContract(PoolTokenRouter01_json_1.default.abi, address);
|
|
39
53
|
this.newMerkleDistributor = (address) => this.newContract(IMerkleDistributor_json_1.default.abi, address);
|
|
40
54
|
this.newFarmingPool = (address) => this.newContract(IFarmingPool_json_1.default.abi, address);
|
|
41
55
|
this.newClaimAggregator = (address) => this.newContract(ClaimAggregator_json_1.default.abi, address);
|
|
@@ -45,6 +59,26 @@ class OnchainContractsHelper {
|
|
|
45
59
|
this.newLendingVault = (address) => this.newContract(ILendingVaultV1_json_1.default.abi, address);
|
|
46
60
|
this.newLendingVaultWatcher = (address) => this.newContract(LendingVaultWatcher01_json_1.default.abi, address);
|
|
47
61
|
this.newImpermaxConfigManager = (address) => this.newContract(ImpermaxConfigManager_json_1.default.abi, address);
|
|
62
|
+
// Impermax V2
|
|
63
|
+
this.newFactoryV2 = (address) => this.newContract(IFactory_json_1.default.abi, address);
|
|
64
|
+
this.newSimpleUniswapOracle = (address) => this.newContract(ISimpleUniswapOracle_json_1.default.abi, address);
|
|
65
|
+
this.newCollateralV2 = (address) => this.newContract(ICollateral_json_1.default.abi, address);
|
|
66
|
+
this.newBorrowableV2 = (address) => this.newContract(IBorrowable_json_1.default.abi, address);
|
|
67
|
+
this.newStakedLPToken = (address) => this.newContract(IStakedLPToken_json_1.default.abi, address);
|
|
68
|
+
this.newRouterV2 = (address) => this.newContract(IRouter02_json_1.default.abi, address);
|
|
69
|
+
// Impermax V3
|
|
70
|
+
this.newFactoryV3 = (address) => this.newContract(ImpermaxV3Factory_json_1.default.abi, address);
|
|
71
|
+
this.newBorrowableV3 = (address) => this.newContract(ImpermaxV3Borrowable_json_1.default.abi, address);
|
|
72
|
+
this.newCollateralV3 = (address) => this.newContract(ImpermaxV3Collateral_json_1.default.abi, address);
|
|
73
|
+
this.newRouterUniV2 = (address) => this.newContract(ImpermaxV3UniV2Router01_json_1.default.abi, address);
|
|
74
|
+
this.newRouterUniV3 = (address) => this.newContract(ImpermaxV3UniV3Router01_json_1.default.abi, address);
|
|
75
|
+
// Nftlps
|
|
76
|
+
this.newNftlpUniV2 = (address) => this.newContract(ITokenizedUniswapV2Position_json_1.default.abi, address);
|
|
77
|
+
this.newNftlpUniV3 = (address) => this.newContract(ITokenizedUniswapV3Position_json_1.default.abi, address);
|
|
78
|
+
// External
|
|
79
|
+
this.newUniswapV2Pair = (address) => this.newContract(IUniswapV2Pair_json_1.default.abi, address);
|
|
80
|
+
this.newUniswapV2Factory = (address) => this.newContract(IUniswapV2Factory_json_1.default.abi, address);
|
|
81
|
+
this.newUniswapV3Pool = (address) => this.newContract(IUniswapV3Pool_json_1.default.abi, address);
|
|
48
82
|
this.onchain = onchain;
|
|
49
83
|
this.impermaxChef = this.newImpermaxChef(impermax_chef_1.IMPERMAX_CHEF[this.onchain.network]);
|
|
50
84
|
this.merkleDistributorIbex = this.newMerkleDistributor(merkle_distributors_1.MERKLE_DISTRIBUTOR_IBEX[this.onchain.network]);
|
|
@@ -2,7 +2,7 @@ import OnchainPoolToken from "./onchainPoolToken";
|
|
|
2
2
|
import { Contract } from "ethers";
|
|
3
3
|
import { Address } from '../config/types';
|
|
4
4
|
import Onchain from './index';
|
|
5
|
-
import
|
|
5
|
+
import OffchainVault from '../offchain/vault/offchainVault';
|
|
6
6
|
export default class OnchainLendingVault extends OnchainPoolToken {
|
|
7
7
|
private readonly onchain;
|
|
8
8
|
private readonly vaultAddress;
|
|
@@ -13,8 +13,8 @@ export default class OnchainLendingVault extends OnchainPoolToken {
|
|
|
13
13
|
getVaultAddress: () => string;
|
|
14
14
|
getContractHelper: () => import("./onchainContractsHelper").default;
|
|
15
15
|
getPoolTokenAddress(): Promise<Address>;
|
|
16
|
-
getOffchainPoolToken(): Promise<
|
|
17
|
-
getOffchainLendingVault: () => Promise<
|
|
16
|
+
getOffchainPoolToken(): Promise<OffchainVault>;
|
|
17
|
+
getOffchainLendingVault: () => Promise<OffchainVault>;
|
|
18
18
|
protected initializePoolToken(): Promise<Contract>;
|
|
19
19
|
protected initializeToken(): Promise<Contract>;
|
|
20
20
|
private initializeAvailableLiquidity;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Contract, Permit, Permits } from "./onchainTypes";
|
|
2
|
+
import Onchain from "./index";
|
|
3
|
+
import { Address } from '../config/types';
|
|
4
|
+
import { BigNumber } from "ethers";
|
|
5
|
+
export default class OnchainPermitHelper {
|
|
6
|
+
private readonly onchain;
|
|
7
|
+
private readonly permit2;
|
|
8
|
+
private readonly deadline;
|
|
9
|
+
constructor(onchain: Onchain);
|
|
10
|
+
encodePermits(permits: Permits): string;
|
|
11
|
+
private getDomainPermit1;
|
|
12
|
+
private getDomainPermit2;
|
|
13
|
+
private getTokenPermitJSONData;
|
|
14
|
+
private getBorrowPermitJSONData;
|
|
15
|
+
private getNftPermitJSONData;
|
|
16
|
+
private getPermit2SingleJSONData;
|
|
17
|
+
private getSignature;
|
|
18
|
+
getTokenPermit(token: Contract, owner: Address, spender: Address, value: BigNumber, callBack: (permit: Permit | null) => void): Promise<void>;
|
|
19
|
+
getNftPermit(token: Contract, owner: Address, spender: Address, tokenId: BigNumber, callBack: (permit: Permit | null) => void): Promise<void>;
|
|
20
|
+
getPermit2Single(token: Contract, owner: Address, spender: Address, value: BigNumber, callBack: (permit: Permit | null) => void): Promise<void>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const ethers_1 = require("ethers");
|
|
13
|
+
const general_1 = require("../config/general");
|
|
14
|
+
const PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
15
|
+
const EIP712_DOMAIN = [
|
|
16
|
+
{ name: "name", type: "string" },
|
|
17
|
+
{ name: "version", type: "string" },
|
|
18
|
+
{ name: "chainId", type: "uint256" },
|
|
19
|
+
{ name: "verifyingContract", type: "address" },
|
|
20
|
+
];
|
|
21
|
+
const PERMIT2_DOMAIN = [
|
|
22
|
+
{ name: "name", type: "string" },
|
|
23
|
+
{ name: "chainId", type: "uint256" },
|
|
24
|
+
{ name: "verifyingContract", type: "address" },
|
|
25
|
+
];
|
|
26
|
+
const PERMIT = [
|
|
27
|
+
{ name: "owner", type: "address" },
|
|
28
|
+
{ name: "spender", type: "address" },
|
|
29
|
+
{ name: "value", type: "uint256" },
|
|
30
|
+
{ name: "nonce", type: "uint256" },
|
|
31
|
+
{ name: "deadline", type: "uint256" },
|
|
32
|
+
];
|
|
33
|
+
const NFT_PERMIT = [
|
|
34
|
+
{ name: "spender", type: "address" },
|
|
35
|
+
{ name: "tokenId", type: "uint256" },
|
|
36
|
+
{ name: "nonce", type: "uint256" },
|
|
37
|
+
{ name: "deadline", type: "uint256" },
|
|
38
|
+
];
|
|
39
|
+
const PERMIT2_DETAILS = [
|
|
40
|
+
{ name: "token", type: "address" },
|
|
41
|
+
{ name: "amount", type: "uint160" },
|
|
42
|
+
{ name: "expiration", type: "uint48" },
|
|
43
|
+
{ name: "nonce", type: "uint48" },
|
|
44
|
+
];
|
|
45
|
+
const PERMIT2_SINGLE = [
|
|
46
|
+
{ name: "details", type: PERMIT2_DETAILS },
|
|
47
|
+
{ name: "spender", type: "address" },
|
|
48
|
+
{ name: "sigDeadline", type: "uint256" },
|
|
49
|
+
];
|
|
50
|
+
const TYPES = {
|
|
51
|
+
EIP712Domain: EIP712_DOMAIN,
|
|
52
|
+
Permit2Domain: PERMIT2_DOMAIN,
|
|
53
|
+
TokenPermit: PERMIT,
|
|
54
|
+
BorrowPermit: PERMIT,
|
|
55
|
+
NftPermit: NFT_PERMIT,
|
|
56
|
+
PermitDetails: PERMIT2_DETAILS,
|
|
57
|
+
PermitSingle: PERMIT2_SINGLE,
|
|
58
|
+
};
|
|
59
|
+
class OnchainPermitHelper {
|
|
60
|
+
// TODO crate new router for V2 otherwise borrowPermit will stop working
|
|
61
|
+
constructor(onchain) {
|
|
62
|
+
this.deadline = general_1.DEADLINE.toString();
|
|
63
|
+
this.getDomainPermit1 = (contract) => __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
return ({
|
|
65
|
+
name: yield contract.methods.name().call(),
|
|
66
|
+
version: "1",
|
|
67
|
+
chainId: this.onchain.chainId,
|
|
68
|
+
verifyingContract: contract._address,
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
this.getDomainPermit2 = () => ({
|
|
72
|
+
name: 'Permit2',
|
|
73
|
+
chainId: this.onchain.chainId,
|
|
74
|
+
verifyingContract: this.permit2._address,
|
|
75
|
+
});
|
|
76
|
+
this.onchain = onchain;
|
|
77
|
+
this.permit2 = onchain.getContractHelper().newPermit2(PERMIT2_ADDRESS);
|
|
78
|
+
}
|
|
79
|
+
encodePermits(permits) {
|
|
80
|
+
if (permits.length == 0 || !permits[0].signature)
|
|
81
|
+
permits = [];
|
|
82
|
+
return ethers_1.ethers.utils.defaultAbiCoder.encode(['tuple(uint256 permitType, bytes permitData, bytes signature)[]'], [permits]);
|
|
83
|
+
}
|
|
84
|
+
getTokenPermitJSONData(contract, message) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const domain = yield this.getDomainPermit1(contract);
|
|
87
|
+
const primaryType = "TokenPermit";
|
|
88
|
+
return JSON.stringify({ types: TYPES, domain, primaryType, message });
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
getBorrowPermitJSONData(contract, message) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
const domain = yield this.getDomainPermit1(contract);
|
|
94
|
+
const primaryType = "BorrowPermit";
|
|
95
|
+
return JSON.stringify({ types: TYPES, domain, primaryType, message });
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
getNftPermitJSONData(contract, message) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const domain = yield this.getDomainPermit1(contract);
|
|
101
|
+
const primaryType = "NftPermit";
|
|
102
|
+
return JSON.stringify({ types: TYPES, domain, primaryType, message });
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
getPermit2SingleJSONData(message) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
const domain = this.getDomainPermit2();
|
|
108
|
+
const primaryType = "PermitSingle";
|
|
109
|
+
return JSON.stringify({ types: TYPES, domain, primaryType, message });
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
getSignature(owner, jsonData, callBack) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
this.onchain.web3.currentProvider.send({
|
|
115
|
+
method: "eth_signTypedData_v4",
|
|
116
|
+
params: [owner, jsonData],
|
|
117
|
+
from: owner
|
|
118
|
+
}, (err, data) => {
|
|
119
|
+
if (err) {
|
|
120
|
+
console.error(err);
|
|
121
|
+
return callBack(null);
|
|
122
|
+
}
|
|
123
|
+
callBack(data.result);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
getTokenPermit(token, owner, spender, value, callBack) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const nonce = yield token.methods.nonces(owner).call();
|
|
130
|
+
const jsonData = yield this.getTokenPermitJSONData(token, {
|
|
131
|
+
owner,
|
|
132
|
+
spender,
|
|
133
|
+
value: value.toString(),
|
|
134
|
+
nonce: ethers_1.BigNumber.from(nonce).toHexString(),
|
|
135
|
+
deadline: this.deadline,
|
|
136
|
+
});
|
|
137
|
+
this.getSignature(owner, jsonData, (signature) => {
|
|
138
|
+
if (!signature)
|
|
139
|
+
return callBack(null);
|
|
140
|
+
callBack({
|
|
141
|
+
permitType: '0',
|
|
142
|
+
permitData: ethers_1.ethers.utils.defaultAbiCoder.encode(['address', 'uint256', 'uint256'], [token.address, value.toString(), this.deadline]),
|
|
143
|
+
signature
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
getNftPermit(token, owner, spender, tokenId, callBack) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
const nonce = yield token.methods.nonces(tokenId).call();
|
|
151
|
+
const jsonData = yield this.getNftPermitJSONData(token, {
|
|
152
|
+
spender,
|
|
153
|
+
tokenId: tokenId.toString(),
|
|
154
|
+
nonce: ethers_1.BigNumber.from(nonce).toHexString(),
|
|
155
|
+
deadline: this.deadline,
|
|
156
|
+
});
|
|
157
|
+
this.getSignature(owner, jsonData, (signature) => {
|
|
158
|
+
if (!signature)
|
|
159
|
+
return callBack(null);
|
|
160
|
+
callBack({
|
|
161
|
+
permitType: '1',
|
|
162
|
+
permitData: ethers_1.ethers.utils.defaultAbiCoder.encode(['address', 'uint256', 'uint256'], [token.address, tokenId.toString(), this.deadline]),
|
|
163
|
+
signature
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
getPermit2Single(token, owner, spender, value, callBack) {
|
|
169
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
const allowanceData = yield this.permit2.methods.allowance(owner, token.address, spender);
|
|
171
|
+
if (!allowanceData)
|
|
172
|
+
return callBack(null);
|
|
173
|
+
const nonce = allowanceData.nonce;
|
|
174
|
+
const permitDetailsType = 'tuple(address tokenAddress, uint160 amount, uint48 expiration, uint48 nonce)';
|
|
175
|
+
const details = {
|
|
176
|
+
token: token._address,
|
|
177
|
+
amount: value.toString(),
|
|
178
|
+
expiration: this.deadline,
|
|
179
|
+
nonce: ethers_1.BigNumber.from(nonce).toHexString(),
|
|
180
|
+
};
|
|
181
|
+
const jsonData = yield this.getPermit2SingleJSONData({
|
|
182
|
+
details,
|
|
183
|
+
spender,
|
|
184
|
+
sigDeadline: this.deadline,
|
|
185
|
+
});
|
|
186
|
+
this.getSignature(owner, jsonData, (signature) => {
|
|
187
|
+
if (!signature)
|
|
188
|
+
return callBack(null);
|
|
189
|
+
callBack({
|
|
190
|
+
permitType: '2',
|
|
191
|
+
permitData: ethers_1.ethers.utils.defaultAbiCoder.encode([permitDetailsType, 'address', 'uint256'], [token, spender, this.deadline]),
|
|
192
|
+
signature
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
exports.default = OnchainPermitHelper;
|