@gearbox-protocol/sdk 12.8.0 → 13.0.0-next.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/dist/cjs/{sdk/pools/PoolServiceV310.js → abi/iStateSerializer.js} +14 -8
- package/dist/cjs/sdk/base/TokensMeta.js +111 -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/constants/index.js +0 -2
- package/dist/cjs/sdk/market/MarketRegister.js +2 -2
- package/dist/cjs/sdk/market/MarketSuite.js +3 -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/pools/PoolService.js +270 -0
- package/dist/cjs/sdk/pools/index.js +2 -4
- package/dist/esm/abi/iStateSerializer.js +12 -0
- package/dist/esm/sdk/base/TokensMeta.js +118 -33
- 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/constants/index.js +0 -1
- package/dist/esm/sdk/market/MarketRegister.js +2 -2
- package/dist/esm/sdk/market/MarketSuite.js +3 -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/pools/PoolService.js +250 -0
- package/dist/esm/sdk/pools/index.js +1 -2
- package/dist/types/abi/iStateSerializer.d.ts +11 -0
- package/dist/types/sdk/base/TokensMeta.d.ts +11 -18
- package/dist/types/sdk/base/index.d.ts +1 -0
- package/dist/types/sdk/base/token-types.d.ts +25 -0
- package/dist/types/sdk/base/types.d.ts +0 -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 +1 -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/types.d.ts +10 -0
- package/dist/types/sdk/pools/PoolService.d.ts +11 -0
- package/dist/types/sdk/pools/index.d.ts +1 -2
- package/dist/types/sdk/pools/types.d.ts +63 -57
- package/dist/types/sdk/sdk-legacy/payload/pool.d.ts +3 -2
- package/package.json +3 -3
- package/dist/cjs/plugins/zappers/ZappersPlugin.js +0 -143
- 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/PoolServiceV300.js +0 -30
- package/dist/cjs/sdk/pools/createPoolService.js +0 -39
- package/dist/esm/plugins/zappers/ZappersPlugin.js +0 -125
- 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/PoolServiceV300.js +0 -6
- package/dist/esm/sdk/pools/PoolServiceV310.js +0 -6
- package/dist/esm/sdk/pools/createPoolService.js +0 -15
- 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/PoolServiceV300.d.ts +0 -4
- package/dist/types/sdk/pools/PoolServiceV310.d.ts +0 -4
- package/dist/types/sdk/pools/createPoolService.d.ts +0 -8
- /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,250 @@
|
|
|
1
|
+
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
2
|
+
import { ierc20ZapperDepositsAbi } from "../../abi/iERC20ZapperDeposits.js";
|
|
3
|
+
import { iethZapperDepositsAbi } from "../../abi/iETHZapperDeposits.js";
|
|
4
|
+
import { iZapperAbi } from "../../abi/iZapper.js";
|
|
5
|
+
import { iPoolV300Abi } from "../../abi/v300.js";
|
|
6
|
+
import {
|
|
7
|
+
KYC_UNDERLYING_DEFAULT,
|
|
8
|
+
KYC_UNDERLYING_ON_DEMAND,
|
|
9
|
+
SDKConstruct
|
|
10
|
+
} from "../base/index.js";
|
|
11
|
+
import { AddressMap, AddressSet, hexEq } from "../index.js";
|
|
12
|
+
const NATIVE_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
13
|
+
const POOL_TOKENS_TO_MIGRATE = new AddressMap([
|
|
14
|
+
// v2 diesels
|
|
15
|
+
["0x6CFaF95457d7688022FC53e7AbE052ef8DFBbdBA", "dDAI"],
|
|
16
|
+
["0xc411dB5f5Eb3f7d552F9B8454B2D74097ccdE6E3", "dUSDC"],
|
|
17
|
+
["0xe753260F1955e8678DCeA8887759e07aa57E8c54", "dWBTC"],
|
|
18
|
+
["0xF21fc650C1B34eb0FDE786D52d23dA99Db3D6278", "dWETH"],
|
|
19
|
+
["0x2158034dB06f06dcB9A786D2F1F8c38781bA779d", "dwstETH"],
|
|
20
|
+
["0x8A1112AFef7F4FC7c066a77AABBc01b3Fff31D47", "dFRAX"]
|
|
21
|
+
]);
|
|
22
|
+
class PoolService extends SDKConstruct {
|
|
23
|
+
getDepositTokensIn(pool) {
|
|
24
|
+
const underlying = this.#describeUnderlying(pool);
|
|
25
|
+
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
26
|
+
switch (underlying.contractType) {
|
|
27
|
+
case KYC_UNDERLYING_DEFAULT:
|
|
28
|
+
return this.#depositTokensIn(pool, false);
|
|
29
|
+
case KYC_UNDERLYING_ON_DEMAND:
|
|
30
|
+
return [underlying.asset];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return this.#depositTokensIn(pool, true);
|
|
34
|
+
}
|
|
35
|
+
getDepositTokensOut(pool, tokenIn) {
|
|
36
|
+
const underlying = this.#describeUnderlying(pool);
|
|
37
|
+
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
38
|
+
switch (underlying.contractType) {
|
|
39
|
+
case KYC_UNDERLYING_DEFAULT:
|
|
40
|
+
return this.#depositTokensOut(pool, tokenIn, false);
|
|
41
|
+
case KYC_UNDERLYING_ON_DEMAND:
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return this.#depositTokensOut(pool, tokenIn, true);
|
|
46
|
+
}
|
|
47
|
+
getDepositMetadata(pool, tokenIn, tokenOut) {
|
|
48
|
+
const underlying = this.#describeUnderlying(pool);
|
|
49
|
+
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
50
|
+
switch (underlying.contractType) {
|
|
51
|
+
case KYC_UNDERLYING_DEFAULT: {
|
|
52
|
+
return this.#depositMetadata(
|
|
53
|
+
"kyc-default",
|
|
54
|
+
pool,
|
|
55
|
+
tokenIn,
|
|
56
|
+
tokenOut,
|
|
57
|
+
false
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
case KYC_UNDERLYING_ON_DEMAND:
|
|
61
|
+
return {
|
|
62
|
+
zapper: void 0,
|
|
63
|
+
approveTarget: underlying.liquidityProvider,
|
|
64
|
+
permissible: false,
|
|
65
|
+
type: "kyc-on-demand"
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return this.#depositMetadata("classic", pool, tokenIn, tokenOut, true);
|
|
70
|
+
}
|
|
71
|
+
addLiquidity(props) {
|
|
72
|
+
const { collateral, meta, permit, referralCode, pool, wallet } = props;
|
|
73
|
+
const underlying = this.#describeUnderlying(pool);
|
|
74
|
+
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
75
|
+
if (underlying.contractType === KYC_UNDERLYING_ON_DEMAND) {
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const { zapper } = meta;
|
|
80
|
+
if (zapper?.tokenIn.addr?.toLowerCase() === NATIVE_ADDRESS.toLowerCase()) {
|
|
81
|
+
return {
|
|
82
|
+
target: zapper.baseParams.addr,
|
|
83
|
+
abi: iethZapperDepositsAbi,
|
|
84
|
+
functionName: "depositWithReferral",
|
|
85
|
+
args: [wallet, referralCode],
|
|
86
|
+
value: collateral.balance
|
|
87
|
+
};
|
|
88
|
+
} else if (zapper) {
|
|
89
|
+
return permit ? {
|
|
90
|
+
target: zapper.baseParams.addr,
|
|
91
|
+
abi: ierc20ZapperDepositsAbi,
|
|
92
|
+
functionName: "depositWithReferralAndPermit",
|
|
93
|
+
args: [
|
|
94
|
+
collateral.balance,
|
|
95
|
+
wallet,
|
|
96
|
+
referralCode,
|
|
97
|
+
permit.deadline,
|
|
98
|
+
permit.v,
|
|
99
|
+
permit.r,
|
|
100
|
+
permit.s
|
|
101
|
+
]
|
|
102
|
+
} : {
|
|
103
|
+
target: zapper.baseParams.addr,
|
|
104
|
+
abi: ierc20ZapperDepositsAbi,
|
|
105
|
+
functionName: "depositWithReferral",
|
|
106
|
+
args: [collateral.balance, wallet, referralCode]
|
|
107
|
+
};
|
|
108
|
+
} else {
|
|
109
|
+
return {
|
|
110
|
+
target: pool,
|
|
111
|
+
abi: iPoolV300Abi,
|
|
112
|
+
functionName: "depositWithReferral",
|
|
113
|
+
args: [collateral.balance, wallet, referralCode]
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
removeLiquidity(props) {
|
|
118
|
+
const { pool, amount, account, zapper, permit } = props;
|
|
119
|
+
const underlying = this.#describeUnderlying(pool);
|
|
120
|
+
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
121
|
+
if (underlying.contractType === KYC_UNDERLYING_ON_DEMAND) {
|
|
122
|
+
return {
|
|
123
|
+
abi: ierc20Abi,
|
|
124
|
+
functionName: "approve",
|
|
125
|
+
args: [underlying.liquidityProvider, 0n],
|
|
126
|
+
target: underlying.asset
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (zapper) {
|
|
131
|
+
return permit ? {
|
|
132
|
+
target: zapper.zapper,
|
|
133
|
+
abi: iZapperAbi,
|
|
134
|
+
functionName: "redeemWithPermit",
|
|
135
|
+
args: [
|
|
136
|
+
amount,
|
|
137
|
+
account,
|
|
138
|
+
permit.deadline,
|
|
139
|
+
permit.v,
|
|
140
|
+
permit.r,
|
|
141
|
+
permit.s
|
|
142
|
+
]
|
|
143
|
+
} : {
|
|
144
|
+
target: zapper.zapper,
|
|
145
|
+
abi: iZapperAbi,
|
|
146
|
+
functionName: "redeem",
|
|
147
|
+
args: [amount, account]
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
target: pool,
|
|
152
|
+
abi: iPoolV300Abi,
|
|
153
|
+
functionName: "redeem",
|
|
154
|
+
args: [amount, account, account]
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
#getDepositZappers(poolAddr) {
|
|
158
|
+
const zappers = this.sdk.marketRegister.poolZappers(poolAddr);
|
|
159
|
+
return zappers.filter((z) => z.type !== "migration");
|
|
160
|
+
}
|
|
161
|
+
#depositTokensIn(poolAddr, allowDirectDeposit) {
|
|
162
|
+
const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
|
|
163
|
+
const result = new AddressSet();
|
|
164
|
+
if (allowDirectDeposit) {
|
|
165
|
+
result.add(pool.underlying);
|
|
166
|
+
}
|
|
167
|
+
const zappers = this.#getDepositZappers(poolAddr);
|
|
168
|
+
for (const z of zappers) {
|
|
169
|
+
if (hexEq(z.tokenOut.addr, poolAddr)) {
|
|
170
|
+
result.add(z.tokenIn.addr);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (result.size === 0) {
|
|
174
|
+
throw new Error(
|
|
175
|
+
`No tokensIn found for pool ${this.labelAddress(poolAddr)}`
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
return result.asArray();
|
|
179
|
+
}
|
|
180
|
+
#depositTokensOut(poolAddr, tokenIn, allowDirectDeposit) {
|
|
181
|
+
const result = new AddressSet();
|
|
182
|
+
const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
|
|
183
|
+
const zappers = this.#getDepositZappers(poolAddr);
|
|
184
|
+
for (const z of zappers) {
|
|
185
|
+
if (hexEq(z.tokenIn.addr, tokenIn)) {
|
|
186
|
+
if (!hexEq(z.tokenOut.addr, poolAddr)) {
|
|
187
|
+
console.log("found", "z.tokenOut.addr", z.tokenOut.addr);
|
|
188
|
+
}
|
|
189
|
+
result.add(z.tokenOut.addr);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (allowDirectDeposit && hexEq(tokenIn, pool.underlying)) {
|
|
193
|
+
result.add(poolAddr);
|
|
194
|
+
}
|
|
195
|
+
if (result.size === 0) {
|
|
196
|
+
throw new Error(
|
|
197
|
+
`No tokensOut found for tokenIn ${this.labelAddress(
|
|
198
|
+
tokenIn
|
|
199
|
+
)} on pool ${this.labelAddress(poolAddr)}`
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
const r = result.asArray().filter((t) => !POOL_TOKENS_TO_MIGRATE.has(t));
|
|
203
|
+
return r;
|
|
204
|
+
}
|
|
205
|
+
#getDepositZapper(poolAddr, tokenIn, tokenOut) {
|
|
206
|
+
const zappers = this.sdk.marketRegister.getZapper(poolAddr, tokenIn, tokenOut)?.filter((z) => z.type !== "migration");
|
|
207
|
+
if (zappers && zappers.length > 1) {
|
|
208
|
+
throw new Error(
|
|
209
|
+
`Multiple zappers found for tokenIn ${this.labelAddress(
|
|
210
|
+
tokenIn
|
|
211
|
+
)} and tokenOut ${this.labelAddress(
|
|
212
|
+
tokenOut
|
|
213
|
+
)} on pool ${this.labelAddress(poolAddr)}`
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
return zappers?.[0];
|
|
217
|
+
}
|
|
218
|
+
#depositMetadata(type, poolAddr, tokenIn, tokenOut, allowDirectDeposit) {
|
|
219
|
+
if (!tokenOut) {
|
|
220
|
+
throw new Error("tokenOut is required for classic pool deposit");
|
|
221
|
+
}
|
|
222
|
+
const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
|
|
223
|
+
const zapper = this.#getDepositZapper(poolAddr, tokenIn, tokenOut);
|
|
224
|
+
if (!zapper && !allowDirectDeposit) {
|
|
225
|
+
throw new Error(
|
|
226
|
+
`No zapper found for tokenIn ${this.labelAddress(
|
|
227
|
+
tokenIn
|
|
228
|
+
)} and tokenOut ${this.labelAddress(
|
|
229
|
+
tokenOut
|
|
230
|
+
)} on pool ${this.labelAddress(poolAddr)}`
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
zapper,
|
|
235
|
+
// zapper or pool itself
|
|
236
|
+
approveTarget: zapper?.baseParams.addr ?? pool.pool.address,
|
|
237
|
+
// TODO: instead of permissible, return permitType зависимости от tokenIn
|
|
238
|
+
// "none" | "eip2612" | "dai_like";
|
|
239
|
+
permissible: !!zapper && tokenIn !== NATIVE_ADDRESS,
|
|
240
|
+
type
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
#describeUnderlying(pool) {
|
|
244
|
+
const market = this.sdk.marketRegister.findByPool(pool);
|
|
245
|
+
return this.sdk.tokensMeta.mustGet(market.underlying);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
export {
|
|
249
|
+
PoolService
|
|
250
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const iStateSerializerAbi: readonly [{
|
|
2
|
+
readonly type: "function";
|
|
3
|
+
readonly inputs: readonly [];
|
|
4
|
+
readonly name: "serialize";
|
|
5
|
+
readonly outputs: readonly [{
|
|
6
|
+
readonly name: "serializedData";
|
|
7
|
+
readonly internalType: "bytes";
|
|
8
|
+
readonly type: "bytes";
|
|
9
|
+
}];
|
|
10
|
+
readonly stateMutability: "view";
|
|
11
|
+
}];
|
|
@@ -1,40 +1,33 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type PhantomTokenContractType } from "../index.js";
|
|
1
|
+
import { type Address, type Chain, type PublicClient, type Transport } from "viem";
|
|
3
2
|
import type { Asset } from "../router/index.js";
|
|
4
3
|
import { AddressMap } from "../utils/index.js";
|
|
5
|
-
import type { TokenMetaData } from "./types.js";
|
|
4
|
+
import type { KYCTokenMeta, PhantomTokenMeta, TokenMetaData } from "./token-types.js";
|
|
6
5
|
export interface FormatBNOptions {
|
|
7
6
|
precision?: number;
|
|
8
7
|
symbol?: boolean;
|
|
9
8
|
}
|
|
10
|
-
export
|
|
11
|
-
/**
|
|
12
|
-
* Undefined if token is not a phantom token
|
|
13
|
-
*/
|
|
14
|
-
phantomTokenType?: PhantomTokenContractType;
|
|
15
|
-
}
|
|
16
|
-
export declare class TokensMeta extends AddressMap<TokenMetaDataExtended> {
|
|
9
|
+
export declare class TokensMeta extends AddressMap<TokenMetaData> {
|
|
17
10
|
#private;
|
|
18
11
|
constructor(client: PublicClient<Transport, Chain>);
|
|
19
12
|
reset(): void;
|
|
20
13
|
symbol(token: Address): string;
|
|
21
14
|
decimals(token: Address): number;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* Throws if the phantom token data is not loaded
|
|
25
|
-
*/
|
|
26
|
-
phantomTokenType(token: Address): PhantomTokenContractType | undefined;
|
|
15
|
+
isPhantomToken(t: TokenMetaData): t is PhantomTokenMeta;
|
|
16
|
+
isKYCUnderlying(t: TokenMetaData): t is KYCTokenMeta;
|
|
27
17
|
/**
|
|
28
18
|
* Returns a map of all phantom tokens
|
|
29
19
|
* Throws if the phantom token data is not loaded
|
|
30
20
|
*/
|
|
31
|
-
get phantomTokens(): AddressMap<
|
|
21
|
+
get phantomTokens(): AddressMap<PhantomTokenMeta>;
|
|
22
|
+
get kycUnderlyings(): AddressMap<KYCTokenMeta>;
|
|
32
23
|
formatBN(asset: Asset, options?: FormatBNOptions): string;
|
|
33
24
|
formatBN(token: Address, amount: number | bigint | string | undefined, options?: FormatBNOptions): string;
|
|
34
25
|
findBySymbol(symbol: string): TokenMetaData | undefined;
|
|
35
26
|
mustFindBySymbol(symbol: string): TokenMetaData;
|
|
36
27
|
/**
|
|
37
|
-
* Loads phantom token
|
|
28
|
+
* Loads token information about phantom token and KYC underlying tokens
|
|
29
|
+
*
|
|
30
|
+
* @param tokens - tokens to load data for, defaults to all tokens
|
|
38
31
|
*/
|
|
39
|
-
|
|
32
|
+
loadTokenData(...tokens: Address[]): Promise<void>;
|
|
40
33
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { MarketData, Unarray } from "./types.js";
|
|
3
|
+
export type SimpleTokenMeta = Unarray<MarketData["tokens"]>;
|
|
4
|
+
export declare const PHANTOM_TOKEN_CONTRACT_TYPES: readonly ["PHANTOM_TOKEN::CONVEX", "PHANTOM_TOKEN::INFINIFI_UNWIND", "PHANTOM_TOKEN::INFRARED", "PHANTOM_TOKEN::MELLOW_WITHDRAWAL", "PHANTOM_TOKEN::MIDAS_REDEMPTION", "PHANTOM_TOKEN::STAKING_REWARDS", "PHANTOM_TOKEN::UPSHIFT_WITHDRAW"];
|
|
5
|
+
export declare const KYC_UNDERLYING_DEFAULT = "KYC_UNDERLYING::DEFAULT";
|
|
6
|
+
export declare const KYC_UNDERLYING_ON_DEMAND = "KYC_UNDERLYING::ON_DEMAND";
|
|
7
|
+
export type KYCUnderlyingContractType = typeof KYC_UNDERLYING_DEFAULT | typeof KYC_UNDERLYING_ON_DEMAND;
|
|
8
|
+
export type PhantomTokenContractType = (typeof PHANTOM_TOKEN_CONTRACT_TYPES)[number];
|
|
9
|
+
export type PhantomTokenMeta = SimpleTokenMeta & {
|
|
10
|
+
contractType: PhantomTokenContractType;
|
|
11
|
+
};
|
|
12
|
+
export type KYCDefaultTokenMeta = SimpleTokenMeta & {
|
|
13
|
+
contractType: typeof KYC_UNDERLYING_DEFAULT;
|
|
14
|
+
kycFactory: Address;
|
|
15
|
+
asset: Address;
|
|
16
|
+
};
|
|
17
|
+
export type KYCOnDemandTokenMeta = SimpleTokenMeta & {
|
|
18
|
+
contractType: typeof KYC_UNDERLYING_ON_DEMAND;
|
|
19
|
+
kycFactory: Address;
|
|
20
|
+
asset: Address;
|
|
21
|
+
pool: Address;
|
|
22
|
+
liquidityProvider: Address;
|
|
23
|
+
};
|
|
24
|
+
export type KYCTokenMeta = KYCDefaultTokenMeta | KYCOnDemandTokenMeta;
|
|
25
|
+
export type TokenMetaData = SimpleTokenMeta | PhantomTokenMeta | KYCTokenMeta;
|
|
@@ -26,7 +26,6 @@ export type CreditManagerState = CreditSuiteState["creditManager"];
|
|
|
26
26
|
export type CreditFacadeState = CreditSuiteState["creditFacade"];
|
|
27
27
|
export type CreditConfiguratorState = CreditSuiteState["creditConfigurator"];
|
|
28
28
|
export type AdapterData = Unarray<CreditSuiteState["adapters"]>;
|
|
29
|
-
export type TokenMetaData = Unarray<MarketData["tokens"]>;
|
|
30
29
|
export type PoolState = MarketData["pool"];
|
|
31
30
|
export type QuotaKeeperState = MarketData["quotaKeeper"];
|
|
32
31
|
export type QuotaState = Unarray<QuotaKeeperState["quotas"]>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
2
|
import type { MarketData, MarketFilter } from "../base/index.js";
|
|
3
|
-
import { SDKConstruct } from "../base/index.js";
|
|
4
3
|
import type { GearboxSDK } from "../GearboxSDK.js";
|
|
5
4
|
import type { MarketStateHuman } from "../types/index.js";
|
|
6
5
|
import { AddressMap } from "../utils/index.js";
|
|
@@ -9,7 +8,8 @@ import { MarketConfiguratorContract } from "./MarketConfiguratorContract.js";
|
|
|
9
8
|
import { MarketSuite } from "./MarketSuite.js";
|
|
10
9
|
import type { IPriceOracleContract } from "./oracle/index.js";
|
|
11
10
|
import type { PoolSuite } from "./pool/index.js";
|
|
12
|
-
|
|
11
|
+
import { ZapperRegister } from "./ZapperRegister.js";
|
|
12
|
+
export declare class MarketRegister extends ZapperRegister {
|
|
13
13
|
#private;
|
|
14
14
|
constructor(sdk: GearboxSDK, ignoreMarkets?: Address[]);
|
|
15
15
|
hydrate(state: MarketData[]): void;
|
|
@@ -21,6 +21,7 @@ export declare class MarketSuite extends SDKConstruct {
|
|
|
21
21
|
*/
|
|
22
22
|
readonly state: MarketData;
|
|
23
23
|
constructor(sdk: GearboxSDK, marketData: MarketData);
|
|
24
|
+
get underlying(): Address;
|
|
24
25
|
get dirty(): boolean;
|
|
25
26
|
get watchAddresses(): Set<Address>;
|
|
26
27
|
stateHuman(raw?: boolean): MarketStateHuman;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import { SDKConstruct } from "../base/index.js";
|
|
3
|
+
import { AddressMap } from "../utils/index.js";
|
|
4
|
+
import type { ZapperData } from "./types.js";
|
|
5
|
+
export declare class ZapperRegister extends SDKConstruct {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* Load zappers for all pools using periphery compressor, adds hardcoded zappers
|
|
9
|
+
*/
|
|
10
|
+
loadZappers(force?: boolean): Promise<void>;
|
|
11
|
+
get zappers(): AddressMap<ZapperData[]>;
|
|
12
|
+
poolZappers(pool: Address): ZapperData[];
|
|
13
|
+
/**
|
|
14
|
+
* Can return multiple zappers if there are multiple zappers for the same tokenIn and tokenOut
|
|
15
|
+
*/
|
|
16
|
+
getZapper(pool: Address, tokenIn: Address, tokenOut: Address): Array<ZapperData> | undefined;
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype";
|
|
2
|
+
import type { Address } from "viem";
|
|
3
|
+
import type { peripheryCompressorAbi } from "../../abi/compressors/peripheryCompressor.js";
|
|
4
|
+
import type { Unarray } from "../base/index.js";
|
|
5
|
+
type CompressorZapperData = Unarray<AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof peripheryCompressorAbi, "getZappers">["outputs"]>>;
|
|
6
|
+
export interface ZapperData extends CompressorZapperData {
|
|
7
|
+
pool: Address;
|
|
8
|
+
type: "migration" | "kyc" | "base";
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import { SDKConstruct } from "../base/index.js";
|
|
3
|
+
import type { AddLiquidityProps, DepositMetadata, IPoolsService, PoolServiceCall, RemoveLiquidityProps } from "./types.js";
|
|
4
|
+
export declare class PoolService extends SDKConstruct implements IPoolsService {
|
|
5
|
+
#private;
|
|
6
|
+
getDepositTokensIn(pool: Address): Address[];
|
|
7
|
+
getDepositTokensOut(pool: Address, tokenIn: Address): Address[];
|
|
8
|
+
getDepositMetadata(pool: Address, tokenIn: Address, tokenOut?: Address): DepositMetadata;
|
|
9
|
+
addLiquidity(props: AddLiquidityProps): PoolServiceCall | undefined;
|
|
10
|
+
removeLiquidity(props: RemoveLiquidityProps): PoolServiceCall;
|
|
11
|
+
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type { iZapperAbi } from "../../abi/iZapper.js";
|
|
5
|
-
import type { iPoolV300Abi } from "../../abi/v300.js";
|
|
6
|
-
import type { PoolData_Legacy } from "../index.js";
|
|
1
|
+
import type { Abi } from "abitype";
|
|
2
|
+
import type { Address, ContractFunctionArgs, ContractFunctionName } from "viem";
|
|
3
|
+
import type { ZapperData } from "../market/index.js";
|
|
7
4
|
import type { Asset } from "../router/index.js";
|
|
5
|
+
import type { PoolData_Legacy } from "../sdk-legacy/index.js";
|
|
8
6
|
interface PermitResult {
|
|
9
7
|
r: Address;
|
|
10
8
|
s: Address;
|
|
@@ -16,40 +14,21 @@ interface PermitResult {
|
|
|
16
14
|
deadline: bigint;
|
|
17
15
|
nonce: bigint;
|
|
18
16
|
}
|
|
17
|
+
export type PoolServiceCall<abi extends Abi | readonly unknown[] = Abi, functionName extends ContractFunctionName<abi, "nonpayable" | "payable"> = ContractFunctionName<abi, "nonpayable" | "payable">, args extends ContractFunctionArgs<abi, "nonpayable" | "payable", functionName> = ContractFunctionArgs<abi, "nonpayable" | "payable", functionName>> = {
|
|
18
|
+
abi: abi;
|
|
19
|
+
functionName: functionName;
|
|
20
|
+
args: args;
|
|
21
|
+
target: Address;
|
|
22
|
+
value?: bigint;
|
|
23
|
+
};
|
|
19
24
|
export interface AddLiquidityProps {
|
|
20
25
|
collateral: Asset;
|
|
21
26
|
pool: Address;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
nativeTokenAddress: Address;
|
|
27
|
-
referralCode: bigint | undefined;
|
|
27
|
+
wallet: Address;
|
|
28
|
+
meta: DepositMetadata;
|
|
29
|
+
permit?: PermitResult;
|
|
30
|
+
referralCode?: bigint;
|
|
28
31
|
}
|
|
29
|
-
export type AddLiquidityCall = [
|
|
30
|
-
{
|
|
31
|
-
target: Address;
|
|
32
|
-
abi: typeof iethZapperDepositsAbi;
|
|
33
|
-
functionName: "depositWithReferral";
|
|
34
|
-
args: [Address, bigint];
|
|
35
|
-
value: bigint;
|
|
36
|
-
} | {
|
|
37
|
-
target: Address;
|
|
38
|
-
abi: typeof ierc20ZapperDepositsAbi;
|
|
39
|
-
functionName: "depositWithReferralAndPermit";
|
|
40
|
-
args: [bigint, Address, bigint, bigint, number, Address, Address];
|
|
41
|
-
} | {
|
|
42
|
-
target: Address;
|
|
43
|
-
abi: typeof ierc20ZapperDepositsAbi;
|
|
44
|
-
functionName: "depositWithReferral";
|
|
45
|
-
args: [bigint, Address, bigint];
|
|
46
|
-
} | {
|
|
47
|
-
target: Address;
|
|
48
|
-
abi: typeof iPoolV300Abi;
|
|
49
|
-
functionName: "depositWithReferral";
|
|
50
|
-
args: [bigint, Address, bigint];
|
|
51
|
-
}
|
|
52
|
-
];
|
|
53
32
|
export interface RemoveLiquidityProps {
|
|
54
33
|
pool: Address;
|
|
55
34
|
amount: bigint;
|
|
@@ -57,36 +36,63 @@ export interface RemoveLiquidityProps {
|
|
|
57
36
|
permit: PermitResult | undefined;
|
|
58
37
|
zapper: PoolData_Legacy["zappers"][Address][Address];
|
|
59
38
|
}
|
|
60
|
-
export
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
39
|
+
export interface DepositMetadata {
|
|
40
|
+
/**
|
|
41
|
+
* Zapper that will perform the deposit, undefined in case of direct pool underlying deposit
|
|
42
|
+
*/
|
|
43
|
+
zapper?: ZapperData;
|
|
44
|
+
/**
|
|
45
|
+
* Before deposit user will nedd to call approve method on token that he wants to deposit,
|
|
46
|
+
* this is the spender address that will be used to call approve method.
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
approveTarget: Address;
|
|
50
|
+
/**
|
|
51
|
+
* If true, user can avoid approval step and deposit with permit
|
|
52
|
+
*/
|
|
53
|
+
permissible: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Type of deposit
|
|
56
|
+
*/
|
|
57
|
+
type: "kyc-on-demand" | "kyc-default" | "classic";
|
|
58
|
+
}
|
|
78
59
|
export interface IPoolsService {
|
|
79
60
|
/**
|
|
80
|
-
*
|
|
61
|
+
* Returns list of tokens that can be deposited to a pool
|
|
62
|
+
* @param pool
|
|
63
|
+
*/
|
|
64
|
+
getDepositTokensIn(pool: Address): Address[];
|
|
65
|
+
/**
|
|
66
|
+
* Returns list of tokens that user can receive after depositing to a pool,
|
|
67
|
+
* depends on the pool type and the token being deposited (one of returned by {@link getDepositTokensIn}).
|
|
68
|
+
*
|
|
69
|
+
* Can return empty array if no tokens can be received (e.g. for KYC underlying on demand)
|
|
70
|
+
*
|
|
71
|
+
* @param pool
|
|
72
|
+
* @param tokenIn
|
|
73
|
+
*/
|
|
74
|
+
getDepositTokensOut(pool: Address, tokenIn: Address): Address[];
|
|
75
|
+
/**
|
|
76
|
+
* After user chooses tokenIn from {@link getDepositTokensIn} and tokenOut from {@link getDepositTokensOut},
|
|
77
|
+
* this method returns metadata that will be used to perform the deposit.
|
|
78
|
+
*
|
|
79
|
+
* @param pool
|
|
80
|
+
* @param tokenIn
|
|
81
|
+
* @param tokenOut can be undefined if deposit is not resulting in a token out (e.g. for KYC underlying on demand)
|
|
82
|
+
*/
|
|
83
|
+
getDepositMetadata(pool: Address, tokenIn: Address, tokenOut?: Address): DepositMetadata;
|
|
84
|
+
/**
|
|
85
|
+
* Returns contract call parameters for adding liquidity to a pool
|
|
86
|
+
* Or undefined if no deposit action is required (e.g. for KYC underlying on demand)
|
|
81
87
|
* @param props - {@link AddLiquidityProps}
|
|
82
88
|
* @returns - {@link AddLiquidityCall}
|
|
83
89
|
*/
|
|
84
|
-
addLiquidity(props: AddLiquidityProps):
|
|
90
|
+
addLiquidity(props: AddLiquidityProps): PoolServiceCall | undefined;
|
|
85
91
|
/**
|
|
86
92
|
* Remove liquidity from a pool
|
|
87
93
|
* @param props - {@link RemoveLiquidityProps}
|
|
88
94
|
* @returns - {@link RemoveLiquidityCall}
|
|
89
95
|
*/
|
|
90
|
-
removeLiquidity(props: RemoveLiquidityProps):
|
|
96
|
+
removeLiquidity(props: RemoveLiquidityProps): PoolServiceCall;
|
|
91
97
|
}
|
|
92
98
|
export {};
|
|
@@ -3,8 +3,8 @@ import type { Address } from "viem";
|
|
|
3
3
|
import type { peripheryCompressorAbi } from "../../../abi/compressors/peripheryCompressor.js";
|
|
4
4
|
import type { Unarray } from "../../base/types.js";
|
|
5
5
|
import type { NetworkType } from "../../chain/chains.js";
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
type ZapperData = Unarray<AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof peripheryCompressorAbi, "getZappers">["outputs"]>>;
|
|
7
|
+
interface ZapperDataFull extends ZapperData {
|
|
8
8
|
pool: Address;
|
|
9
9
|
}
|
|
10
10
|
export interface PoolDataPayload {
|
|
@@ -178,3 +178,4 @@ export interface UserPoolAggregatedStatsPayload {
|
|
|
178
178
|
user: Address;
|
|
179
179
|
pools: Array<UserPoolPayload>;
|
|
180
180
|
}
|
|
181
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.0.0-next.10",
|
|
4
4
|
"description": "Gearbox SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/cjs/sdk/index.js",
|
|
@@ -66,10 +66,10 @@
|
|
|
66
66
|
"zod": "^4.3.6"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@biomejs/biome": "^2.
|
|
69
|
+
"@biomejs/biome": "^2.4.2",
|
|
70
70
|
"@commitlint/cli": "^20.4.1",
|
|
71
71
|
"@commitlint/config-conventional": "^20.4.1",
|
|
72
|
-
"@gearbox-protocol/biome-config": "^1.0.
|
|
72
|
+
"@gearbox-protocol/biome-config": "^1.0.21",
|
|
73
73
|
"@types/cross-spawn": "^6.0.6",
|
|
74
74
|
"axios": "^1.13.5",
|
|
75
75
|
"cross-spawn": "^7.0.6",
|