aftermath-ts-sdk 1.1.73 → 1.1.75
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/general/types/configTypes.d.ts +9 -0
- package/dist/general/types/configTypes.d.ts.map +1 -1
- package/dist/general/utils/casting.d.ts +3 -1
- package/dist/general/utils/casting.d.ts.map +1 -1
- package/dist/general/utils/casting.js +17 -0
- package/dist/general/utils/helpers.d.ts +2 -1
- package/dist/general/utils/helpers.d.ts.map +1 -1
- package/dist/general/utils/helpers.js +11 -0
- package/dist/packages/farms/farms.d.ts.map +1 -1
- package/dist/packages/farms/farms.js +12 -2
- package/dist/packages/nftAmm/api/nftAmmApi.js +4 -4
- package/dist/packages/pools/api/poolsApi.d.ts +200 -128
- package/dist/packages/pools/api/poolsApi.d.ts.map +1 -1
- package/dist/packages/pools/api/poolsApi.js +539 -306
- package/dist/packages/pools/api/poolsApiCasting.d.ts +9 -6
- package/dist/packages/pools/api/poolsApiCasting.d.ts.map +1 -1
- package/dist/packages/pools/api/poolsApiCasting.js +51 -31
- package/dist/packages/pools/api/poolsApiCastingTypes.d.ts +23 -1
- package/dist/packages/pools/api/poolsApiCastingTypes.d.ts.map +1 -1
- package/dist/packages/pools/pool.d.ts +43 -29
- package/dist/packages/pools/pool.d.ts.map +1 -1
- package/dist/packages/pools/pool.js +109 -49
- package/dist/packages/pools/pools.d.ts +5 -2
- package/dist/packages/pools/pools.d.ts.map +1 -1
- package/dist/packages/pools/pools.js +9 -2
- package/dist/packages/pools/poolsTypes.d.ts +34 -3
- package/dist/packages/pools/poolsTypes.d.ts.map +1 -1
- package/dist/packages/pools/utils/cmmmCalculations.d.ts.map +1 -1
- package/dist/packages/pools/utils/cmmmCalculations.js +9 -1
- package/package.json +2 -2
|
@@ -61,10 +61,10 @@ class PoolsApi {
|
|
|
61
61
|
});
|
|
62
62
|
this.fetchPools = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
63
63
|
const poolIds = inputs.objectIds.map((objectId) => utils_2.Helpers.addLeadingZeroesToType(objectId));
|
|
64
|
-
const
|
|
64
|
+
const response = yield this.Provider.indexerCaller.fetchIndexer("pools", undefined, {
|
|
65
65
|
pool_ids: poolIds,
|
|
66
66
|
});
|
|
67
|
-
const pools =
|
|
67
|
+
const pools = poolsApiCasting_1.PoolsApiCasting.poolObjectsFromIndexerResponse(response);
|
|
68
68
|
return poolIds.map((objectId) => pools.find((pool) => pool.objectId ===
|
|
69
69
|
utils_2.Helpers.addLeadingZeroesToType(objectId)
|
|
70
70
|
// TODO: handle this error case better
|
|
@@ -76,9 +76,366 @@ class PoolsApi {
|
|
|
76
76
|
* @returns {Promise<PoolObject[]>} A promise that resolves to an array of all fetched pool objects.
|
|
77
77
|
*/
|
|
78
78
|
this.fetchAllPools = () => __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
const
|
|
80
|
-
return
|
|
79
|
+
const response = yield this.Provider.indexerCaller.fetchIndexer("pools");
|
|
80
|
+
return poolsApiCasting_1.PoolsApiCasting.poolObjectsFromIndexerResponse(response);
|
|
81
81
|
});
|
|
82
|
+
this.fetchOwnedDaoFeePoolOwnerCaps = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const { walletAddress } = inputs;
|
|
84
|
+
if (!this.objectTypes.daoFeePoolOwnerCap)
|
|
85
|
+
throw new Error("dao fee pool addresses have not been set in provider");
|
|
86
|
+
return this.Provider.Objects().fetchCastObjectsOwnedByAddressOfType({
|
|
87
|
+
walletAddress,
|
|
88
|
+
objectType: this.objectTypes.daoFeePoolOwnerCap,
|
|
89
|
+
objectFromSuiObjectResponse: casting_1.Casting.pools.daoFeePoolOwnerCapObjectFromSuiObjectResponse,
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
// =========================================================================
|
|
93
|
+
// Transaction Commands
|
|
94
|
+
// =========================================================================
|
|
95
|
+
/**
|
|
96
|
+
* Executes a trade transaction on the specified pool.
|
|
97
|
+
* @param inputs An object containing the necessary inputs for the trade transaction.
|
|
98
|
+
* @returns A `TransactionObjectArgument` representing the trade transaction.
|
|
99
|
+
*/
|
|
100
|
+
this.tradeTx = (inputs) => {
|
|
101
|
+
const { tx, poolId, coinInId, coinInType, expectedCoinOutAmount, coinOutType, lpCoinType, slippage, withTransfer, } = inputs;
|
|
102
|
+
return tx.moveCall({
|
|
103
|
+
target: utils_2.Helpers.transactions.createTxTarget(withTransfer
|
|
104
|
+
? this.addresses.pools.packages.ammInterface
|
|
105
|
+
: this.addresses.pools.packages.amm, withTransfer
|
|
106
|
+
? PoolsApi.constants.moduleNames.interface
|
|
107
|
+
: PoolsApi.constants.moduleNames.swap, "swap_exact_in"),
|
|
108
|
+
typeArguments: [lpCoinType, coinInType, coinOutType],
|
|
109
|
+
arguments: [
|
|
110
|
+
tx.object(poolId),
|
|
111
|
+
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
112
|
+
tx.object(this.addresses.pools.objects.protocolFeeVault),
|
|
113
|
+
tx.object(this.addresses.pools.objects.treasury),
|
|
114
|
+
tx.object(this.addresses.pools.objects.insuranceFund),
|
|
115
|
+
tx.object(this.addresses.referralVault.objects.referralVault),
|
|
116
|
+
typeof coinInId === "string" ? tx.object(coinInId) : coinInId,
|
|
117
|
+
tx.pure.u64(expectedCoinOutAmount.toString()),
|
|
118
|
+
tx.pure.u64(pools_1.Pools.normalizeInvertSlippage(slippage)),
|
|
119
|
+
],
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Creates a transaction object argument for depositing multiple coins into a pool.
|
|
124
|
+
*
|
|
125
|
+
* @param inputs - An object containing the necessary parameters for the deposit transaction.
|
|
126
|
+
* @returns A transaction object argument representing the deposit transaction.
|
|
127
|
+
*/
|
|
128
|
+
this.multiCoinDepositTx = (inputs) => {
|
|
129
|
+
const { tx, poolId, coinIds, coinTypes, expectedLpRatio, lpCoinType, slippage, withTransfer, } = inputs;
|
|
130
|
+
const poolSize = coinTypes.length;
|
|
131
|
+
return tx.moveCall({
|
|
132
|
+
target: utils_2.Helpers.transactions.createTxTarget(withTransfer
|
|
133
|
+
? this.addresses.pools.packages.ammInterface
|
|
134
|
+
: this.addresses.pools.packages.amm, withTransfer
|
|
135
|
+
? PoolsApi.constants.moduleNames.interface
|
|
136
|
+
: PoolsApi.constants.moduleNames.deposit, `deposit_${poolSize}_coins`),
|
|
137
|
+
typeArguments: [lpCoinType, ...coinTypes],
|
|
138
|
+
arguments: [
|
|
139
|
+
tx.object(poolId),
|
|
140
|
+
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
141
|
+
tx.object(this.addresses.pools.objects.protocolFeeVault),
|
|
142
|
+
tx.object(this.addresses.pools.objects.treasury),
|
|
143
|
+
tx.object(this.addresses.pools.objects.insuranceFund),
|
|
144
|
+
tx.object(this.addresses.referralVault.objects.referralVault),
|
|
145
|
+
...coinIds.map((coinId) => typeof coinId === "string" ? tx.object(coinId) : coinId),
|
|
146
|
+
tx.pure.u128(expectedLpRatio.toString()),
|
|
147
|
+
tx.pure.u64(pools_1.Pools.normalizeInvertSlippage(slippage)),
|
|
148
|
+
],
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Withdraws multiple coins from a pool.
|
|
153
|
+
* @param inputs An object containing the necessary parameters for the transaction.
|
|
154
|
+
* @returns A TransactionObjectArgument representing the transaction.
|
|
155
|
+
*/
|
|
156
|
+
this.multiCoinWithdrawTx = (inputs) => {
|
|
157
|
+
const { tx, poolId, lpCoinId, expectedAmountsOut, coinTypes, lpCoinType, slippage, withTransfer, } = inputs;
|
|
158
|
+
const poolSize = coinTypes.length;
|
|
159
|
+
return tx.moveCall({
|
|
160
|
+
target: utils_2.Helpers.transactions.createTxTarget(withTransfer
|
|
161
|
+
? this.addresses.pools.packages.ammInterface
|
|
162
|
+
: this.addresses.pools.packages.amm, withTransfer
|
|
163
|
+
? PoolsApi.constants.moduleNames.interface
|
|
164
|
+
: PoolsApi.constants.moduleNames.withdraw, `withdraw_${poolSize}_coins`),
|
|
165
|
+
typeArguments: [lpCoinType, ...coinTypes],
|
|
166
|
+
arguments: [
|
|
167
|
+
tx.object(poolId),
|
|
168
|
+
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
169
|
+
tx.object(this.addresses.pools.objects.protocolFeeVault),
|
|
170
|
+
tx.object(this.addresses.pools.objects.treasury),
|
|
171
|
+
tx.object(this.addresses.pools.objects.insuranceFund),
|
|
172
|
+
tx.object(this.addresses.referralVault.objects.referralVault),
|
|
173
|
+
typeof lpCoinId === "string" ? tx.object(lpCoinId) : lpCoinId,
|
|
174
|
+
tx.pure(bcs_1.bcs
|
|
175
|
+
.vector(bcs_1.bcs.u64())
|
|
176
|
+
.serialize(expectedAmountsOut.map((amount) => amount.toString()))),
|
|
177
|
+
tx.pure.u64(pools_1.Pools.normalizeInvertSlippage(slippage)),
|
|
178
|
+
],
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Withdraws all coins from a liquidity pool.
|
|
183
|
+
* @param inputs - The inputs required for the transaction.
|
|
184
|
+
* @param inputs.tx - The transaction block.
|
|
185
|
+
* @param inputs.poolId - The ID of the liquidity pool.
|
|
186
|
+
* @param inputs.lpCoinId - The ID of the LP coin.
|
|
187
|
+
* @param inputs.lpCoinType - The type of the LP coin.
|
|
188
|
+
* @param inputs.coinTypes - An array of coin types.
|
|
189
|
+
* @param inputs.withTransfer - Whether or not to include a transfer.
|
|
190
|
+
* @returns An array of transaction objects.
|
|
191
|
+
*/
|
|
192
|
+
this.allCoinWithdrawTx = (inputs) => {
|
|
193
|
+
const { tx, poolId, lpCoinId, coinTypes, lpCoinType, withTransfer } = inputs;
|
|
194
|
+
const poolSize = coinTypes.length;
|
|
195
|
+
return tx.moveCall({
|
|
196
|
+
target: utils_2.Helpers.transactions.createTxTarget(withTransfer
|
|
197
|
+
? this.addresses.pools.packages.ammInterface
|
|
198
|
+
: this.addresses.pools.packages.amm, withTransfer
|
|
199
|
+
? PoolsApi.constants.moduleNames.interface
|
|
200
|
+
: PoolsApi.constants.moduleNames.withdraw, `all_coin_withdraw_${poolSize}_coins`),
|
|
201
|
+
typeArguments: [lpCoinType, ...coinTypes],
|
|
202
|
+
arguments: [
|
|
203
|
+
tx.object(poolId),
|
|
204
|
+
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
205
|
+
tx.object(this.addresses.pools.objects.protocolFeeVault),
|
|
206
|
+
tx.object(this.addresses.pools.objects.treasury),
|
|
207
|
+
tx.object(this.addresses.pools.objects.insuranceFund),
|
|
208
|
+
tx.object(this.addresses.referralVault.objects.referralVault),
|
|
209
|
+
typeof lpCoinId === "string" ? tx.object(lpCoinId) : lpCoinId,
|
|
210
|
+
],
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Publishes a transaction block for creating a liquidity pool coin.
|
|
215
|
+
* @param inputs An object containing the transaction block and the decimal value of the liquidity pool coin.
|
|
216
|
+
* @returns A promise that resolves to the result of the transaction publishing.
|
|
217
|
+
*/
|
|
218
|
+
this.publishLpCoinTx = (inputs) => {
|
|
219
|
+
var _a;
|
|
220
|
+
const compilations = (_a = this.addresses.pools.other) === null || _a === void 0 ? void 0 : _a.createLpCoinPackageCompilations;
|
|
221
|
+
if (!compilations)
|
|
222
|
+
throw new Error("not all required addresses have been set in provider for lp coin publishing (requires package compilations)");
|
|
223
|
+
const { tx, lpCoinDecimals } = inputs;
|
|
224
|
+
const compiledModulesAndDeps = JSON.parse(compilations[lpCoinDecimals]);
|
|
225
|
+
return tx.publish({
|
|
226
|
+
modules: compiledModulesAndDeps.modules.map((m) => Array.from((0, utils_1.fromB64)(m))),
|
|
227
|
+
dependencies: compiledModulesAndDeps.dependencies.map((addr) => (0, utils_1.normalizeSuiObjectId)(addr)),
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
// TODO: handle bounds checks here instead of just on-chain ?
|
|
231
|
+
/**
|
|
232
|
+
* Creates a transaction to create a new pool.
|
|
233
|
+
* @param inputs - An object containing the necessary inputs to create the pool.
|
|
234
|
+
* @returns A transaction block to create the pool.
|
|
235
|
+
*/
|
|
236
|
+
this.createPoolTx = (inputs) => {
|
|
237
|
+
const { tx, lpCoinType, createPoolCapId, coinsInfo, lpCoinMetadata, lpCoinDescription, lpCoinIconUrl, withTransfer, } = inputs;
|
|
238
|
+
const poolSize = coinsInfo.length;
|
|
239
|
+
const coinTypes = coinsInfo.map((coin) => coin.coinType);
|
|
240
|
+
const decimals = coinsInfo.map((coin) => coin.decimals);
|
|
241
|
+
return tx.moveCall({
|
|
242
|
+
target: utils_2.Helpers.transactions.createTxTarget(withTransfer
|
|
243
|
+
? this.addresses.pools.packages.ammInterface
|
|
244
|
+
: this.addresses.pools.packages.amm, withTransfer
|
|
245
|
+
? PoolsApi.constants.moduleNames.interface
|
|
246
|
+
: PoolsApi.constants.moduleNames.poolFactory, `create_pool_${poolSize}_coins`),
|
|
247
|
+
typeArguments: [lpCoinType, ...coinTypes],
|
|
248
|
+
arguments: [
|
|
249
|
+
typeof createPoolCapId === "string"
|
|
250
|
+
? tx.object(createPoolCapId)
|
|
251
|
+
: createPoolCapId,
|
|
252
|
+
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
253
|
+
tx.pure(bcs_1.bcs
|
|
254
|
+
.vector(bcs_1.bcs.u8())
|
|
255
|
+
.serialize(casting_1.Casting.u8VectorFromString(inputs.poolName))),
|
|
256
|
+
tx.pure(bcs_1.bcs
|
|
257
|
+
.vector(bcs_1.bcs.u8())
|
|
258
|
+
.serialize(casting_1.Casting.u8VectorFromString(lpCoinMetadata.name.toString()))),
|
|
259
|
+
tx.pure(bcs_1.bcs
|
|
260
|
+
.vector(bcs_1.bcs.u8())
|
|
261
|
+
.serialize(casting_1.Casting.u8VectorFromString(lpCoinMetadata.symbol.toString().toUpperCase()))),
|
|
262
|
+
tx.pure(bcs_1.bcs
|
|
263
|
+
.vector(bcs_1.bcs.u8())
|
|
264
|
+
.serialize(casting_1.Casting.u8VectorFromString(lpCoinDescription))),
|
|
265
|
+
tx.pure(bcs_1.bcs
|
|
266
|
+
.vector(bcs_1.bcs.u8())
|
|
267
|
+
.serialize(casting_1.Casting.u8VectorFromString(lpCoinIconUrl))),
|
|
268
|
+
tx.pure(bcs_1.bcs
|
|
269
|
+
.vector(bcs_1.bcs.u64())
|
|
270
|
+
.serialize(coinsInfo.map((coin) => coin.weight))),
|
|
271
|
+
tx.pure.u64(inputs.poolFlatness),
|
|
272
|
+
tx.pure(bcs_1.bcs
|
|
273
|
+
.vector(bcs_1.bcs.u64())
|
|
274
|
+
.serialize(coinsInfo.map((coin) => coin.tradeFeeIn))),
|
|
275
|
+
tx.pure(bcs_1.bcs
|
|
276
|
+
.vector(bcs_1.bcs.u64())
|
|
277
|
+
.serialize(coinsInfo.map((coin) => coin.tradeFeeOut))),
|
|
278
|
+
tx.pure(bcs_1.bcs
|
|
279
|
+
.vector(bcs_1.bcs.u64())
|
|
280
|
+
.serialize(coinsInfo.map((coin) => coin.depositFee))),
|
|
281
|
+
tx.pure(bcs_1.bcs
|
|
282
|
+
.vector(bcs_1.bcs.u64())
|
|
283
|
+
.serialize(coinsInfo.map((coin) => coin.withdrawFee))),
|
|
284
|
+
...coinsInfo.map((coin) => typeof coin.coinId === "string"
|
|
285
|
+
? tx.object(coin.coinId)
|
|
286
|
+
: coin.coinId),
|
|
287
|
+
tx.pure(bcs_1.bcs
|
|
288
|
+
.option(bcs_1.bcs.vector(bcs_1.bcs.u8()))
|
|
289
|
+
.serialize(decimals.includes(undefined)
|
|
290
|
+
? undefined
|
|
291
|
+
: decimals)),
|
|
292
|
+
tx.pure.bool(inputs.respectDecimals),
|
|
293
|
+
tx.pure(bcs_1.bcs.option(bcs_1.bcs.u8()).serialize(inputs.forceLpDecimals)), // force_lp_decimals
|
|
294
|
+
],
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
/**
|
|
298
|
+
* Returns the pool object ID for a given LP coin type transaction.
|
|
299
|
+
* @param inputs - An object containing the transaction block and LP coin type.
|
|
300
|
+
* @returns The pool object ID.
|
|
301
|
+
*/
|
|
302
|
+
this.poolObjectIdForLpCoinTypeTx = (inputs) => {
|
|
303
|
+
const { tx, lpCoinType } = inputs;
|
|
304
|
+
return tx.moveCall({
|
|
305
|
+
target: utils_2.Helpers.transactions.createTxTarget(this.addresses.pools.packages.amm, PoolsApi.constants.moduleNames.poolRegistry, "lp_type_to_pool_id"),
|
|
306
|
+
typeArguments: [lpCoinType],
|
|
307
|
+
arguments: [tx.object(this.addresses.pools.objects.poolRegistry)],
|
|
308
|
+
});
|
|
309
|
+
};
|
|
310
|
+
this.daoFeePoolNewTx = (inputs) => {
|
|
311
|
+
const { tx, poolId } = inputs;
|
|
312
|
+
if (!this.addresses.daoFeePools)
|
|
313
|
+
throw new Error("dao fee pool addresses have not been set in provider");
|
|
314
|
+
return tx.moveCall({
|
|
315
|
+
target: utils_2.Helpers.transactions.createTxTarget(this.addresses.daoFeePools.packages.amm, PoolsApi.constants.moduleNames.pool, "new"),
|
|
316
|
+
typeArguments: [inputs.lpCoinType],
|
|
317
|
+
arguments: [
|
|
318
|
+
typeof poolId === "string" ? tx.object(poolId) : poolId,
|
|
319
|
+
tx.object(this.addresses.daoFeePools.objects.version),
|
|
320
|
+
tx.pure.u16(Number(inputs.feeBps)),
|
|
321
|
+
tx.pure.address(inputs.feeRecipient),
|
|
322
|
+
],
|
|
323
|
+
});
|
|
324
|
+
};
|
|
325
|
+
this.daoFeePoolUpdateFeeBpsTx = (inputs) => {
|
|
326
|
+
const { tx } = inputs;
|
|
327
|
+
if (!this.addresses.daoFeePools)
|
|
328
|
+
throw new Error("dao fee pool addresses have not been set in provider");
|
|
329
|
+
return tx.moveCall({
|
|
330
|
+
target: utils_2.Helpers.transactions.createTxTarget(this.addresses.daoFeePools.packages.amm, PoolsApi.constants.moduleNames.pool, "update_fee_bps"),
|
|
331
|
+
typeArguments: [inputs.lpCoinType],
|
|
332
|
+
arguments: [
|
|
333
|
+
tx.object(inputs.daoFeePoolOwnerCapId),
|
|
334
|
+
tx.object(inputs.daoFeePoolId),
|
|
335
|
+
tx.object(this.addresses.daoFeePools.objects.version),
|
|
336
|
+
tx.pure.u16(Number(inputs.newFeeBps)),
|
|
337
|
+
],
|
|
338
|
+
});
|
|
339
|
+
};
|
|
340
|
+
this.daoFeePoolUpdateFeeRecipientTx = (inputs) => {
|
|
341
|
+
const { tx } = inputs;
|
|
342
|
+
if (!this.addresses.daoFeePools)
|
|
343
|
+
throw new Error("dao fee pool addresses have not been set in provider");
|
|
344
|
+
return tx.moveCall({
|
|
345
|
+
target: utils_2.Helpers.transactions.createTxTarget(this.addresses.daoFeePools.packages.amm, PoolsApi.constants.moduleNames.pool, "update_fee_recipient"),
|
|
346
|
+
typeArguments: [inputs.lpCoinType],
|
|
347
|
+
arguments: [
|
|
348
|
+
tx.object(inputs.daoFeePoolOwnerCapId),
|
|
349
|
+
tx.object(inputs.daoFeePoolId),
|
|
350
|
+
tx.object(this.addresses.daoFeePools.objects.version),
|
|
351
|
+
tx.pure.address(inputs.newFeeRecipient),
|
|
352
|
+
],
|
|
353
|
+
});
|
|
354
|
+
};
|
|
355
|
+
/**
|
|
356
|
+
* Executes a trade transaction on the specified pool.
|
|
357
|
+
* @param inputs An object containing the necessary inputs for the trade transaction.
|
|
358
|
+
* @returns A `TransactionObjectArgument` representing the trade transaction.
|
|
359
|
+
*/
|
|
360
|
+
this.daoFeePoolTradeTx = (inputs) => {
|
|
361
|
+
const { tx, daoFeePoolId, coinInId, coinInType, expectedCoinOutAmount, coinOutType, lpCoinType, slippage, } = inputs;
|
|
362
|
+
if (!this.addresses.daoFeePools)
|
|
363
|
+
throw new Error("dao fee pool addresses have not been set in provider");
|
|
364
|
+
return tx.moveCall({
|
|
365
|
+
target: utils_2.Helpers.transactions.createTxTarget(this.addresses.daoFeePools.packages.amm, PoolsApi.constants.moduleNames.swap, "swap_exact_in"),
|
|
366
|
+
typeArguments: [lpCoinType, coinInType, coinOutType],
|
|
367
|
+
arguments: [
|
|
368
|
+
tx.object(daoFeePoolId),
|
|
369
|
+
tx.object(this.addresses.daoFeePools.objects.version),
|
|
370
|
+
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
371
|
+
tx.object(this.addresses.pools.objects.protocolFeeVault),
|
|
372
|
+
tx.object(this.addresses.pools.objects.treasury),
|
|
373
|
+
tx.object(this.addresses.pools.objects.insuranceFund),
|
|
374
|
+
tx.object(this.addresses.referralVault.objects.referralVault),
|
|
375
|
+
typeof coinInId === "string" ? tx.object(coinInId) : coinInId,
|
|
376
|
+
tx.pure.u64(expectedCoinOutAmount.toString()),
|
|
377
|
+
tx.pure.u64(pools_1.Pools.normalizeInvertSlippage(slippage)),
|
|
378
|
+
],
|
|
379
|
+
});
|
|
380
|
+
};
|
|
381
|
+
/**
|
|
382
|
+
* Creates a transaction object argument for depositing multiple coins into a pool.
|
|
383
|
+
*
|
|
384
|
+
* @param inputs - An object containing the necessary parameters for the deposit transaction.
|
|
385
|
+
* @returns A transaction object argument representing the deposit transaction.
|
|
386
|
+
*/
|
|
387
|
+
this.daoFeePoolMultiCoinDepositTx = (inputs) => {
|
|
388
|
+
const { tx, daoFeePoolId, coinIds, coinTypes, expectedLpRatio, lpCoinType, slippage, } = inputs;
|
|
389
|
+
if (!this.addresses.daoFeePools)
|
|
390
|
+
throw new Error("dao fee pool addresses have not been set in provider");
|
|
391
|
+
const poolSize = coinTypes.length;
|
|
392
|
+
return tx.moveCall({
|
|
393
|
+
target: utils_2.Helpers.transactions.createTxTarget(this.addresses.daoFeePools.packages.amm, PoolsApi.constants.moduleNames.deposit, `deposit_${poolSize}_coins`),
|
|
394
|
+
typeArguments: [lpCoinType, ...coinTypes],
|
|
395
|
+
arguments: [
|
|
396
|
+
tx.object(daoFeePoolId),
|
|
397
|
+
tx.object(this.addresses.daoFeePools.objects.version),
|
|
398
|
+
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
399
|
+
tx.object(this.addresses.pools.objects.protocolFeeVault),
|
|
400
|
+
tx.object(this.addresses.pools.objects.treasury),
|
|
401
|
+
tx.object(this.addresses.pools.objects.insuranceFund),
|
|
402
|
+
tx.object(this.addresses.referralVault.objects.referralVault),
|
|
403
|
+
...coinIds.map((coinId) => typeof coinId === "string" ? tx.object(coinId) : coinId),
|
|
404
|
+
tx.pure.u128(expectedLpRatio.toString()),
|
|
405
|
+
tx.pure.u64(pools_1.Pools.normalizeInvertSlippage(slippage)),
|
|
406
|
+
],
|
|
407
|
+
});
|
|
408
|
+
};
|
|
409
|
+
/**
|
|
410
|
+
* Withdraws all coins from a liquidity pool.
|
|
411
|
+
* @param inputs - The inputs required for the transaction.
|
|
412
|
+
* @param inputs.tx - The transaction block.
|
|
413
|
+
* @param inputs.poolId - The ID of the liquidity pool.
|
|
414
|
+
* @param inputs.lpCoinId - The ID of the LP coin.
|
|
415
|
+
* @param inputs.lpCoinType - The type of the LP coin.
|
|
416
|
+
* @param inputs.coinTypes - An array of coin types.
|
|
417
|
+
* @returns An array of transaction objects.
|
|
418
|
+
*/
|
|
419
|
+
this.daoFeePoolAllCoinWithdrawTx = (inputs) => {
|
|
420
|
+
const { tx, daoFeePoolId, lpCoinId, coinTypes, lpCoinType } = inputs;
|
|
421
|
+
if (!this.addresses.daoFeePools)
|
|
422
|
+
throw new Error("dao fee pool addresses have not been set in provider");
|
|
423
|
+
const poolSize = coinTypes.length;
|
|
424
|
+
return tx.moveCall({
|
|
425
|
+
target: utils_2.Helpers.transactions.createTxTarget(this.addresses.daoFeePools.packages.amm, PoolsApi.constants.moduleNames.withdraw, `all_coin_withdraw_${poolSize}_coins`),
|
|
426
|
+
typeArguments: [lpCoinType, ...coinTypes],
|
|
427
|
+
arguments: [
|
|
428
|
+
tx.object(daoFeePoolId),
|
|
429
|
+
tx.object(this.addresses.daoFeePools.objects.version),
|
|
430
|
+
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
431
|
+
tx.object(this.addresses.pools.objects.protocolFeeVault),
|
|
432
|
+
tx.object(this.addresses.pools.objects.treasury),
|
|
433
|
+
tx.object(this.addresses.pools.objects.insuranceFund),
|
|
434
|
+
tx.object(this.addresses.referralVault.objects.referralVault),
|
|
435
|
+
typeof lpCoinId === "string" ? tx.object(lpCoinId) : lpCoinId,
|
|
436
|
+
],
|
|
437
|
+
});
|
|
438
|
+
};
|
|
82
439
|
// =========================================================================
|
|
83
440
|
// Transaction Builders
|
|
84
441
|
// =========================================================================
|
|
@@ -146,17 +503,32 @@ class PoolsApi {
|
|
|
146
503
|
coinAmount: coinInAmount,
|
|
147
504
|
isSponsoredTx,
|
|
148
505
|
});
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
506
|
+
if (pool.pool.daoFeePoolObject) {
|
|
507
|
+
const coinOutId = this.daoFeePoolTradeTx({
|
|
508
|
+
tx,
|
|
509
|
+
coinInId,
|
|
510
|
+
daoFeePoolId: pool.pool.daoFeePoolObject.objectId,
|
|
511
|
+
expectedCoinOutAmount: amountOut,
|
|
512
|
+
lpCoinType: pool.pool.lpCoinType,
|
|
513
|
+
coinInType,
|
|
514
|
+
coinOutType,
|
|
515
|
+
slippage,
|
|
516
|
+
});
|
|
517
|
+
tx.transferObjects([coinOutId], walletAddress);
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
this.tradeTx({
|
|
521
|
+
tx,
|
|
522
|
+
coinInId,
|
|
523
|
+
poolId: pool.pool.objectId,
|
|
524
|
+
expectedCoinOutAmount: amountOut,
|
|
525
|
+
lpCoinType: pool.pool.lpCoinType,
|
|
526
|
+
coinInType,
|
|
527
|
+
coinOutType,
|
|
528
|
+
slippage,
|
|
529
|
+
withTransfer: true,
|
|
530
|
+
});
|
|
531
|
+
}
|
|
160
532
|
return tx;
|
|
161
533
|
});
|
|
162
534
|
this.fetchAddTradeTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -207,18 +579,32 @@ class PoolsApi {
|
|
|
207
579
|
const expectedLpRatio = casting_1.Casting.numberToFixedBigInt(lpRatio);
|
|
208
580
|
const coinIds = yield this.Provider.Coin().fetchCoinsWithAmountTx(Object.assign(Object.assign({}, inputs), { tx,
|
|
209
581
|
coinTypes,
|
|
210
|
-
coinAmounts,
|
|
211
|
-
isSponsoredTx }));
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
582
|
+
coinAmounts,
|
|
583
|
+
isSponsoredTx }));
|
|
584
|
+
if (pool.pool.daoFeePoolObject) {
|
|
585
|
+
const lpCoinId = this.daoFeePoolMultiCoinDepositTx({
|
|
586
|
+
tx,
|
|
587
|
+
daoFeePoolId: pool.pool.daoFeePoolObject.objectId,
|
|
588
|
+
lpCoinType: pool.pool.lpCoinType,
|
|
589
|
+
coinIds,
|
|
590
|
+
coinTypes,
|
|
591
|
+
expectedLpRatio,
|
|
592
|
+
slippage,
|
|
593
|
+
});
|
|
594
|
+
tx.transferObjects([lpCoinId], walletAddress);
|
|
595
|
+
}
|
|
596
|
+
else {
|
|
597
|
+
this.multiCoinDepositTx({
|
|
598
|
+
tx,
|
|
599
|
+
poolId: pool.pool.objectId,
|
|
600
|
+
lpCoinType: pool.pool.lpCoinType,
|
|
601
|
+
coinIds,
|
|
602
|
+
coinTypes,
|
|
603
|
+
expectedLpRatio,
|
|
604
|
+
slippage,
|
|
605
|
+
withTransfer: true,
|
|
606
|
+
});
|
|
607
|
+
}
|
|
222
608
|
return tx;
|
|
223
609
|
});
|
|
224
610
|
/**
|
|
@@ -256,16 +642,22 @@ class PoolsApi {
|
|
|
256
642
|
coinType: pool.pool.lpCoinType,
|
|
257
643
|
coinAmount: lpCoinAmount,
|
|
258
644
|
});
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
645
|
+
if (pool.pool.daoFeePoolObject) {
|
|
646
|
+
// TODO: handle dao fee pool
|
|
647
|
+
// TODO: handle transfer
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
this.multiCoinWithdrawTx({
|
|
651
|
+
tx,
|
|
652
|
+
poolId: pool.pool.objectId,
|
|
653
|
+
lpCoinType: pool.pool.lpCoinType,
|
|
654
|
+
expectedAmountsOut: coinAmounts,
|
|
655
|
+
coinTypes: coinTypes,
|
|
656
|
+
lpCoinId,
|
|
657
|
+
slippage,
|
|
658
|
+
withTransfer: true,
|
|
659
|
+
});
|
|
660
|
+
}
|
|
269
661
|
return tx;
|
|
270
662
|
});
|
|
271
663
|
/**
|
|
@@ -289,14 +681,26 @@ class PoolsApi {
|
|
|
289
681
|
coinAmount: lpCoinAmount,
|
|
290
682
|
});
|
|
291
683
|
const coinTypes = Object.keys(pool.pool.coins);
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
684
|
+
if (pool.pool.daoFeePoolObject) {
|
|
685
|
+
const withdrawnCoinIds = this.daoFeePoolAllCoinWithdrawTx({
|
|
686
|
+
tx,
|
|
687
|
+
daoFeePoolId: pool.pool.daoFeePoolObject.objectId,
|
|
688
|
+
lpCoinType: pool.pool.lpCoinType,
|
|
689
|
+
coinTypes,
|
|
690
|
+
lpCoinId,
|
|
691
|
+
});
|
|
692
|
+
tx.transferObjects(coinTypes.map((_, index) => withdrawnCoinIds[index]), walletAddress);
|
|
693
|
+
}
|
|
694
|
+
else {
|
|
695
|
+
this.allCoinWithdrawTx({
|
|
696
|
+
tx,
|
|
697
|
+
poolId: pool.pool.objectId,
|
|
698
|
+
lpCoinType: pool.pool.lpCoinType,
|
|
699
|
+
coinTypes,
|
|
700
|
+
lpCoinId,
|
|
701
|
+
withTransfer: true,
|
|
702
|
+
});
|
|
703
|
+
}
|
|
300
704
|
return tx;
|
|
301
705
|
});
|
|
302
706
|
/**
|
|
@@ -318,7 +722,7 @@ class PoolsApi {
|
|
|
318
722
|
* @returns A Promise that resolves to a Transaction object representing the built transaction.
|
|
319
723
|
*/
|
|
320
724
|
this.fetchBuildCreatePoolTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
321
|
-
const { coinsInfo, isSponsoredTx, burnLpCoin, lpCoinType } = inputs;
|
|
725
|
+
const { coinsInfo, isSponsoredTx, burnLpCoin, lpCoinType, daoFeeInfo } = inputs;
|
|
322
726
|
const tx = new transactions_1.Transaction();
|
|
323
727
|
tx.setSender(inputs.walletAddress);
|
|
324
728
|
// TODO: make this fetching work
|
|
@@ -348,241 +752,54 @@ class PoolsApi {
|
|
|
348
752
|
coinsInfo: coinsInfo.map((info, index) => {
|
|
349
753
|
return Object.assign(Object.assign({}, info), { coinId: coinArgs[index] });
|
|
350
754
|
}), lpCoinDescription });
|
|
351
|
-
if (
|
|
352
|
-
|
|
353
|
-
|
|
755
|
+
if (daoFeeInfo) {
|
|
756
|
+
if (!this.objectTypes.daoFeePool)
|
|
757
|
+
throw new Error("dao fee pool addresses have not been set in provider");
|
|
758
|
+
const [poolId, lpCoinId] = this.createPoolTx(createPoolTxArgs);
|
|
759
|
+
const [daoFeePoolId, daoFeePoolOwnerCapId] = this.daoFeePoolNewTx({
|
|
354
760
|
tx,
|
|
355
|
-
|
|
356
|
-
|
|
761
|
+
poolId,
|
|
762
|
+
lpCoinType,
|
|
763
|
+
feeRecipient: daoFeeInfo.feeRecipient,
|
|
764
|
+
feeBps: casting_1.Casting.percentageToBps(daoFeeInfo.feePercentage),
|
|
357
765
|
});
|
|
358
|
-
this.Provider.Objects().
|
|
766
|
+
this.Provider.Objects().publicShareObjectTx({
|
|
359
767
|
tx,
|
|
360
|
-
object:
|
|
768
|
+
object: daoFeePoolId,
|
|
769
|
+
objectType: `${this.objectTypes.daoFeePool}<${lpCoinType}>`,
|
|
361
770
|
});
|
|
771
|
+
if (burnLpCoin) {
|
|
772
|
+
this.Provider.Objects().burnObjectTx({
|
|
773
|
+
tx,
|
|
774
|
+
object: lpCoinId,
|
|
775
|
+
});
|
|
776
|
+
tx.transferObjects([daoFeePoolOwnerCapId], inputs.walletAddress);
|
|
777
|
+
}
|
|
778
|
+
else {
|
|
779
|
+
tx.transferObjects([lpCoinId, daoFeePoolOwnerCapId], inputs.walletAddress);
|
|
780
|
+
}
|
|
362
781
|
}
|
|
363
782
|
else {
|
|
364
|
-
|
|
783
|
+
if (burnLpCoin) {
|
|
784
|
+
const [poolId, lpCoinId] = this.createPoolTx(createPoolTxArgs);
|
|
785
|
+
this.Provider.Objects().publicShareObjectTx({
|
|
786
|
+
tx,
|
|
787
|
+
object: poolId,
|
|
788
|
+
objectType: `${this.objectTypes.pool}<${lpCoinType}>`,
|
|
789
|
+
});
|
|
790
|
+
this.Provider.Objects().burnObjectTx({
|
|
791
|
+
tx,
|
|
792
|
+
object: lpCoinId,
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
else {
|
|
796
|
+
this.createPoolTx(Object.assign(Object.assign({}, createPoolTxArgs), { withTransfer: true }));
|
|
797
|
+
}
|
|
365
798
|
}
|
|
366
799
|
return tx;
|
|
367
800
|
});
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
// =========================================================================
|
|
371
|
-
/**
|
|
372
|
-
* Executes a trade transaction on the specified pool.
|
|
373
|
-
* @param inputs An object containing the necessary inputs for the trade transaction.
|
|
374
|
-
* @returns A `TransactionObjectArgument` representing the trade transaction.
|
|
375
|
-
*/
|
|
376
|
-
this.tradeTx = (inputs) => {
|
|
377
|
-
const { tx, poolId, coinInId, coinInType, expectedCoinOutAmount, coinOutType, lpCoinType, slippage, withTransfer, } = inputs;
|
|
378
|
-
return tx.moveCall({
|
|
379
|
-
target: utils_2.Helpers.transactions.createTxTarget(withTransfer
|
|
380
|
-
? this.addresses.pools.packages.ammInterface
|
|
381
|
-
: this.addresses.pools.packages.amm, withTransfer
|
|
382
|
-
? PoolsApi.constants.moduleNames.interface
|
|
383
|
-
: PoolsApi.constants.moduleNames.swap, "swap_exact_in"),
|
|
384
|
-
typeArguments: [lpCoinType, coinInType, coinOutType],
|
|
385
|
-
arguments: [
|
|
386
|
-
tx.object(poolId),
|
|
387
|
-
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
388
|
-
tx.object(this.addresses.pools.objects.protocolFeeVault),
|
|
389
|
-
tx.object(this.addresses.pools.objects.treasury),
|
|
390
|
-
tx.object(this.addresses.pools.objects.insuranceFund),
|
|
391
|
-
tx.object(this.addresses.referralVault.objects.referralVault),
|
|
392
|
-
typeof coinInId === "string" ? tx.object(coinInId) : coinInId,
|
|
393
|
-
tx.pure.u64(expectedCoinOutAmount.toString()),
|
|
394
|
-
tx.pure.u64(pools_1.Pools.normalizeSlippage(slippage)),
|
|
395
|
-
],
|
|
396
|
-
});
|
|
397
|
-
};
|
|
398
|
-
/**
|
|
399
|
-
* Creates a transaction object argument for depositing multiple coins into a pool.
|
|
400
|
-
*
|
|
401
|
-
* @param inputs - An object containing the necessary parameters for the deposit transaction.
|
|
402
|
-
* @returns A transaction object argument representing the deposit transaction.
|
|
403
|
-
*/
|
|
404
|
-
this.multiCoinDepositTx = (inputs) => {
|
|
405
|
-
const { tx, poolId, coinIds, coinTypes, expectedLpRatio, lpCoinType, slippage, withTransfer, } = inputs;
|
|
406
|
-
const poolSize = coinTypes.length;
|
|
407
|
-
return tx.moveCall({
|
|
408
|
-
target: utils_2.Helpers.transactions.createTxTarget(withTransfer
|
|
409
|
-
? this.addresses.pools.packages.ammInterface
|
|
410
|
-
: this.addresses.pools.packages.amm, withTransfer
|
|
411
|
-
? PoolsApi.constants.moduleNames.interface
|
|
412
|
-
: PoolsApi.constants.moduleNames.deposit, `deposit_${poolSize}_coins`),
|
|
413
|
-
typeArguments: [lpCoinType, ...coinTypes],
|
|
414
|
-
arguments: [
|
|
415
|
-
tx.object(poolId),
|
|
416
|
-
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
417
|
-
tx.object(this.addresses.pools.objects.protocolFeeVault),
|
|
418
|
-
tx.object(this.addresses.pools.objects.treasury),
|
|
419
|
-
tx.object(this.addresses.pools.objects.insuranceFund),
|
|
420
|
-
tx.object(this.addresses.referralVault.objects.referralVault),
|
|
421
|
-
...coinIds.map((coinId) => typeof coinId === "string" ? tx.object(coinId) : coinId),
|
|
422
|
-
tx.pure.u128(expectedLpRatio.toString()),
|
|
423
|
-
tx.pure.u64(pools_1.Pools.normalizeSlippage(slippage)),
|
|
424
|
-
],
|
|
425
|
-
});
|
|
426
|
-
};
|
|
427
|
-
/**
|
|
428
|
-
* Withdraws multiple coins from a pool.
|
|
429
|
-
* @param inputs An object containing the necessary parameters for the transaction.
|
|
430
|
-
* @returns A TransactionObjectArgument representing the transaction.
|
|
431
|
-
*/
|
|
432
|
-
this.multiCoinWithdrawTx = (inputs) => {
|
|
433
|
-
const { tx, poolId, lpCoinId, expectedAmountsOut, coinTypes, lpCoinType, slippage, withTransfer, } = inputs;
|
|
434
|
-
const poolSize = coinTypes.length;
|
|
435
|
-
return tx.moveCall({
|
|
436
|
-
target: utils_2.Helpers.transactions.createTxTarget(withTransfer
|
|
437
|
-
? this.addresses.pools.packages.ammInterface
|
|
438
|
-
: this.addresses.pools.packages.amm, withTransfer
|
|
439
|
-
? PoolsApi.constants.moduleNames.interface
|
|
440
|
-
: PoolsApi.constants.moduleNames.withdraw, `withdraw_${poolSize}_coins`),
|
|
441
|
-
typeArguments: [lpCoinType, ...coinTypes],
|
|
442
|
-
arguments: [
|
|
443
|
-
tx.object(poolId),
|
|
444
|
-
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
445
|
-
tx.object(this.addresses.pools.objects.protocolFeeVault),
|
|
446
|
-
tx.object(this.addresses.pools.objects.treasury),
|
|
447
|
-
tx.object(this.addresses.pools.objects.insuranceFund),
|
|
448
|
-
tx.object(this.addresses.referralVault.objects.referralVault),
|
|
449
|
-
typeof lpCoinId === "string" ? tx.object(lpCoinId) : lpCoinId,
|
|
450
|
-
tx.pure(bcs_1.bcs
|
|
451
|
-
.vector(bcs_1.bcs.u64())
|
|
452
|
-
.serialize(expectedAmountsOut.map((amount) => amount.toString()))),
|
|
453
|
-
tx.pure.u64(pools_1.Pools.normalizeSlippage(slippage)),
|
|
454
|
-
],
|
|
455
|
-
});
|
|
456
|
-
};
|
|
457
|
-
/**
|
|
458
|
-
* Withdraws all coins from a liquidity pool.
|
|
459
|
-
* @param inputs - The inputs required for the transaction.
|
|
460
|
-
* @param inputs.tx - The transaction block.
|
|
461
|
-
* @param inputs.poolId - The ID of the liquidity pool.
|
|
462
|
-
* @param inputs.lpCoinId - The ID of the LP coin.
|
|
463
|
-
* @param inputs.lpCoinType - The type of the LP coin.
|
|
464
|
-
* @param inputs.coinTypes - An array of coin types.
|
|
465
|
-
* @param inputs.withTransfer - Whether or not to include a transfer.
|
|
466
|
-
* @returns An array of transaction objects.
|
|
467
|
-
*/
|
|
468
|
-
this.allCoinWithdrawTx = (inputs) => {
|
|
469
|
-
const { tx, poolId, lpCoinId, coinTypes, lpCoinType, withTransfer } = inputs;
|
|
470
|
-
const poolSize = coinTypes.length;
|
|
471
|
-
return tx.moveCall({
|
|
472
|
-
target: utils_2.Helpers.transactions.createTxTarget(withTransfer
|
|
473
|
-
? this.addresses.pools.packages.ammInterface
|
|
474
|
-
: this.addresses.pools.packages.amm, withTransfer
|
|
475
|
-
? PoolsApi.constants.moduleNames.interface
|
|
476
|
-
: PoolsApi.constants.moduleNames.withdraw, `all_coin_withdraw_${poolSize}_coins`),
|
|
477
|
-
typeArguments: [lpCoinType, ...coinTypes],
|
|
478
|
-
arguments: [
|
|
479
|
-
tx.object(poolId),
|
|
480
|
-
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
481
|
-
tx.object(this.addresses.pools.objects.protocolFeeVault),
|
|
482
|
-
tx.object(this.addresses.pools.objects.treasury),
|
|
483
|
-
tx.object(this.addresses.pools.objects.insuranceFund),
|
|
484
|
-
tx.object(this.addresses.referralVault.objects.referralVault),
|
|
485
|
-
typeof lpCoinId === "string" ? tx.object(lpCoinId) : lpCoinId,
|
|
486
|
-
],
|
|
487
|
-
});
|
|
488
|
-
};
|
|
489
|
-
/**
|
|
490
|
-
* Publishes a transaction block for creating a liquidity pool coin.
|
|
491
|
-
* @param inputs An object containing the transaction block and the decimal value of the liquidity pool coin.
|
|
492
|
-
* @returns A promise that resolves to the result of the transaction publishing.
|
|
493
|
-
*/
|
|
494
|
-
this.publishLpCoinTx = (inputs) => {
|
|
495
|
-
var _a;
|
|
496
|
-
const compilations = (_a = this.addresses.pools.other) === null || _a === void 0 ? void 0 : _a.createLpCoinPackageCompilations;
|
|
497
|
-
if (!compilations)
|
|
498
|
-
throw new Error("not all required addresses have been set in provider for lp coin publishing (requires pacakge compilations)");
|
|
499
|
-
const { tx, lpCoinDecimals } = inputs;
|
|
500
|
-
const compiledModulesAndDeps = JSON.parse(compilations[lpCoinDecimals]);
|
|
501
|
-
return tx.publish({
|
|
502
|
-
modules: compiledModulesAndDeps.modules.map((m) => Array.from((0, utils_1.fromB64)(m))),
|
|
503
|
-
dependencies: compiledModulesAndDeps.dependencies.map((addr) => (0, utils_1.normalizeSuiObjectId)(addr)),
|
|
504
|
-
});
|
|
505
|
-
};
|
|
506
|
-
// TODO: handle bounds checks here instead of just on-chain ?
|
|
507
|
-
/**
|
|
508
|
-
* Creates a transaction to create a new pool.
|
|
509
|
-
* @param inputs - An object containing the necessary inputs to create the pool.
|
|
510
|
-
* @returns A transaction block to create the pool.
|
|
511
|
-
*/
|
|
512
|
-
this.createPoolTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
513
|
-
const { tx, lpCoinType, createPoolCapId, coinsInfo, lpCoinMetadata, lpCoinDescription, lpCoinIconUrl, withTransfer, } = inputs;
|
|
514
|
-
const poolSize = coinsInfo.length;
|
|
515
|
-
const coinTypes = coinsInfo.map((coin) => coin.coinType);
|
|
516
|
-
const decimals = coinsInfo.map((coin) => coin.decimals);
|
|
517
|
-
return tx.moveCall({
|
|
518
|
-
target: utils_2.Helpers.transactions.createTxTarget(withTransfer
|
|
519
|
-
? this.addresses.pools.packages.ammInterface
|
|
520
|
-
: this.addresses.pools.packages.amm, withTransfer
|
|
521
|
-
? PoolsApi.constants.moduleNames.interface
|
|
522
|
-
: PoolsApi.constants.moduleNames.poolFactory, `create_pool_${poolSize}_coins`),
|
|
523
|
-
typeArguments: [lpCoinType, ...coinTypes],
|
|
524
|
-
arguments: [
|
|
525
|
-
typeof createPoolCapId === "string"
|
|
526
|
-
? tx.object(createPoolCapId)
|
|
527
|
-
: createPoolCapId,
|
|
528
|
-
tx.object(this.addresses.pools.objects.poolRegistry),
|
|
529
|
-
tx.pure(bcs_1.bcs
|
|
530
|
-
.vector(bcs_1.bcs.u8())
|
|
531
|
-
.serialize(casting_1.Casting.u8VectorFromString(inputs.poolName))),
|
|
532
|
-
tx.pure(bcs_1.bcs
|
|
533
|
-
.vector(bcs_1.bcs.u8())
|
|
534
|
-
.serialize(casting_1.Casting.u8VectorFromString(lpCoinMetadata.name.toString()))),
|
|
535
|
-
tx.pure(bcs_1.bcs
|
|
536
|
-
.vector(bcs_1.bcs.u8())
|
|
537
|
-
.serialize(casting_1.Casting.u8VectorFromString(lpCoinMetadata.symbol.toString().toUpperCase()))),
|
|
538
|
-
tx.pure(bcs_1.bcs
|
|
539
|
-
.vector(bcs_1.bcs.u8())
|
|
540
|
-
.serialize(casting_1.Casting.u8VectorFromString(lpCoinDescription))),
|
|
541
|
-
tx.pure(bcs_1.bcs
|
|
542
|
-
.vector(bcs_1.bcs.u8())
|
|
543
|
-
.serialize(casting_1.Casting.u8VectorFromString(lpCoinIconUrl))),
|
|
544
|
-
tx.pure(bcs_1.bcs
|
|
545
|
-
.vector(bcs_1.bcs.u64())
|
|
546
|
-
.serialize(coinsInfo.map((coin) => coin.weight))),
|
|
547
|
-
tx.pure.u64(inputs.poolFlatness),
|
|
548
|
-
tx.pure(bcs_1.bcs
|
|
549
|
-
.vector(bcs_1.bcs.u64())
|
|
550
|
-
.serialize(coinsInfo.map((coin) => coin.tradeFeeIn))),
|
|
551
|
-
tx.pure(bcs_1.bcs
|
|
552
|
-
.vector(bcs_1.bcs.u64())
|
|
553
|
-
.serialize(coinsInfo.map((coin) => coin.tradeFeeOut))),
|
|
554
|
-
tx.pure(bcs_1.bcs
|
|
555
|
-
.vector(bcs_1.bcs.u64())
|
|
556
|
-
.serialize(coinsInfo.map((coin) => coin.depositFee))),
|
|
557
|
-
tx.pure(bcs_1.bcs
|
|
558
|
-
.vector(bcs_1.bcs.u64())
|
|
559
|
-
.serialize(coinsInfo.map((coin) => coin.withdrawFee))),
|
|
560
|
-
...coinsInfo.map((coin) => typeof coin.coinId === "string"
|
|
561
|
-
? tx.object(coin.coinId)
|
|
562
|
-
: coin.coinId),
|
|
563
|
-
tx.pure(bcs_1.bcs
|
|
564
|
-
.option(bcs_1.bcs.vector(bcs_1.bcs.u8()))
|
|
565
|
-
.serialize(decimals.includes(undefined)
|
|
566
|
-
? undefined
|
|
567
|
-
: decimals)),
|
|
568
|
-
tx.pure.bool(inputs.respectDecimals),
|
|
569
|
-
tx.pure(bcs_1.bcs.option(bcs_1.bcs.u8()).serialize(inputs.forceLpDecimals)), // force_lp_decimals
|
|
570
|
-
],
|
|
571
|
-
});
|
|
572
|
-
});
|
|
573
|
-
/**
|
|
574
|
-
* Returns the pool object ID for a given LP coin type transaction.
|
|
575
|
-
* @param inputs - An object containing the transaction block and LP coin type.
|
|
576
|
-
* @returns The pool object ID.
|
|
577
|
-
*/
|
|
578
|
-
this.poolObjectIdForLpCoinTypeTx = (inputs) => {
|
|
579
|
-
const { tx, lpCoinType } = inputs;
|
|
580
|
-
return tx.moveCall({
|
|
581
|
-
target: utils_2.Helpers.transactions.createTxTarget(this.addresses.pools.packages.amm, PoolsApi.constants.moduleNames.poolRegistry, "lp_type_to_pool_id"),
|
|
582
|
-
typeArguments: [lpCoinType],
|
|
583
|
-
arguments: [tx.object(this.addresses.pools.objects.poolRegistry)],
|
|
584
|
-
});
|
|
585
|
-
};
|
|
801
|
+
this.buildDaoFeePoolUpdateFeeBpsTx = utils_2.Helpers.transactions.createBuildTxFunc(this.daoFeePoolUpdateFeeBpsTx);
|
|
802
|
+
this.buildDaoFeePoolUpdateFeeRecipientTx = utils_2.Helpers.transactions.createBuildTxFunc(this.daoFeePoolUpdateFeeRecipientTx);
|
|
586
803
|
// =========================================================================
|
|
587
804
|
// Inspections
|
|
588
805
|
// =========================================================================
|
|
@@ -659,7 +876,6 @@ class PoolsApi {
|
|
|
659
876
|
// =========================================================================
|
|
660
877
|
// Stats
|
|
661
878
|
// =========================================================================
|
|
662
|
-
// TODO: use promise.all to execute some of this fetching in parallel
|
|
663
879
|
/**
|
|
664
880
|
* Fetches statistics for a given pool.
|
|
665
881
|
* @param inputs An object containing the pool, trade events within a certain time frame, coins to price, and coins to decimals.
|
|
@@ -1091,14 +1307,22 @@ class PoolsApi {
|
|
|
1091
1307
|
this.withdrawV2EventType = () => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.pools.packages.eventsV2, PoolsApi.constants.moduleNames.events, PoolsApi.constants.eventNames.withdrawV2);
|
|
1092
1308
|
const pools = Provider.addresses.pools;
|
|
1093
1309
|
const referralVault = Provider.addresses.referralVault;
|
|
1310
|
+
const daoFeePools = Provider.addresses.daoFeePools;
|
|
1094
1311
|
if (!pools || !referralVault)
|
|
1095
1312
|
throw new Error("not all required addresses have been set in provider");
|
|
1096
1313
|
this.addresses = {
|
|
1097
1314
|
pools,
|
|
1098
1315
|
referralVault,
|
|
1316
|
+
daoFeePools,
|
|
1099
1317
|
};
|
|
1100
1318
|
this.objectTypes = {
|
|
1101
1319
|
pool: `${pools.packages.events}::pool::Pool`,
|
|
1320
|
+
daoFeePool: daoFeePools
|
|
1321
|
+
? `${daoFeePools.packages.amm}::pool::DaoFeePool`
|
|
1322
|
+
: undefined,
|
|
1323
|
+
daoFeePoolOwnerCap: daoFeePools
|
|
1324
|
+
? `${daoFeePools.packages.amm}::pool::OwnerCap`
|
|
1325
|
+
: undefined,
|
|
1102
1326
|
};
|
|
1103
1327
|
this.eventTypes = {
|
|
1104
1328
|
trade: this.tradeEventType(),
|
|
@@ -1108,8 +1332,7 @@ class PoolsApi {
|
|
|
1108
1332
|
depositV2: this.depositV2EventType(),
|
|
1109
1333
|
withdrawV2: this.withdrawV2EventType(),
|
|
1110
1334
|
};
|
|
1111
|
-
this.moveErrors = {
|
|
1112
|
-
[this.addresses.pools.packages.amm]: {
|
|
1335
|
+
this.moveErrors = Object.assign({ [this.addresses.pools.packages.amm]: {
|
|
1113
1336
|
[PoolsApi.constants.moduleNames.pool]: {
|
|
1114
1337
|
/// A user provides a input that should be between 0 and `FIXED_ONE` but isn't.
|
|
1115
1338
|
0: "Flatness Not Normalized",
|
|
@@ -1140,69 +1363,69 @@ class PoolsApi {
|
|
|
1140
1363
|
[PoolsApi.constants.moduleNames.poolRegistry]: {
|
|
1141
1364
|
/// A user tries to create a Pool and the generic parameters of `create_pool_n_coins` were
|
|
1142
1365
|
/// provided in nonlexicographical order.
|
|
1143
|
-
60: "
|
|
1366
|
+
60: "Not Sorted",
|
|
1144
1367
|
/// A user tries to create a Pool with exact parameters as an already active Pool.
|
|
1145
|
-
61: "
|
|
1368
|
+
61: "Duplicate Pool",
|
|
1146
1369
|
/// A user tries to upgrade the `PoolRegistry` to a value
|
|
1147
|
-
62: "
|
|
1370
|
+
62: "Invalid Upgrade",
|
|
1148
1371
|
},
|
|
1149
1372
|
[PoolsApi.constants.moduleNames.deposit]: {
|
|
1150
1373
|
/// A user attempts to perform a `deposit` with an older contract.
|
|
1151
|
-
20: "
|
|
1374
|
+
20: "Invalid Protocol Version",
|
|
1152
1375
|
/// A user attempts to perform `deposit-n-coins` on a Pool with a size `m` < `n`.
|
|
1153
|
-
21: "
|
|
1376
|
+
21: "Invalid Pool Size",
|
|
1154
1377
|
/// A user attempts to perform a deposit and provides a coin with a value of zero.
|
|
1155
|
-
22: "
|
|
1378
|
+
22: "Zero Value",
|
|
1156
1379
|
// A user calls `deposit_n_coins` or `all_coin_deposit_n_coins` and provides the same generic
|
|
1157
1380
|
// at least twice.
|
|
1158
|
-
23: "
|
|
1381
|
+
23: "Duplicate Types",
|
|
1159
1382
|
},
|
|
1160
1383
|
[PoolsApi.constants.moduleNames.poolFactory]: {
|
|
1161
1384
|
/// A user attempts to create a pool on an older contract.
|
|
1162
|
-
10: "
|
|
1385
|
+
10: "Invalid Protocol Version",
|
|
1163
1386
|
/// A user attempts to create a Pool and provides a coin with a value of zero.
|
|
1164
|
-
11: "
|
|
1387
|
+
11: "Zero Value",
|
|
1165
1388
|
},
|
|
1166
1389
|
[PoolsApi.constants.moduleNames.price]: {
|
|
1167
1390
|
/// A user attempts to query spot/oracle price using an old contract.
|
|
1168
|
-
10: "
|
|
1391
|
+
10: "Invalid Protocol Version",
|
|
1169
1392
|
},
|
|
1170
1393
|
[PoolsApi.constants.moduleNames.swap]: {
|
|
1171
1394
|
/// A user attempts to perform a `swap` with an older contract.
|
|
1172
|
-
40: "
|
|
1395
|
+
40: "Invalid Protocol Version",
|
|
1173
1396
|
/// A user attempts to perform `multi-swap-exact-in/out-n-to-m` on a Pool with a size
|
|
1174
1397
|
/// `s` < `n` + `m`.
|
|
1175
|
-
41: "
|
|
1398
|
+
41: "Invalid Pool Size",
|
|
1176
1399
|
/// A user attempts to perform swap and providing provides a coin with a
|
|
1177
1400
|
/// value of zero.
|
|
1178
|
-
42: "
|
|
1401
|
+
42: "Zero Value",
|
|
1179
1402
|
/// A user attempts to perform a multi-coin withdraw and provides an `amounts_out`
|
|
1180
1403
|
/// vector whose length does
|
|
1181
|
-
43: "
|
|
1404
|
+
43: "Bad Vector Length",
|
|
1182
1405
|
/// A user attempts to swap attempts to swap `Coin<CI>` for `amount_out` of `Coin<CO>`
|
|
1183
1406
|
/// but its value is insufficient.
|
|
1184
|
-
44: "
|
|
1407
|
+
44: "Insufficient Coin In",
|
|
1185
1408
|
// A user calls `multi_swap_exact_in_1_to_n` or `multi_swap_exact_out_1_to_n` and provides the same
|
|
1186
1409
|
// generic at least twice.
|
|
1187
|
-
45: "
|
|
1410
|
+
45: "Duplicate Types",
|
|
1188
1411
|
/// Something went wrong with the internal calculations
|
|
1189
|
-
46: "
|
|
1412
|
+
46: "Internal Error",
|
|
1190
1413
|
/// An external app is trying to call authorized functions without permission.
|
|
1191
|
-
47: "
|
|
1414
|
+
47: "Not Authorized",
|
|
1192
1415
|
},
|
|
1193
1416
|
[PoolsApi.constants.moduleNames.withdraw]: {
|
|
1194
1417
|
/// A user attempts to perform a `withdraw` with an older contract.
|
|
1195
|
-
30: "
|
|
1418
|
+
30: "Invalid Protocol Version",
|
|
1196
1419
|
/// A user attempts to perform `withdraw-n-coins` on a Pool with a size `m` < `n`.
|
|
1197
|
-
31: "
|
|
1420
|
+
31: "Invalid PoolSize",
|
|
1198
1421
|
/// A user attempts to perform a withdraw and provides an LP coin with a value of zero.
|
|
1199
|
-
32: "
|
|
1422
|
+
32: "Zero Value",
|
|
1200
1423
|
/// A user attempts to perform a multi-coin withdraw and provides an `amounts_out`
|
|
1201
1424
|
/// vector whose length does
|
|
1202
|
-
33: "
|
|
1425
|
+
33: "Bad Vector Length",
|
|
1203
1426
|
// A user calls `withdraw_n_coins` or `all_coin_withdraw_n_coins` and provides the same generic
|
|
1204
1427
|
// at least twice.
|
|
1205
|
-
34: "
|
|
1428
|
+
34: "Duplicate Types",
|
|
1206
1429
|
},
|
|
1207
1430
|
[PoolsApi.constants.moduleNames.math]: {
|
|
1208
1431
|
// TODO: change error code in move
|
|
@@ -1212,25 +1435,35 @@ class PoolsApi {
|
|
|
1212
1435
|
51: "Slippage",
|
|
1213
1436
|
/// A user tries to perform a swap that would result in more than `MAX_SWAP_AMOUNT_IN` worth of
|
|
1214
1437
|
/// one of the Pool's coins entering the Pool.
|
|
1215
|
-
52: "
|
|
1438
|
+
52: "Invalid Swap Amount In",
|
|
1216
1439
|
/// A user tries to perform a swap that would result in more than `MAX_SWAP_AMOUNT_OUT` worth of
|
|
1217
1440
|
/// one of the Pool's coins exiting the Pool.
|
|
1218
|
-
53: "
|
|
1441
|
+
53: "Invalid Swap Amount Out",
|
|
1219
1442
|
/// A user tries to perform a `swap_exact_out` with a value for `amount_out` that equates to
|
|
1220
1443
|
/// zero amount of `Coin<CI>`.
|
|
1221
|
-
54: "
|
|
1444
|
+
54: "Zero Amount In",
|
|
1222
1445
|
/// A user tries to perform a `swap_exact_in` with an amount of `Coin<CI>` that equates to
|
|
1223
1446
|
/// zero amount of `Coin<CO>`.
|
|
1224
|
-
55: "
|
|
1447
|
+
55: "Zero Amount Out",
|
|
1225
1448
|
/// A user tries to deposit into a Pool with a deposit that is worth zero LP coins.
|
|
1226
|
-
56: "
|
|
1449
|
+
56: "Zero Lp Out",
|
|
1227
1450
|
/// A user tries to invest with an lp ratio of 0
|
|
1228
|
-
57: "
|
|
1451
|
+
57: "Zero Lp Ratio",
|
|
1229
1452
|
},
|
|
1230
1453
|
[PoolsApi.constants.moduleNames.geometricMeanCalculations]: {},
|
|
1231
1454
|
[PoolsApi.constants.moduleNames.stableCalculations]: {},
|
|
1232
|
-
},
|
|
1233
|
-
|
|
1455
|
+
} }, (this.addresses.daoFeePools
|
|
1456
|
+
? {
|
|
1457
|
+
[this.addresses.daoFeePools.packages.amm]: {
|
|
1458
|
+
version: {
|
|
1459
|
+
/// A user tried to interact with an old contract.
|
|
1460
|
+
0: "Invalid Version",
|
|
1461
|
+
/// `init_package_version` has been called outside of this packages `init` function.
|
|
1462
|
+
1: "Version Object Already Created",
|
|
1463
|
+
},
|
|
1464
|
+
},
|
|
1465
|
+
}
|
|
1466
|
+
: {}));
|
|
1234
1467
|
}
|
|
1235
1468
|
// =========================================================================
|
|
1236
1469
|
// Events
|