@gearbox-protocol/sdk 13.1.0 → 13.2.0-next.1
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/dist/cjs/abi/310/iSecuritizeDegenNFT.js +263 -0
- package/dist/cjs/abi/310/iSecuritizeKYCFactory.js +278 -0
- package/dist/cjs/{sdk/pools/PoolServiceV310.js → abi/iStateSerializer.js} +14 -8
- package/dist/cjs/dev/AccountOpener.js +45 -5
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +462 -104
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +16 -5
- package/dist/cjs/sdk/base/ChainContractsRegister.js +1 -1
- package/dist/cjs/sdk/base/TokensMeta.js +255 -32
- package/dist/cjs/sdk/base/index.js +2 -0
- package/dist/cjs/sdk/{constants/phantom-tokens.js → base/token-types.js} +9 -3
- package/dist/cjs/sdk/chain/chains.js +2 -1
- package/dist/cjs/sdk/constants/index.js +0 -2
- package/dist/cjs/sdk/market/MarketRegister.js +2 -2
- package/dist/cjs/sdk/market/MarketSuite.js +6 -0
- package/dist/cjs/{plugins/zappers/extraZappers.js → sdk/market/ZapperRegister.js} +110 -6
- package/dist/cjs/sdk/market/index.js +3 -1
- package/dist/cjs/sdk/market/pool/PoolSuite.js +3 -0
- package/dist/cjs/sdk/market/pool/PoolV310Contract.js +17 -2
- package/dist/cjs/sdk/market/pool/SecuritizeKYCFactory.js +97 -0
- package/dist/cjs/sdk/market/pool/index.js +4 -0
- package/dist/cjs/sdk/pools/PoolService.js +391 -0
- package/dist/cjs/sdk/pools/index.js +2 -4
- package/dist/cjs/sdk/utils/AddressMap.js +1 -1
- package/dist/cjs/sdk/utils/viem/sendRawTx.js +16 -0
- package/dist/esm/abi/310/iSecuritizeDegenNFT.js +239 -0
- package/dist/esm/abi/310/iSecuritizeKYCFactory.js +254 -0
- package/dist/esm/abi/iStateSerializer.js +12 -0
- package/dist/esm/dev/AccountOpener.js +47 -6
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +462 -104
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +16 -5
- package/dist/esm/sdk/base/ChainContractsRegister.js +1 -1
- package/dist/esm/sdk/base/TokensMeta.js +261 -32
- package/dist/esm/sdk/base/index.js +1 -0
- package/dist/esm/sdk/{constants/phantom-tokens.js → base/token-types.js} +4 -0
- package/dist/esm/sdk/chain/chains.js +2 -1
- package/dist/esm/sdk/constants/index.js +0 -1
- package/dist/esm/sdk/market/MarketRegister.js +2 -2
- package/dist/esm/sdk/market/MarketSuite.js +6 -0
- package/dist/esm/{plugins/zappers/extraZappers.js → sdk/market/ZapperRegister.js} +109 -2
- package/dist/esm/sdk/market/index.js +1 -0
- package/dist/esm/sdk/market/pool/PoolSuite.js +3 -0
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +17 -2
- package/dist/esm/sdk/market/pool/SecuritizeKYCFactory.js +73 -0
- package/dist/esm/sdk/market/pool/index.js +2 -0
- package/dist/esm/sdk/pools/PoolService.js +371 -0
- package/dist/esm/sdk/pools/index.js +1 -2
- package/dist/esm/sdk/utils/AddressMap.js +1 -1
- package/dist/esm/sdk/utils/viem/sendRawTx.js +19 -1
- package/dist/types/abi/310/iSecuritizeDegenNFT.d.ts +324 -0
- package/dist/types/abi/310/iSecuritizeKYCFactory.d.ts +322 -0
- package/dist/types/abi/iStateSerializer.d.ts +11 -0
- package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +123 -27
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
- package/dist/types/sdk/accounts/types.d.ts +108 -8
- package/dist/types/sdk/base/TokensMeta.d.ts +34 -18
- package/dist/types/sdk/base/index.d.ts +1 -0
- package/dist/types/sdk/base/token-types.d.ts +33 -0
- package/dist/types/sdk/base/types.d.ts +0 -1
- package/dist/types/sdk/chain/chains.d.ts +1 -1
- package/dist/types/sdk/constants/index.d.ts +0 -1
- package/dist/types/sdk/market/MarketRegister.d.ts +2 -2
- package/dist/types/sdk/market/MarketSuite.d.ts +3 -0
- package/dist/types/sdk/market/ZapperRegister.d.ts +17 -0
- package/dist/types/sdk/market/index.d.ts +1 -0
- package/dist/types/sdk/market/pool/PoolSuite.d.ts +2 -0
- package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +6 -2
- package/dist/types/sdk/market/pool/SecuritizeKYCFactory.d.ts +345 -0
- package/dist/types/sdk/market/pool/index.d.ts +2 -0
- package/dist/types/sdk/market/types.d.ts +10 -0
- package/dist/types/sdk/pools/PoolService.d.ts +14 -0
- package/dist/types/sdk/pools/index.d.ts +1 -2
- package/dist/types/sdk/pools/types.d.ts +84 -63
- package/dist/types/sdk/utils/AddressMap.d.ts +1 -1
- package/dist/types/sdk/utils/viem/sendRawTx.d.ts +5 -1
- package/package.json +1 -1
- package/dist/cjs/plugins/zappers/ZappersPlugin.js +0 -144
- package/dist/cjs/plugins/zappers/index.js +0 -26
- package/dist/cjs/plugins/zappers/package.json +0 -1
- package/dist/cjs/sdk/pools/AbstractPoolService.js +0 -137
- package/dist/cjs/sdk/pools/createPoolService.js +0 -35
- package/dist/esm/plugins/zappers/ZappersPlugin.js +0 -126
- package/dist/esm/plugins/zappers/index.js +0 -3
- package/dist/esm/plugins/zappers/package.json +0 -1
- package/dist/esm/sdk/pools/AbstractPoolService.js +0 -113
- package/dist/esm/sdk/pools/PoolServiceV310.js +0 -6
- package/dist/esm/sdk/pools/createPoolService.js +0 -11
- package/dist/types/plugins/zappers/ZappersPlugin.d.ts +0 -18
- package/dist/types/plugins/zappers/extraZappers.d.ts +0 -6
- package/dist/types/plugins/zappers/index.d.ts +0 -3
- package/dist/types/plugins/zappers/types.d.ts +0 -12
- package/dist/types/sdk/constants/phantom-tokens.d.ts +0 -2
- package/dist/types/sdk/pools/AbstractPoolService.d.ts +0 -9
- package/dist/types/sdk/pools/PoolServiceV310.d.ts +0 -4
- package/dist/types/sdk/pools/createPoolService.d.ts +0 -3
- /package/dist/cjs/{plugins/zappers → sdk/market}/types.js +0 -0
- /package/dist/esm/{plugins/zappers → sdk/market}/types.js +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { iSecuritizeDegenNFTAbi } from "../../../abi/310/iSecuritizeDegenNFT.js";
|
|
2
|
+
import { iSecuritizeKYCFactoryAbi } from "../../../abi/310/iSecuritizeKYCFactory.js";
|
|
3
|
+
import { BaseContract } from "../../base/index.js";
|
|
4
|
+
import { AddressMap } from "../../index.js";
|
|
5
|
+
const abi = iSecuritizeKYCFactoryAbi;
|
|
6
|
+
class SecuritizeKYCFactory extends BaseContract {
|
|
7
|
+
investorCache;
|
|
8
|
+
#degenNFT;
|
|
9
|
+
constructor(options, address) {
|
|
10
|
+
super(options, {
|
|
11
|
+
addr: address,
|
|
12
|
+
name: "SecuritizeKYCFactory",
|
|
13
|
+
abi
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
async precomputeWalletAddress(creditManager, investor) {
|
|
17
|
+
return this.contract.read.precomputeWalletAddress([
|
|
18
|
+
creditManager,
|
|
19
|
+
investor
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
22
|
+
async getWallet(creditAccount) {
|
|
23
|
+
return this.contract.read.getWallet([creditAccount]);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns the investor address for a credit account.
|
|
27
|
+
* @param creditAccount - Credit account address
|
|
28
|
+
* @param fromCache - If true, use and update an in-memory cache (creditAccount -> investor). On cache miss, loads from contract and stores the result for future calls.
|
|
29
|
+
*/
|
|
30
|
+
async getInvestor(creditAccount, fromCache) {
|
|
31
|
+
if (fromCache && this.investorCache?.has(creditAccount)) {
|
|
32
|
+
return this.investorCache.get(creditAccount);
|
|
33
|
+
}
|
|
34
|
+
const investor = await this.contract.read.getInvestor([creditAccount]);
|
|
35
|
+
if (fromCache) {
|
|
36
|
+
if (!this.investorCache) {
|
|
37
|
+
this.investorCache = new AddressMap();
|
|
38
|
+
}
|
|
39
|
+
this.investorCache.upsert(creditAccount, investor);
|
|
40
|
+
}
|
|
41
|
+
return investor;
|
|
42
|
+
}
|
|
43
|
+
async getDSTokens() {
|
|
44
|
+
const degenNFT = await this.getDegenNFT();
|
|
45
|
+
const tokens = await this.client.readContract({
|
|
46
|
+
address: degenNFT,
|
|
47
|
+
abi: iSecuritizeDegenNFTAbi,
|
|
48
|
+
functionName: "getDSTokens"
|
|
49
|
+
});
|
|
50
|
+
return [...tokens];
|
|
51
|
+
}
|
|
52
|
+
multicall(creditAccount, calls, tokensToRegister) {
|
|
53
|
+
return this.createRawTx({
|
|
54
|
+
functionName: "multicall",
|
|
55
|
+
args: [creditAccount, calls, tokensToRegister]
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
openCreditAccount(creditManager, calls, tokensToRegister) {
|
|
59
|
+
return this.createRawTx({
|
|
60
|
+
functionName: "openCreditAccount",
|
|
61
|
+
args: [creditManager, calls, tokensToRegister]
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async getDegenNFT() {
|
|
65
|
+
if (!this.#degenNFT) {
|
|
66
|
+
this.#degenNFT = await this.contract.read.getDegenNFT();
|
|
67
|
+
}
|
|
68
|
+
return this.#degenNFT;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
SecuritizeKYCFactory
|
|
73
|
+
};
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import { iPoolV310Abi } from "../../abi/310/generated.js";
|
|
2
|
+
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
3
|
+
import { ierc20ZapperDepositsAbi } from "../../abi/iERC20ZapperDeposits.js";
|
|
4
|
+
import { iethZapperDepositsAbi } from "../../abi/iETHZapperDeposits.js";
|
|
5
|
+
import { iZapperAbi } from "../../abi/iZapper.js";
|
|
6
|
+
import {
|
|
7
|
+
KYC_UNDERLYING_DEFAULT,
|
|
8
|
+
KYC_UNDERLYING_ON_DEMAND,
|
|
9
|
+
SDKConstruct
|
|
10
|
+
} from "../base/index.js";
|
|
11
|
+
import { AddressSet, hexEq } from "../index.js";
|
|
12
|
+
import { AddressMap } from "../utils/index.js";
|
|
13
|
+
const NATIVE_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
14
|
+
const POOL_TOKENS_TO_MIGRATE = new AddressMap([
|
|
15
|
+
// v2 diesels
|
|
16
|
+
["0x6CFaF95457d7688022FC53e7AbE052ef8DFBbdBA", "dDAI"],
|
|
17
|
+
["0xc411dB5f5Eb3f7d552F9B8454B2D74097ccdE6E3", "dUSDC"],
|
|
18
|
+
["0xe753260F1955e8678DCeA8887759e07aa57E8c54", "dWBTC"],
|
|
19
|
+
["0xF21fc650C1B34eb0FDE786D52d23dA99Db3D6278", "dWETH"],
|
|
20
|
+
["0x2158034dB06f06dcB9A786D2F1F8c38781bA779d", "dwstETH"],
|
|
21
|
+
["0x8A1112AFef7F4FC7c066a77AABBc01b3Fff31D47", "dFRAX"]
|
|
22
|
+
]);
|
|
23
|
+
class PoolService extends SDKConstruct {
|
|
24
|
+
getDepositTokensIn(pool) {
|
|
25
|
+
const underlying = this.#describeUnderlying(pool);
|
|
26
|
+
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
27
|
+
switch (underlying.contractType) {
|
|
28
|
+
case KYC_UNDERLYING_DEFAULT:
|
|
29
|
+
return this.#depositTokensIn(pool, false);
|
|
30
|
+
case KYC_UNDERLYING_ON_DEMAND:
|
|
31
|
+
return [underlying.asset];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return this.#depositTokensIn(pool, true);
|
|
35
|
+
}
|
|
36
|
+
getDepositTokensOut(pool, tokenIn) {
|
|
37
|
+
const underlying = this.#describeUnderlying(pool);
|
|
38
|
+
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
39
|
+
switch (underlying.contractType) {
|
|
40
|
+
case KYC_UNDERLYING_DEFAULT:
|
|
41
|
+
return this.#depositTokensOut(pool, tokenIn, false);
|
|
42
|
+
case KYC_UNDERLYING_ON_DEMAND:
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return this.#depositTokensOut(pool, tokenIn, true);
|
|
47
|
+
}
|
|
48
|
+
getDepositMetadata(pool, tokenIn, tokenOut) {
|
|
49
|
+
const underlying = this.#describeUnderlying(pool);
|
|
50
|
+
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
51
|
+
switch (underlying.contractType) {
|
|
52
|
+
case KYC_UNDERLYING_DEFAULT: {
|
|
53
|
+
return this.#depositMetadata(
|
|
54
|
+
"kyc-default",
|
|
55
|
+
pool,
|
|
56
|
+
tokenIn,
|
|
57
|
+
tokenOut,
|
|
58
|
+
false
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
case KYC_UNDERLYING_ON_DEMAND:
|
|
62
|
+
return {
|
|
63
|
+
zapper: void 0,
|
|
64
|
+
approveTarget: underlying.liquidityProvider,
|
|
65
|
+
permissible: false,
|
|
66
|
+
type: "kyc-on-demand"
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return this.#depositMetadata("classic", pool, tokenIn, tokenOut, true);
|
|
71
|
+
}
|
|
72
|
+
addLiquidity(props) {
|
|
73
|
+
const { collateral, meta, permit, referralCode, pool, wallet } = props;
|
|
74
|
+
const underlying = this.#describeUnderlying(pool);
|
|
75
|
+
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
76
|
+
if (underlying.contractType === KYC_UNDERLYING_ON_DEMAND) {
|
|
77
|
+
return void 0;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const { zapper } = meta;
|
|
81
|
+
if (zapper && hexEq(zapper.tokenIn.addr, NATIVE_ADDRESS)) {
|
|
82
|
+
return {
|
|
83
|
+
target: zapper.baseParams.addr,
|
|
84
|
+
abi: iethZapperDepositsAbi,
|
|
85
|
+
functionName: "depositWithReferral",
|
|
86
|
+
args: [wallet, referralCode],
|
|
87
|
+
value: collateral.balance
|
|
88
|
+
};
|
|
89
|
+
} else if (zapper) {
|
|
90
|
+
return permit ? {
|
|
91
|
+
target: zapper.baseParams.addr,
|
|
92
|
+
abi: ierc20ZapperDepositsAbi,
|
|
93
|
+
functionName: "depositWithReferralAndPermit",
|
|
94
|
+
args: [
|
|
95
|
+
collateral.balance,
|
|
96
|
+
wallet,
|
|
97
|
+
referralCode,
|
|
98
|
+
permit.deadline,
|
|
99
|
+
permit.v,
|
|
100
|
+
permit.r,
|
|
101
|
+
permit.s
|
|
102
|
+
]
|
|
103
|
+
} : {
|
|
104
|
+
target: zapper.baseParams.addr,
|
|
105
|
+
abi: ierc20ZapperDepositsAbi,
|
|
106
|
+
functionName: "depositWithReferral",
|
|
107
|
+
args: [collateral.balance, wallet, referralCode]
|
|
108
|
+
};
|
|
109
|
+
} else {
|
|
110
|
+
return {
|
|
111
|
+
target: pool,
|
|
112
|
+
abi: iPoolV310Abi,
|
|
113
|
+
functionName: "depositWithReferral",
|
|
114
|
+
args: [collateral.balance, wallet, referralCode]
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
getWithdrawalTokensIn(pool) {
|
|
119
|
+
const underlying = this.#describeUnderlying(pool);
|
|
120
|
+
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
121
|
+
switch (underlying.contractType) {
|
|
122
|
+
case KYC_UNDERLYING_DEFAULT:
|
|
123
|
+
return this.#withdrawalTokensIn(pool, false);
|
|
124
|
+
case KYC_UNDERLYING_ON_DEMAND:
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return this.#withdrawalTokensIn(pool, true);
|
|
129
|
+
}
|
|
130
|
+
getWithdrawalTokensOut(pool, tokenIn) {
|
|
131
|
+
const underlying = this.#describeUnderlying(pool);
|
|
132
|
+
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
133
|
+
switch (underlying.contractType) {
|
|
134
|
+
case KYC_UNDERLYING_DEFAULT:
|
|
135
|
+
return this.#withdrawalTokensOut(pool, tokenIn, false);
|
|
136
|
+
case KYC_UNDERLYING_ON_DEMAND:
|
|
137
|
+
return [underlying.asset];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return this.#withdrawalTokensOut(pool, tokenIn, true);
|
|
141
|
+
}
|
|
142
|
+
removeLiquidity(props) {
|
|
143
|
+
const { pool, amount, meta, wallet, permit } = props;
|
|
144
|
+
const underlying = this.#describeUnderlying(pool);
|
|
145
|
+
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
146
|
+
if (underlying.contractType === KYC_UNDERLYING_ON_DEMAND) {
|
|
147
|
+
return {
|
|
148
|
+
abi: ierc20Abi,
|
|
149
|
+
functionName: "approve",
|
|
150
|
+
args: [underlying.liquidityProvider, 0n],
|
|
151
|
+
target: underlying.asset
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (meta.zapper) {
|
|
156
|
+
return permit ? {
|
|
157
|
+
target: meta.zapper.baseParams.addr,
|
|
158
|
+
abi: iZapperAbi,
|
|
159
|
+
functionName: "redeemWithPermit",
|
|
160
|
+
args: [
|
|
161
|
+
amount,
|
|
162
|
+
wallet,
|
|
163
|
+
permit.deadline,
|
|
164
|
+
permit.v,
|
|
165
|
+
permit.r,
|
|
166
|
+
permit.s
|
|
167
|
+
]
|
|
168
|
+
} : {
|
|
169
|
+
target: meta.zapper.baseParams.addr,
|
|
170
|
+
abi: iZapperAbi,
|
|
171
|
+
functionName: "redeem",
|
|
172
|
+
args: [amount, wallet]
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
target: pool,
|
|
177
|
+
abi: iPoolV310Abi,
|
|
178
|
+
functionName: "redeem",
|
|
179
|
+
args: [amount, wallet, wallet]
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
getWithdrawalMetadata(pool, tokenIn, tokenOut) {
|
|
183
|
+
const underlying = this.#describeUnderlying(pool);
|
|
184
|
+
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
185
|
+
switch (underlying.contractType) {
|
|
186
|
+
case KYC_UNDERLYING_DEFAULT: {
|
|
187
|
+
return this.#withdrawalMetadata(
|
|
188
|
+
"kyc-default",
|
|
189
|
+
pool,
|
|
190
|
+
tokenIn,
|
|
191
|
+
tokenOut,
|
|
192
|
+
false
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
case KYC_UNDERLYING_ON_DEMAND:
|
|
196
|
+
return {
|
|
197
|
+
zapper: void 0,
|
|
198
|
+
approveTarget: void 0,
|
|
199
|
+
permissible: false,
|
|
200
|
+
type: "kyc-on-demand"
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return this.#withdrawalMetadata("classic", pool, tokenIn, tokenOut, true);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Filter out v2 diesel tokens (can come from migration v2 -> v3 zappers)
|
|
208
|
+
* Also omits "migration" zappers (v3 -> v3.1) since they are treated in a different way
|
|
209
|
+
*/
|
|
210
|
+
#getDepositZappers(poolAddr) {
|
|
211
|
+
const zappers = this.sdk.marketRegister.poolZappers(poolAddr);
|
|
212
|
+
return zappers.filter(
|
|
213
|
+
(z) => z.type !== "migration" && !POOL_TOKENS_TO_MIGRATE.has(z.tokenIn.addr)
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
#depositTokensIn(poolAddr, allowDirectDeposit) {
|
|
217
|
+
const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
|
|
218
|
+
const result = new AddressSet();
|
|
219
|
+
if (allowDirectDeposit) {
|
|
220
|
+
result.add(pool.underlying);
|
|
221
|
+
}
|
|
222
|
+
const zappers = this.#getDepositZappers(poolAddr);
|
|
223
|
+
for (const z of zappers) {
|
|
224
|
+
if (hexEq(z.tokenOut.addr, poolAddr)) {
|
|
225
|
+
result.add(z.tokenIn.addr);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (result.size === 0) {
|
|
229
|
+
throw new Error(
|
|
230
|
+
`No tokensIn found for pool ${this.labelAddress(poolAddr)}`
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
return result.asArray();
|
|
234
|
+
}
|
|
235
|
+
#withdrawalTokensIn(poolAddr, allowDirectDeposit) {
|
|
236
|
+
const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
|
|
237
|
+
const result = new AddressSet();
|
|
238
|
+
if (allowDirectDeposit && pool) {
|
|
239
|
+
result.add(poolAddr);
|
|
240
|
+
}
|
|
241
|
+
const zappers = this.#getDepositZappers(poolAddr);
|
|
242
|
+
for (const z of zappers) {
|
|
243
|
+
result.add(z.tokenOut.addr);
|
|
244
|
+
}
|
|
245
|
+
if (result.size === 0) {
|
|
246
|
+
throw new Error(
|
|
247
|
+
`No tokensIn found for pool ${this.labelAddress(poolAddr)}`
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
return result.asArray();
|
|
251
|
+
}
|
|
252
|
+
#depositTokensOut(poolAddr, tokenIn, allowDirectDeposit) {
|
|
253
|
+
const result = new AddressSet();
|
|
254
|
+
const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
|
|
255
|
+
const zappers = this.#getDepositZappers(poolAddr);
|
|
256
|
+
for (const z of zappers) {
|
|
257
|
+
if (hexEq(z.tokenIn.addr, tokenIn)) {
|
|
258
|
+
result.add(z.tokenOut.addr);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (allowDirectDeposit && hexEq(tokenIn, pool.underlying)) {
|
|
262
|
+
result.add(poolAddr);
|
|
263
|
+
}
|
|
264
|
+
if (result.size === 0) {
|
|
265
|
+
throw new Error(
|
|
266
|
+
`No tokensOut found for tokenIn ${this.labelAddress(
|
|
267
|
+
tokenIn
|
|
268
|
+
)} on pool ${this.labelAddress(poolAddr)}`
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
const r = result.asArray();
|
|
272
|
+
return r;
|
|
273
|
+
}
|
|
274
|
+
#withdrawalTokensOut(poolAddr, tokenIn, allowDirectDeposit) {
|
|
275
|
+
const result = new AddressSet();
|
|
276
|
+
const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
|
|
277
|
+
const zappers = this.#getDepositZappers(poolAddr);
|
|
278
|
+
for (const z of zappers) {
|
|
279
|
+
if (hexEq(z.tokenOut.addr, tokenIn)) {
|
|
280
|
+
result.add(z.tokenIn.addr);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (allowDirectDeposit && hexEq(tokenIn, poolAddr)) {
|
|
284
|
+
result.add(pool.underlying);
|
|
285
|
+
}
|
|
286
|
+
if (result.size === 0) {
|
|
287
|
+
throw new Error(
|
|
288
|
+
`No tokensOut found for tokenIn ${this.labelAddress(
|
|
289
|
+
tokenIn
|
|
290
|
+
)} on pool ${this.labelAddress(poolAddr)}`
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
const r = result.asArray();
|
|
294
|
+
return r;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Filter out v2 diesel tokens (can come from migration v2 -> v3 zappers)
|
|
298
|
+
* Also omits "migration" zappers (v3 -> v3.1) since they are treated in a different way
|
|
299
|
+
*/
|
|
300
|
+
#getDepositZapper(poolAddr, tokenIn, tokenOut) {
|
|
301
|
+
const zappers = this.sdk.marketRegister.getZapper(poolAddr, tokenIn, tokenOut)?.filter(
|
|
302
|
+
(z) => z.type !== "migration" && !POOL_TOKENS_TO_MIGRATE.has(z.tokenIn.addr)
|
|
303
|
+
);
|
|
304
|
+
if (zappers && zappers.length > 1) {
|
|
305
|
+
throw new Error(
|
|
306
|
+
`Multiple zappers found for tokenIn ${this.labelAddress(
|
|
307
|
+
tokenIn
|
|
308
|
+
)} and tokenOut ${this.labelAddress(
|
|
309
|
+
tokenOut
|
|
310
|
+
)} on pool ${this.labelAddress(poolAddr)}`
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
return zappers?.[0];
|
|
314
|
+
}
|
|
315
|
+
#depositMetadata(type, poolAddr, tokenIn, tokenOut, allowDirectDeposit) {
|
|
316
|
+
if (!tokenOut) {
|
|
317
|
+
throw new Error("tokenOut is required for classic pool deposit");
|
|
318
|
+
}
|
|
319
|
+
const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
|
|
320
|
+
const zapper = this.#getDepositZapper(poolAddr, tokenIn, tokenOut);
|
|
321
|
+
if (!zapper && !allowDirectDeposit) {
|
|
322
|
+
throw new Error(
|
|
323
|
+
`No zapper found for tokenIn ${this.labelAddress(
|
|
324
|
+
tokenIn
|
|
325
|
+
)} and tokenOut ${this.labelAddress(
|
|
326
|
+
tokenOut
|
|
327
|
+
)} on pool ${this.labelAddress(poolAddr)}`
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
zapper,
|
|
332
|
+
// zapper or pool itself
|
|
333
|
+
approveTarget: zapper?.baseParams.addr ?? pool.pool.address,
|
|
334
|
+
// TODO: instead of permissible, return permitType зависимости от tokenIn
|
|
335
|
+
// "none" | "eip2612" | "dai_like";
|
|
336
|
+
permissible: !!zapper && !hexEq(tokenIn, NATIVE_ADDRESS),
|
|
337
|
+
type
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
#withdrawalMetadata(type, poolAddr, tokenIn, tokenOut, allowDirectDeposit) {
|
|
341
|
+
if (!tokenOut) {
|
|
342
|
+
throw new Error("tokenOut is required for classic pool deposit");
|
|
343
|
+
}
|
|
344
|
+
const zapper = this.#getDepositZapper(poolAddr, tokenOut, tokenIn);
|
|
345
|
+
if (!zapper && !allowDirectDeposit) {
|
|
346
|
+
throw new Error(
|
|
347
|
+
`No zapper found for tokenIn ${this.labelAddress(
|
|
348
|
+
tokenOut
|
|
349
|
+
)} and tokenOut ${this.labelAddress(
|
|
350
|
+
tokenIn
|
|
351
|
+
)} on pool ${this.labelAddress(poolAddr)}`
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
return {
|
|
355
|
+
zapper,
|
|
356
|
+
// zapper or pool itself
|
|
357
|
+
approveTarget: zapper?.baseParams.addr,
|
|
358
|
+
// TODO: instead of permissible, return permitType зависимости от tokenIn
|
|
359
|
+
// "none" | "eip2612" | "dai_like";
|
|
360
|
+
permissible: !!zapper,
|
|
361
|
+
type
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
#describeUnderlying(pool) {
|
|
365
|
+
const market = this.sdk.marketRegister.findByPool(pool);
|
|
366
|
+
return this.sdk.tokensMeta.mustGet(market.underlying);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
export {
|
|
370
|
+
PoolService
|
|
371
|
+
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
estimateGas,
|
|
3
|
+
sendTransaction
|
|
4
|
+
} from "viem/actions";
|
|
2
5
|
import { getAction } from "viem/utils";
|
|
3
6
|
async function sendRawTx(client, params) {
|
|
4
7
|
const { tx, ...rest } = params;
|
|
@@ -13,6 +16,21 @@ async function sendRawTx(client, params) {
|
|
|
13
16
|
value: BigInt(tx.value)
|
|
14
17
|
});
|
|
15
18
|
}
|
|
19
|
+
async function estimateRawTxGas(client, params) {
|
|
20
|
+
const { tx, ...rest } = params;
|
|
21
|
+
return getAction(
|
|
22
|
+
client,
|
|
23
|
+
estimateGas,
|
|
24
|
+
"estimateGas"
|
|
25
|
+
)({
|
|
26
|
+
...rest,
|
|
27
|
+
account: params.account,
|
|
28
|
+
data: tx.callData,
|
|
29
|
+
to: tx.to,
|
|
30
|
+
value: BigInt(tx.value)
|
|
31
|
+
});
|
|
32
|
+
}
|
|
16
33
|
export {
|
|
34
|
+
estimateRawTxGas,
|
|
17
35
|
sendRawTx
|
|
18
36
|
};
|