@affluent-org/sdk 0.0.4 → 0.0.6
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/affluent.d.ts +3 -3
- package/dist/affluent.js +3 -3
- package/dist/common/computation.d.ts +6 -0
- package/dist/common/computation.js +54 -0
- package/dist/common/helper.d.ts +5 -0
- package/dist/common/helper.js +29 -0
- package/dist/common/service.d.ts +10 -2
- package/dist/common/service.js +56 -3
- package/dist/common/trace-action.d.ts +92 -0
- package/dist/common/trace-action.js +187 -0
- package/dist/common/transform.d.ts +87 -0
- package/dist/common/transform.js +264 -0
- package/dist/common/types.d.ts +140 -0
- package/dist/common/types.js +11 -0
- package/dist/context.d.ts +3 -0
- package/dist/context.js +9 -0
- package/dist/contracts/oracle/redstone-onchain-oracle/index.js +2 -0
- package/dist/contracts/oracle/redstone-onchain-oracle/type.d.ts +1 -1
- package/dist/contracts/vault/strategy-vault/index.d.ts +2 -1
- package/dist/contracts/vault/strategy-vault/index.js +1 -0
- package/dist/factorial.d.ts +18 -8
- package/dist/factorial.js +26 -14
- package/dist/index.d.ts +4 -2
- package/dist/index.js +18 -2
- package/dist/lib/send-msg.d.ts +16 -2
- package/dist/lib/send-msg.js +23 -2
- package/dist/monitor.js +2 -0
- package/dist/monitorCacheV1.js +3 -2
- package/dist/oracle/oracle.d.ts +3 -2
- package/dist/oracle/oracle.js +25 -2
- package/dist/pool.d.ts +41 -0
- package/dist/pool.js +146 -178
- package/dist/poolCacheV1.js +1 -0
- package/dist/rfq-auction.d.ts +2 -2
- package/dist/rfq-auction.js +6 -6
- package/dist/rfq-batch.d.ts +21 -11
- package/dist/rfq-batch.js +81 -9
- package/dist/services/composite-oracle/codec.d.ts +76 -0
- package/dist/services/composite-oracle/codec.js +281 -0
- package/dist/services/composite-oracle/computation.d.ts +8 -19
- package/dist/services/composite-oracle/computation.js +119 -76
- package/dist/services/composite-oracle/index.d.ts +2 -2
- package/dist/services/composite-oracle/index.js +5 -6
- package/dist/services/composite-oracle/query.d.ts +6 -6
- package/dist/services/composite-oracle/query.js +6 -47
- package/dist/services/pool/computation.d.ts +3 -9
- package/dist/services/pool/computation.js +12 -78
- package/dist/services/pool/index.d.ts +10 -59
- package/dist/services/pool/index.js +55 -8
- package/dist/services/pool/oracle.d.ts +2 -2
- package/dist/services/pool/query.d.ts +1 -1
- package/dist/services/pool/query.js +1 -1
- package/dist/services/pool/user/trace.d.ts +90 -0
- package/dist/services/pool/user/trace.js +168 -0
- package/dist/services/rfq-auction/index.d.ts +7 -23
- package/dist/services/rfq-auction/index.js +45 -6
- package/dist/services/rfq-auction/oracle.d.ts +2 -2
- package/dist/services/rfq-auction/user/index.js +1 -1
- package/dist/services/rfq-auction/user/trace.d.ts +53 -0
- package/dist/services/rfq-auction/user/trace.js +68 -0
- package/dist/services/rfq-batch/index.d.ts +16 -13
- package/dist/services/rfq-batch/index.js +34 -10
- package/dist/services/rfq-batch/oracle.d.ts +2 -2
- package/dist/services/rfq-batch/user/trace.d.ts +49 -0
- package/dist/services/rfq-batch/user/trace.js +67 -0
- package/dist/services/share-vault/index.d.ts +14 -88
- package/dist/services/share-vault/index.js +37 -10
- package/dist/services/share-vault/query.d.ts +5 -32
- package/dist/services/share-vault/query.js +25 -12
- package/dist/services/share-vault/user/trace.d.ts +54 -0
- package/dist/services/share-vault/user/trace.js +84 -0
- package/dist/services/strategy-vault/index.d.ts +77 -2115
- package/dist/services/strategy-vault/index.js +119 -54
- package/dist/services/strategy-vault/oracle.d.ts +3 -3
- package/dist/services/strategy-vault/oracle.js +1 -0
- package/dist/services/strategy-vault/owner/index.d.ts +2 -2
- package/dist/services/strategy-vault/owner/index.js +1 -1
- package/dist/services/strategy-vault/owner/types.d.ts +4 -0
- package/dist/services/strategy-vault/query.d.ts +14 -143
- package/dist/services/strategy-vault/query.js +28 -40
- package/dist/services/strategy-vault/user/trace.d.ts +156 -0
- package/dist/services/strategy-vault/user/trace.js +264 -0
- package/dist/share-vault.d.ts +164 -8
- package/dist/share-vault.js +222 -67
- package/dist/strategy_vault/base.d.ts +521 -105
- package/dist/strategy_vault/base.js +493 -41
- package/dist/strategy_vault/steps.d.ts +120 -3
- package/dist/strategy_vault/steps.js +161 -0
- package/dist/types/sender.d.ts +1 -0
- package/dist/utils/_parse_temp/StrategyVault.d.ts +9 -9
- package/dist/utils/_parse_temp/StrategyVault.js +48 -40
- package/dist/utils/_parse_temp/parseMsgBody.d.ts +2 -2
- package/dist/utils/_parse_temp/parseMsgBody.js +84 -84
- package/dist/utils/external-message-hash.d.ts +7 -3
- package/dist/utils/external-message-hash.js +20 -7
- package/dist/utils/oracle/redstone/helper.js +2 -0
- package/dist/utils/oracle/redstone/redstoneHelper.d.ts +7 -0
- package/dist/utils/oracle/redstone/redstoneHelper.js +103 -1
- package/dist/utils/pending-tracker/trackable-sender.d.ts +37 -4
- package/dist/utils/pending-tracker/trackable-sender.js +47 -8
- package/dist/utils/pending-tracker/v3-client.d.ts +16 -0
- package/dist/utils/pending-tracker/v3-client.js +80 -2
- package/dist/utils/risk_calculator/risk_calculator.d.ts +3 -3
- package/dist/utils/toncenter/index.d.ts +1 -0
- package/dist/utils/toncenter/index.js +17 -0
- package/dist/utils/toncenter/transform.d.ts +11 -0
- package/dist/utils/toncenter/transform.js +40 -0
- package/dist/utils/toncenter/type.d.ts +227 -0
- package/dist/utils/toncenter/type.js +2 -0
- package/package.json +3 -3
|
@@ -21,6 +21,9 @@ const redstoneHelper_1 = require("../utils/oracle/redstone/redstoneHelper");
|
|
|
21
21
|
const readonlyCachedRedstone_1 = require("../utils/oracle/redstone/readonlyCachedRedstone");
|
|
22
22
|
const oracle_1 = require("../oracle/oracle");
|
|
23
23
|
const unknown_contract_1 = require("../common/unknown-contract");
|
|
24
|
+
const oracle_v2_1 = require("../oracle/oracle-v2");
|
|
25
|
+
const share_vault_1 = require("../share-vault");
|
|
26
|
+
const versions_1 = require("../common/versions");
|
|
24
27
|
function jsonReplacer(_, value) {
|
|
25
28
|
if (typeof value === "bigint") {
|
|
26
29
|
return { __type: "bigint", value: value.toString() };
|
|
@@ -310,13 +313,33 @@ class StrategyVaultBase extends service_1.ServiceBaseV1 {
|
|
|
310
313
|
return oracleParams;
|
|
311
314
|
}
|
|
312
315
|
async sendDepositAsset(sender, params, value) {
|
|
316
|
+
const { opts, input } = await this._createInternalDepositAsset(sender, params, value);
|
|
317
|
+
await sender.send(input);
|
|
318
|
+
return opts;
|
|
319
|
+
}
|
|
320
|
+
async createInternalDepositAsset(sender, params, value) {
|
|
321
|
+
const { opts, input } = await this._createInternalDepositAsset(sender, params, value);
|
|
322
|
+
return input;
|
|
323
|
+
}
|
|
324
|
+
async _createInternalDepositAsset(sender, params, value) {
|
|
325
|
+
const vaultault = this.client.open(strategy_vault_1.StrategyVault.createFromAddress((0, utils_1.toAddress)(params.strategyVaultAddress)));
|
|
326
|
+
const vaultData = await vaultault.getVaultData();
|
|
327
|
+
const version = this.contractVersion.getVersion(vaultData.code);
|
|
328
|
+
if (version === versions_1.AffluentVersions.StrategyV1) {
|
|
329
|
+
return this._createInternalDepositAssetV1(sender, params, value);
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
return this._createInternalDepositAssetV2(sender, params, value);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
async _createInternalDepositAssetV1(sender, params, value) {
|
|
313
336
|
const vault = this.getVault(params.strategyVaultAddress);
|
|
314
337
|
const vaultData = await vault.getVaultData();
|
|
315
338
|
const oracle = new oracle_1.OracleLibs(this.client, this.network);
|
|
316
339
|
// need all assets in vault
|
|
317
340
|
const oraclePayload = await oracle.getOracleParamsForStrategyVault(vaultData, [params.assetAddress.toString(), ...Object.keys(vaultData.assets)]);
|
|
318
341
|
const isWTON = params.assetAddress.toString() === this.contracts.WTON ? true : false;
|
|
319
|
-
const forwardPayload = strategy_vault_1.StrategyVault.
|
|
342
|
+
const forwardPayload = strategy_vault_1.StrategyVault.createDepositPayloadV1(oraclePayload, isWTON ? (0, core_1.toNano)(0.02) : 0n, isWTON ? jetton_minter_2.WTON_UNWRAP_CELL : undefined);
|
|
320
343
|
const assetAddress = (0, utils_1.toAddress)(params.assetAddress);
|
|
321
344
|
const fee = vaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.Deposit] +
|
|
322
345
|
vaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.DepositLogic] +
|
|
@@ -333,50 +356,36 @@ class StrategyVaultBase extends service_1.ServiceBaseV1 {
|
|
|
333
356
|
// send to vault wton wallet
|
|
334
357
|
const wtonMaster = this.getByContract(jetton_minter_2.WTONMinter, assetAddress);
|
|
335
358
|
const wtonWallet = this.getByContract(jetton_wallet_2.WTONWallet, (0, utils_1.toAddress)(await wtonMaster.getWalletAddress(vault.address)));
|
|
336
|
-
|
|
359
|
+
return {
|
|
360
|
+
opts,
|
|
361
|
+
input: wtonWallet.createInternalExternalTransfer(value ?? jetton_wallet_2.WTONWallet.Gas.ExternalTransfer, opts),
|
|
362
|
+
};
|
|
337
363
|
}
|
|
338
364
|
else {
|
|
339
365
|
// send to sender jetton wallet
|
|
340
366
|
const jettonMaster = this.getByContract(jetton_minter_1.JettonMinter, assetAddress);
|
|
341
367
|
const jettonWalletAddress = await jettonMaster.getWalletAddress(sender.address);
|
|
342
368
|
const jettonWallet = this.getByContract(jetton_wallet_1.JettonWallet, jettonWalletAddress);
|
|
343
|
-
|
|
369
|
+
return {
|
|
370
|
+
opts,
|
|
371
|
+
input: jettonWallet.createInternalTransfer(value ?? fee + (0, core_1.toNano)(0.1), opts),
|
|
372
|
+
};
|
|
344
373
|
}
|
|
345
|
-
return opts;
|
|
346
|
-
}
|
|
347
|
-
async sendBurnVaultAsset(sender, params, value) {
|
|
348
|
-
const vault = this.getVault(params.strategyVaultAddress);
|
|
349
|
-
const vaultData = await vault.getVaultData();
|
|
350
|
-
const vaultAssetWalllet = await this.getVaultWallet(params.strategyVaultAddress, sender.address);
|
|
351
|
-
const oraclePayload = await this.getOracleParamsV2(params.strategyVaultAddress);
|
|
352
|
-
const withdrawAssetAddress = (0, utils_1.toAddress)(params.withdrawAssetAddress);
|
|
353
|
-
const isWTON = withdrawAssetAddress.toString() === this.contracts.WTON ? true : false;
|
|
354
|
-
const forwardPayload = strategy_vault_1.StrategyVault.createWithdrawPayload(withdrawAssetAddress, oraclePayload, isWTON ? (0, core_1.toNano)(0.02) : 0n, isWTON ? jetton_minter_2.WTON_UNWRAP_CELL : undefined);
|
|
355
|
-
const fee = vaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.Withdraw] +
|
|
356
|
-
vaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.WithdrawLogic] +
|
|
357
|
-
(isWTON ? (0, core_1.toNano)(0.02) : 0n) +
|
|
358
|
-
(0, core_1.toNano)(0.1);
|
|
359
|
-
const opts = {
|
|
360
|
-
amount: params.vaultShareAmountForBurn,
|
|
361
|
-
response: sender.address,
|
|
362
|
-
forwardPayload: forwardPayload,
|
|
363
|
-
queryId: createQueryId({ ...params, forwardPayload }),
|
|
364
|
-
};
|
|
365
|
-
await vaultAssetWalllet.sendBurn(sender, value ?? fee, opts);
|
|
366
|
-
return opts;
|
|
367
374
|
}
|
|
368
|
-
async
|
|
375
|
+
async _createInternalDepositAssetV2(sender, params, value) {
|
|
369
376
|
const vault = this.getVault(params.strategyVaultAddress);
|
|
370
377
|
const vaultData = await vault.getVaultData();
|
|
371
378
|
const oracle = new oracle_1.OracleLibs(this.client, this.network);
|
|
372
379
|
// need all assets in vault
|
|
373
380
|
const oraclePayload = await oracle.getOracleParamsForStrategyVault(vaultData, [params.assetAddress.toString(), ...Object.keys(vaultData.assets)]);
|
|
374
381
|
const isWTON = params.assetAddress.toString() === this.contracts.WTON ? true : false;
|
|
375
|
-
const
|
|
382
|
+
const jettonResponseTonAmount = isWTON ? (0, core_1.toNano)(0.02) : 0n;
|
|
383
|
+
const jettonResponsePayload = isWTON ? jetton_minter_2.WTON_UNWRAP_CELL : undefined;
|
|
384
|
+
const forwardPayload = strategy_vault_1.StrategyVault.createDepositPayload(sender.address, oraclePayload, jettonResponseTonAmount, jettonResponsePayload);
|
|
376
385
|
const assetAddress = (0, utils_1.toAddress)(params.assetAddress);
|
|
377
386
|
const fee = vaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.Deposit] +
|
|
378
387
|
vaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.DepositLogic] +
|
|
379
|
-
|
|
388
|
+
jettonResponseTonAmount;
|
|
380
389
|
const opts = {
|
|
381
390
|
recipient: vault.address,
|
|
382
391
|
amount: params.amount,
|
|
@@ -385,31 +394,49 @@ class StrategyVaultBase extends service_1.ServiceBaseV1 {
|
|
|
385
394
|
forwardPayload,
|
|
386
395
|
queryId: params.queryId ?? createQueryId({ ...params, forwardPayload }),
|
|
387
396
|
};
|
|
388
|
-
if (
|
|
389
|
-
// send to vault wton wallet
|
|
397
|
+
if (isWTON) {
|
|
390
398
|
const wtonMaster = this.getByContract(jetton_minter_2.WTONMinter, assetAddress);
|
|
391
399
|
const wtonWallet = this.getByContract(jetton_wallet_2.WTONWallet, (0, utils_1.toAddress)(await wtonMaster.getWalletAddress(vault.address)));
|
|
392
|
-
return
|
|
400
|
+
return {
|
|
401
|
+
opts,
|
|
402
|
+
input: wtonWallet.createInternalExternalTransfer(value ?? jetton_wallet_2.WTONWallet.Gas.ExternalTransfer, opts),
|
|
403
|
+
};
|
|
393
404
|
}
|
|
394
405
|
else {
|
|
395
406
|
// send to sender jetton wallet
|
|
396
407
|
const jettonMaster = this.getByContract(jetton_minter_1.JettonMinter, assetAddress);
|
|
397
408
|
const jettonWalletAddress = await jettonMaster.getWalletAddress(sender.address);
|
|
398
409
|
const jettonWallet = this.getByContract(jetton_wallet_1.JettonWallet, jettonWalletAddress);
|
|
399
|
-
return
|
|
410
|
+
return {
|
|
411
|
+
opts,
|
|
412
|
+
input: jettonWallet.createInternalTransfer(value ?? fee + (0, core_1.toNano)(0.1), opts),
|
|
413
|
+
};
|
|
400
414
|
}
|
|
401
415
|
}
|
|
416
|
+
async sendBurnVaultAsset(sender, params, value) {
|
|
417
|
+
const { opts, input } = await this._createInternalBurnVaultAsset(sender, params, value);
|
|
418
|
+
await sender.send(input);
|
|
419
|
+
return opts;
|
|
420
|
+
}
|
|
402
421
|
async createInternalBurnVaultAsset(sender, params, value) {
|
|
422
|
+
const { opts, input } = await this._createInternalBurnVaultAsset(sender, params, value);
|
|
423
|
+
return input;
|
|
424
|
+
}
|
|
425
|
+
async _createInternalBurnVaultAsset(sender, params, value) {
|
|
403
426
|
const vault = this.getVault(params.strategyVaultAddress);
|
|
404
427
|
const vaultData = await vault.getVaultData();
|
|
405
428
|
const vaultAssetWalllet = await this.getVaultWallet(params.strategyVaultAddress, sender.address);
|
|
406
|
-
const
|
|
429
|
+
const oracle = new oracle_1.OracleLibs(this.client, this.network);
|
|
430
|
+
// need all assets in vault
|
|
431
|
+
const oraclePayload = await oracle.getOracleParamsForStrategyVault(vaultData, [params.withdrawAssetAddress.toString(), ...Object.keys(vaultData.assets)]);
|
|
407
432
|
const withdrawAssetAddress = (0, utils_1.toAddress)(params.withdrawAssetAddress);
|
|
408
433
|
const isWTON = withdrawAssetAddress.toString() === this.contracts.WTON ? true : false;
|
|
409
|
-
const
|
|
434
|
+
const jettonResponseTonAmount = isWTON ? (0, core_1.toNano)(0.02) : 0n;
|
|
435
|
+
const jettonResponsePayload = isWTON ? jetton_minter_2.WTON_UNWRAP_CELL : undefined;
|
|
436
|
+
const forwardPayload = strategy_vault_1.StrategyVault.createWithdrawPayload(withdrawAssetAddress, oraclePayload, jettonResponseTonAmount, jettonResponsePayload);
|
|
410
437
|
const fee = vaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.Withdraw] +
|
|
411
438
|
vaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.WithdrawLogic] +
|
|
412
|
-
|
|
439
|
+
jettonResponseTonAmount +
|
|
413
440
|
(0, core_1.toNano)(0.1);
|
|
414
441
|
const opts = {
|
|
415
442
|
amount: params.vaultShareAmountForBurn,
|
|
@@ -417,22 +444,445 @@ class StrategyVaultBase extends service_1.ServiceBaseV1 {
|
|
|
417
444
|
forwardPayload: forwardPayload,
|
|
418
445
|
queryId: createQueryId({ ...params, forwardPayload }),
|
|
419
446
|
};
|
|
420
|
-
return
|
|
447
|
+
return {
|
|
448
|
+
opts,
|
|
449
|
+
input: vaultAssetWalllet.createInternalBurn(value ?? fee, opts),
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
async createInternalDepositQueue(sender, params) {
|
|
453
|
+
const assetAddress = (0, utils_1.toAddress)(params.assetAddress);
|
|
454
|
+
const isWTON = this.isWTON(assetAddress);
|
|
455
|
+
const vault = this.getVault(params.strategyVaultAddress);
|
|
456
|
+
const jettonForwardParams = params.jettonForwardParams ?? {};
|
|
457
|
+
const queueItemParams = params.queueItemParams ?? {};
|
|
458
|
+
queueItemParams.jettonForwardTonAmount ??= isWTON ? jetton_minter_2.WTON_UNWRAP_GAS : 0n;
|
|
459
|
+
queueItemParams.jettonForwardPayload ??= isWTON
|
|
460
|
+
? jetton_minter_2.WTON_UNWRAP_CELL
|
|
461
|
+
: undefined;
|
|
462
|
+
queueItemParams.actionForwardTonAmount ??= 0n;
|
|
463
|
+
const vaultData = await vault.getVaultData();
|
|
464
|
+
jettonForwardParams.forwardPayload ??=
|
|
465
|
+
strategy_vault_1.StrategyVault.createDepositQueuePayload(params.responseAddress ?? sender.address, queueItemParams.jettonForwardTonAmount, queueItemParams.jettonForwardPayload);
|
|
466
|
+
const isFirst = !vaultData.depositQueueManager.pendingAssetQueue[assetAddress.toString()]
|
|
467
|
+
?.dict[sender.address.toString()];
|
|
468
|
+
jettonForwardParams.forwardTonAmount ??=
|
|
469
|
+
strategy_vault_1.StrategyVault.calcQueueResistGas(vaultData, queueItemParams, isFirst) +
|
|
470
|
+
(0, core_1.toNano)(0.03); // buffer
|
|
471
|
+
const sendValue = params.value ?? jettonForwardParams.forwardTonAmount + (0, core_1.toNano)(0.1);
|
|
472
|
+
const opts = {
|
|
473
|
+
recipient: vault.address,
|
|
474
|
+
amount: params.amount,
|
|
475
|
+
response: sender.address,
|
|
476
|
+
forwardTonAmount: jettonForwardParams.forwardTonAmount,
|
|
477
|
+
forwardPayload: jettonForwardParams.forwardPayload,
|
|
478
|
+
queryId: params.queryId ?? createQueryId(params),
|
|
479
|
+
};
|
|
480
|
+
if (isWTON) {
|
|
481
|
+
// send to vault wton wallet
|
|
482
|
+
const wtonMaster = this.getByContract(jetton_minter_2.WTONMinter, assetAddress);
|
|
483
|
+
const wtonWallet = this.getByContract(jetton_wallet_2.WTONWallet, (0, utils_1.toAddress)(await wtonMaster.getWalletAddress(vault.address)));
|
|
484
|
+
return {
|
|
485
|
+
opts,
|
|
486
|
+
input: wtonWallet.createInternalExternalTransfer(sendValue, opts),
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
else {
|
|
490
|
+
// send to sender jetton wallet
|
|
491
|
+
const jettonMaster = this.getByContract(jetton_minter_1.JettonMinter, assetAddress);
|
|
492
|
+
const jettonWalletAddress = await jettonMaster.getWalletAddress(sender.address);
|
|
493
|
+
const jettonWallet = this.getByContract(jetton_wallet_1.JettonWallet, jettonWalletAddress);
|
|
494
|
+
return {
|
|
495
|
+
opts,
|
|
496
|
+
input: jettonWallet.createInternalTransfer(sendValue, opts),
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
async sendDepositQueue(sender, params) {
|
|
501
|
+
const { input, opts } = await this.createInternalDepositQueue(sender, params);
|
|
502
|
+
await sender.send({
|
|
503
|
+
to: input.to,
|
|
504
|
+
value: input.value,
|
|
505
|
+
body: input.body,
|
|
506
|
+
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY,
|
|
507
|
+
});
|
|
508
|
+
return opts;
|
|
509
|
+
}
|
|
510
|
+
async createInternalWithdrawQueue(sender, params) {
|
|
511
|
+
const assetAddress = (0, utils_1.toAddress)(params.assetAddress);
|
|
512
|
+
const isWTON = this.isWTON(assetAddress);
|
|
513
|
+
const vault = this.getVault(params.strategyVaultAddress);
|
|
514
|
+
const jettonForwardParams = params.jettonForwardParams ?? {};
|
|
515
|
+
const queueItemParams = params.queueItemParams ?? {};
|
|
516
|
+
queueItemParams.jettonForwardTonAmount ??= isWTON ? jetton_minter_2.WTON_UNWRAP_GAS : 0n;
|
|
517
|
+
queueItemParams.jettonForwardPayload ??= isWTON
|
|
518
|
+
? jetton_minter_2.WTON_UNWRAP_CELL
|
|
519
|
+
: undefined;
|
|
520
|
+
queueItemParams.actionForwardTonAmount ??= 0n;
|
|
521
|
+
const vaultData = await vault.getVaultData();
|
|
522
|
+
jettonForwardParams.forwardPayload ??=
|
|
523
|
+
strategy_vault_1.StrategyVault.createWithdrawQueuePayload(assetAddress, queueItemParams.jettonForwardTonAmount, queueItemParams.jettonForwardPayload, queueItemParams.actionForwardTonAmount, queueItemParams.actionForwardPayload);
|
|
524
|
+
const isFirst = !vaultData.withdrawQueueManager.pendingAssetQueue[assetAddress.toString()]
|
|
525
|
+
?.dict[sender.address.toString()];
|
|
526
|
+
jettonForwardParams.forwardTonAmount ??=
|
|
527
|
+
strategy_vault_1.StrategyVault.calcQueueResistGas(vaultData, queueItemParams, isFirst) +
|
|
528
|
+
(0, core_1.toNano)(0.03); // buffer
|
|
529
|
+
const sendValue = params.value ?? jettonForwardParams.forwardTonAmount + (0, core_1.toNano)(0.1);
|
|
530
|
+
const opts = {
|
|
531
|
+
amount: params.shareAmount,
|
|
532
|
+
response: sender.address,
|
|
533
|
+
forwardPayload: jettonForwardParams.forwardPayload,
|
|
534
|
+
queryId: params.queryId ?? createQueryId(params),
|
|
535
|
+
};
|
|
536
|
+
const vaultWalllet = await this.getVaultWallet(params.strategyVaultAddress, sender.address);
|
|
537
|
+
return {
|
|
538
|
+
opts,
|
|
539
|
+
input: vaultWalllet.createInternalBurn(sendValue, opts),
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
async sendWithdrawQueue(sender, params) {
|
|
543
|
+
const { input, opts } = await this.createInternalWithdrawQueue(sender, params);
|
|
544
|
+
await sender.send({
|
|
545
|
+
to: input.to,
|
|
546
|
+
value: input.value,
|
|
547
|
+
body: input.body,
|
|
548
|
+
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY,
|
|
549
|
+
});
|
|
550
|
+
return opts;
|
|
551
|
+
}
|
|
552
|
+
async createInternalCancelDepositQueue(params) {
|
|
553
|
+
const vault = this.getVault(params.strategyVaultAddress);
|
|
554
|
+
const opts = {
|
|
555
|
+
to: vault.address,
|
|
556
|
+
value: params.value ?? (0, core_1.toNano)(0.1),
|
|
557
|
+
assetAddress: (0, utils_1.toAddress)(params.assetAddress),
|
|
558
|
+
userAddress: (0, utils_1.toAddress)(params.userAddress),
|
|
559
|
+
queryId: params.queryId ?? createQueryId(params),
|
|
560
|
+
};
|
|
561
|
+
return {
|
|
562
|
+
opts,
|
|
563
|
+
input: strategy_vault_1.StrategyVault.createInternalCancelDepositQueue(opts),
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
async sendCancelDepositQueue(sender, params) {
|
|
567
|
+
const { input, opts } = await this.createInternalCancelDepositQueue(params);
|
|
568
|
+
await sender.send({
|
|
569
|
+
to: input.to,
|
|
570
|
+
value: input.value,
|
|
571
|
+
body: input.body,
|
|
572
|
+
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY,
|
|
573
|
+
});
|
|
574
|
+
return opts;
|
|
575
|
+
}
|
|
576
|
+
async createInternalCancelWithdrawQueue(params) {
|
|
577
|
+
const vault = this.getVault(params.strategyVaultAddress);
|
|
578
|
+
const opts = {
|
|
579
|
+
to: vault.address,
|
|
580
|
+
value: params.value ?? (0, core_1.toNano)(0.1),
|
|
581
|
+
assetAddress: (0, utils_1.toAddress)(params.assetAddress),
|
|
582
|
+
userAddress: (0, utils_1.toAddress)(params.userAddress),
|
|
583
|
+
queryId: params.queryId ?? createQueryId(params),
|
|
584
|
+
};
|
|
585
|
+
return {
|
|
586
|
+
opts,
|
|
587
|
+
input: strategy_vault_1.StrategyVault.createInternalCancelWithdrawQueue(opts),
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
async sendCancelWithdrawQueue(sender, params) {
|
|
591
|
+
const { input, opts } = await this.createInternalCancelWithdrawQueue(params);
|
|
592
|
+
await sender.send({
|
|
593
|
+
to: input.to,
|
|
594
|
+
value: input.value,
|
|
595
|
+
body: input.body,
|
|
596
|
+
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY,
|
|
597
|
+
});
|
|
598
|
+
return opts;
|
|
599
|
+
}
|
|
600
|
+
async createInternalConfirmQueue(params) {
|
|
601
|
+
const opts = {
|
|
602
|
+
to: (0, utils_1.toAddress)(params.strategyVaultAddress),
|
|
603
|
+
value: params.value ?? (0, core_1.toNano)(0.5),
|
|
604
|
+
depositAssets: params.depositAssets,
|
|
605
|
+
withdrawAssets: params.withdrawAssets,
|
|
606
|
+
oracleParams: params.oracleParams,
|
|
607
|
+
queryId: params.queryId ?? 0n,
|
|
608
|
+
};
|
|
609
|
+
return {
|
|
610
|
+
opts,
|
|
611
|
+
input: strategy_vault_1.StrategyVault.createInternalConfirmQueue(opts),
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
async sendConfirmQueue(sender, params) {
|
|
615
|
+
const vault = this.getVault(params.strategyVaultAddress);
|
|
616
|
+
const vaultData = await vault.getVaultData();
|
|
617
|
+
const gasConfig = vaultData.gasConfig;
|
|
618
|
+
const oracle = new oracle_1.OracleLibs(this.client, this.network);
|
|
619
|
+
// need all assets in vault
|
|
620
|
+
const oracleParams = await oracle.getOracleParamsForStrategyVault(vaultData, [...Object.keys(vaultData.assets)]);
|
|
621
|
+
const depositAssets = params.depositAssets ??
|
|
622
|
+
Object.entries(vaultData.depositQueueManager.pendingAssetQueue)
|
|
623
|
+
.filter(([key, value]) => {
|
|
624
|
+
return (value.sum > 0n &&
|
|
625
|
+
!vaultData.depositQueueManager.confirmedAssetQueue[key]);
|
|
626
|
+
})
|
|
627
|
+
.map(([key]) => (0, utils_1.toAddress)(key));
|
|
628
|
+
const withdrawAssets = params.withdrawAssets ??
|
|
629
|
+
Object.entries(vaultData.withdrawQueueManager.pendingAssetQueue)
|
|
630
|
+
.filter(([key, value]) => {
|
|
631
|
+
return (value.sum > 0n &&
|
|
632
|
+
!vaultData.withdrawQueueManager.confirmedAssetQueue[key]);
|
|
633
|
+
})
|
|
634
|
+
.map(([key]) => (0, utils_1.toAddress)(key));
|
|
635
|
+
const depositLogicGas = depositAssets.length
|
|
636
|
+
? gasConfig[strategy_vault_1.StrategyVault.GasKey.Deposit] +
|
|
637
|
+
gasConfig[strategy_vault_1.StrategyVault.GasKey.DepositLogic] *
|
|
638
|
+
BigInt(depositAssets.length)
|
|
639
|
+
: 0n;
|
|
640
|
+
const withdrawLogicGas = withdrawAssets.length
|
|
641
|
+
? gasConfig[strategy_vault_1.StrategyVault.GasKey.Withdraw] +
|
|
642
|
+
gasConfig[strategy_vault_1.StrategyVault.GasKey.WithdrawLogic] *
|
|
643
|
+
BigInt(withdrawAssets.length)
|
|
644
|
+
: 0n;
|
|
645
|
+
const estimateGas = withdrawLogicGas + depositLogicGas + (0, core_1.toNano)(0.05); // + buffer
|
|
646
|
+
const value = params.value ?? estimateGas + (0, core_1.toNano)(0.05); // + buffer
|
|
647
|
+
const queryId = params.queryId ?? 0n;
|
|
648
|
+
const { opts, input } = await this.createInternalConfirmQueue({
|
|
649
|
+
strategyVaultAddress: params.strategyVaultAddress,
|
|
650
|
+
depositAssets,
|
|
651
|
+
withdrawAssets,
|
|
652
|
+
oracleParams,
|
|
653
|
+
value,
|
|
654
|
+
queryId,
|
|
655
|
+
});
|
|
656
|
+
return await sender.send({
|
|
657
|
+
to: input.to,
|
|
658
|
+
value: input.value,
|
|
659
|
+
body: input.body,
|
|
660
|
+
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY,
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
async createInternalExecuteDepositQueue(sender, params) {
|
|
664
|
+
params.count ??= 50n;
|
|
665
|
+
const opts = {
|
|
666
|
+
to: (0, utils_1.toAddress)(params.strategyVaultAddress),
|
|
667
|
+
value: params.value ?? (0, core_1.toNano)(0.05),
|
|
668
|
+
asset: (0, utils_1.toAddress)(params.assetAddress),
|
|
669
|
+
count: params.count,
|
|
670
|
+
queryId: params.queryId ?? 0n,
|
|
671
|
+
};
|
|
672
|
+
return {
|
|
673
|
+
opts,
|
|
674
|
+
input: strategy_vault_1.StrategyVault.createInternalExecuteDepositQueue(opts),
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
async sendExecuteDepositQueue(sender, params) {
|
|
678
|
+
const { opts, input } = await this.createInternalExecuteDepositQueue(sender, params);
|
|
679
|
+
return await sender.send({
|
|
680
|
+
to: input.to,
|
|
681
|
+
value: input.value,
|
|
682
|
+
body: input.body,
|
|
683
|
+
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY,
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
async createInternalExecuteWithdrawQueue(sender, params) {
|
|
687
|
+
const opts = {
|
|
688
|
+
to: (0, utils_1.toAddress)(params.strategyVaultAddress),
|
|
689
|
+
value: params.value ?? (0, core_1.toNano)(0.05),
|
|
690
|
+
asset: (0, utils_1.toAddress)(params.assetAddress),
|
|
691
|
+
count: params.count ?? 50n,
|
|
692
|
+
queryId: params.queryId ?? 0n,
|
|
693
|
+
};
|
|
694
|
+
return {
|
|
695
|
+
opts,
|
|
696
|
+
input: strategy_vault_1.StrategyVault.createInternalExecuteWithdrawQueue(opts),
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
async sendExecuteWithdrawQueue(sender, params) {
|
|
700
|
+
const { opts, input } = await this.createInternalExecuteWithdrawQueue(sender, params);
|
|
701
|
+
return await sender.send({
|
|
702
|
+
to: input.to,
|
|
703
|
+
value: input.value,
|
|
704
|
+
body: input.body,
|
|
705
|
+
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY,
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
async sendDepositToVault(sender, params) {
|
|
709
|
+
const oracle = new oracle_v2_1.OracleLibsV2(this.client, this.network);
|
|
710
|
+
const strategyVault = this.getVault(params.strategyVaultAddress);
|
|
711
|
+
const strategyVaultData = await strategyVault.getVaultData();
|
|
712
|
+
const targetVaultType = await oracle.getAssetType(params.depositToVault);
|
|
713
|
+
const strategyResponseGas = strategyVaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.IncreaseBalance] +
|
|
714
|
+
strategyVaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.ActionNotification];
|
|
715
|
+
const bucket = new oracle_v2_1.AddressBucket();
|
|
716
|
+
let targetVaultOracleParams;
|
|
717
|
+
let forwardTonAmount = 0n;
|
|
718
|
+
if (targetVaultType.type === "share-vault") {
|
|
719
|
+
const depositToVault = this.getByContract(__1.ShareVault, params.depositToVault);
|
|
720
|
+
const shareVaultData = await depositToVault.getVaultData();
|
|
721
|
+
const shareVaultSupplyGas = __1.ShareVault.calculateGasFee(__1.ShareVault.Op.Supply, __1.ShareVault.Gas.baseFee, Object.keys(shareVaultData.whitelistedPools).length, shareVaultData.minimumGasFee);
|
|
722
|
+
forwardTonAmount = shareVaultSupplyGas + strategyResponseGas;
|
|
723
|
+
}
|
|
724
|
+
else if (targetVaultType.type === "strategy-vault") {
|
|
725
|
+
const depositToVault = this.getVault(params.depositToVault);
|
|
726
|
+
const depositToVaultData = await depositToVault.getVaultData();
|
|
727
|
+
const targetVaultOracleInfo = await oracle.getOracleParamsForStrategyVault(depositToVault.address, depositToVaultData, bucket);
|
|
728
|
+
targetVaultOracleParams = targetVaultOracleInfo.oracleParams;
|
|
729
|
+
const targetDepositGas = depositToVaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.Deposit];
|
|
730
|
+
forwardTonAmount =
|
|
731
|
+
(0, core_1.toNano)(bucket.totalSize() * 0.05) +
|
|
732
|
+
targetDepositGas +
|
|
733
|
+
strategyResponseGas;
|
|
734
|
+
}
|
|
735
|
+
else {
|
|
736
|
+
throw new Error("Invalid target vault type");
|
|
737
|
+
}
|
|
738
|
+
const { oracleParams } = await oracle.getOracleParamsForStrategyVault(strategyVault.address, strategyVaultData, bucket);
|
|
739
|
+
const vaultStrategyGas = (0, core_1.toNano)(bucket.totalSize() * 0.05) + // data agg & oracle
|
|
740
|
+
strategyVaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.VaultInteraction]; // send to vault
|
|
741
|
+
const sendValue = params.value ?? vaultStrategyGas + forwardTonAmount + (0, core_1.toNano)(0.1); // add buffer
|
|
742
|
+
await strategyVault.sendDepositToVault(sender, sendValue, {
|
|
743
|
+
oracleParams,
|
|
744
|
+
vaultInteractParams: {
|
|
745
|
+
vaultAddress: (0, utils_1.toAddress)(params.depositToVault),
|
|
746
|
+
assetAddress: (0, utils_1.toAddress)(params.assetAddress),
|
|
747
|
+
assetAmount: params.amount,
|
|
748
|
+
forwardTonAmount,
|
|
749
|
+
},
|
|
750
|
+
targetVaultOracleParams,
|
|
751
|
+
queryId: params.queryId,
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
async sendWithdrawFromVault(sender, params) {
|
|
755
|
+
const oracle = new oracle_v2_1.OracleLibsV2(this.client, this.network);
|
|
756
|
+
const strategyVault = this.getVault(params.strategyVaultAddress);
|
|
757
|
+
const strategyVaultData = await strategyVault.getVaultData();
|
|
758
|
+
const targetVaultType = await oracle.getAssetType(params.withdrawFromVault);
|
|
759
|
+
const strategyResponseGas = strategyVaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.IncreaseBalance] +
|
|
760
|
+
2n *
|
|
761
|
+
strategyVaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.ActionNotification];
|
|
762
|
+
const bucket = new oracle_v2_1.AddressBucket();
|
|
763
|
+
let targetVaultOracleParams;
|
|
764
|
+
let forwardTonAmount = 0n;
|
|
765
|
+
if (targetVaultType.type === "share-vault") {
|
|
766
|
+
const withdrawFromVault = this.getByContract(__1.ShareVault, params.withdrawFromVault);
|
|
767
|
+
const shareVaultData = await withdrawFromVault.getVaultData();
|
|
768
|
+
const { count } = await new share_vault_1.ShareVaultV1(this.client, this.network).estimateWithdrawLiquidityFulfillmentPoolCount(shareVaultData, params.withdrawAmount);
|
|
769
|
+
const targetWithdrawGas = __1.ShareVault.calculateGasFee(__1.ShareVault.Op.Withdraw, __1.ShareVault.Gas.baseFee, count, shareVaultData.minimumGasFee);
|
|
770
|
+
forwardTonAmount = targetWithdrawGas + strategyResponseGas + (0, core_1.toNano)(0.1); // add buffer
|
|
771
|
+
}
|
|
772
|
+
else if (targetVaultType.type === "strategy-vault") {
|
|
773
|
+
const withdrawFromVault = this.getVault(params.withdrawFromVault);
|
|
774
|
+
const withdrawFromVaultData = await withdrawFromVault.getVaultData();
|
|
775
|
+
const targetVaultOracleInfo = await oracle.getOracleParamsForStrategyVault(withdrawFromVault.address, withdrawFromVaultData, bucket);
|
|
776
|
+
targetVaultOracleParams = targetVaultOracleInfo.oracleParams;
|
|
777
|
+
const targetWithdrawGas = withdrawFromVaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.Withdraw];
|
|
778
|
+
forwardTonAmount =
|
|
779
|
+
(0, core_1.toNano)(bucket.totalSize() * 0.05) +
|
|
780
|
+
targetWithdrawGas +
|
|
781
|
+
strategyResponseGas;
|
|
782
|
+
}
|
|
783
|
+
else {
|
|
784
|
+
throw new Error("Invalid target vault type");
|
|
785
|
+
}
|
|
786
|
+
const { oracleParams } = await oracle.getOracleParamsForStrategyVault(strategyVault.address, strategyVaultData, bucket);
|
|
787
|
+
const vaultStrategyGas = (0, core_1.toNano)(bucket.totalSize() * 0.05) + // data agg & oracle
|
|
788
|
+
strategyVaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.VaultInteraction]; // send to vault
|
|
789
|
+
const sendValue = params.value ?? vaultStrategyGas + forwardTonAmount + (0, core_1.toNano)(0.1); // add buffer
|
|
790
|
+
await strategyVault.sendWithdrawFromVault(sender, sendValue, {
|
|
791
|
+
oracleParams,
|
|
792
|
+
vaultInteractParams: {
|
|
793
|
+
targetVaultAddress: (0, utils_1.toAddress)(params.withdrawFromVault),
|
|
794
|
+
targetVaultAmount: params.withdrawAmount,
|
|
795
|
+
assetAddress: (0, utils_1.toAddress)(params.assetAddress),
|
|
796
|
+
forwardTonAmount,
|
|
797
|
+
},
|
|
798
|
+
targetVaultOracleParams,
|
|
799
|
+
queryId: params.queryId,
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
async sendDepositToVaultQueue(sender, params) {
|
|
803
|
+
const oracle = new oracle_v2_1.OracleLibsV2(this.client, this.network);
|
|
804
|
+
const strategyVault = this.getVault(params.strategyVaultAddress);
|
|
805
|
+
const strategyVaultData = await strategyVault.getVaultData();
|
|
806
|
+
const targetVault = this.getByContract(strategy_vault_1.StrategyVault, params.depositToVaultQueue);
|
|
807
|
+
const targetVaultData = await targetVault.getVaultData();
|
|
808
|
+
const { oracleParams, bucket } = await oracle.getOracleParamsForStrategyVault(strategyVault.address, strategyVaultData);
|
|
809
|
+
const vaultStrategyGas = (0, core_1.toNano)(bucket.totalSize() * 0.05) + // data agg & oracle
|
|
810
|
+
strategyVaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.JettonTransfer] +
|
|
811
|
+
strategyVaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.VaultInteraction];
|
|
812
|
+
const forwardTonAmount = strategy_vault_1.StrategyVault.calcQueueResistGas(targetVaultData, {
|
|
813
|
+
actionForwardTonAmount: strategyVaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.ActionNotification],
|
|
814
|
+
jettonForwardTonAmount: strategyVaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.IncreaseBalance],
|
|
815
|
+
});
|
|
816
|
+
const sendValue = params.value ?? vaultStrategyGas + forwardTonAmount + (0, core_1.toNano)(0.1); // add buffer
|
|
817
|
+
await strategyVault.sendDepositToVaultQueue(sender, sendValue, {
|
|
818
|
+
oracleParams,
|
|
819
|
+
vaultQueueInteractParams: {
|
|
820
|
+
vaultAddress: (0, utils_1.toAddress)(params.depositToVaultQueue),
|
|
821
|
+
assetAddress: (0, utils_1.toAddress)(params.assetAddress),
|
|
822
|
+
assetAmount: params.amount,
|
|
823
|
+
},
|
|
824
|
+
queryId: params.queryId,
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
async sendWithdrawFromVaultQueue(sender, params) {
|
|
828
|
+
const oracle = new oracle_v2_1.OracleLibsV2(this.client, this.network);
|
|
829
|
+
const strategyVault = this.getVault(params.strategyVaultAddress);
|
|
830
|
+
const strategyVaultData = await strategyVault.getVaultData();
|
|
831
|
+
const targetVault = this.getByContract(strategy_vault_1.StrategyVault, params.withdrawFromVaultQueue);
|
|
832
|
+
const targetVaultData = await targetVault.getVaultData();
|
|
833
|
+
const { oracleParams, bucket } = await oracle.getOracleParamsForStrategyVault(strategyVault.address, strategyVaultData);
|
|
834
|
+
const vaultStrategyGas = (0, core_1.toNano)(bucket.totalSize() * 0.05) + // data agg & oracle
|
|
835
|
+
strategyVaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.JettonTransfer] +
|
|
836
|
+
strategyVaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.VaultInteraction];
|
|
837
|
+
const forwardTonAmount = strategy_vault_1.StrategyVault.calcQueueResistGas(targetVaultData, {
|
|
838
|
+
actionForwardTonAmount: strategyVaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.ActionNotification],
|
|
839
|
+
jettonForwardTonAmount: strategyVaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.IncreaseBalance],
|
|
840
|
+
});
|
|
841
|
+
const sendValue = params.value ?? vaultStrategyGas + forwardTonAmount + (0, core_1.toNano)(0.1); // add buffer
|
|
842
|
+
await strategyVault.sendWithdrawFromVaultQueue(sender, sendValue, {
|
|
843
|
+
oracleParams,
|
|
844
|
+
vaultQueueInteractParams: {
|
|
845
|
+
targetVaultAddress: (0, utils_1.toAddress)(params.withdrawFromVaultQueue),
|
|
846
|
+
targetVaultAmount: params.amount,
|
|
847
|
+
assetAddress: (0, utils_1.toAddress)(params.assetAddress),
|
|
848
|
+
},
|
|
849
|
+
queryId: params.queryId,
|
|
850
|
+
});
|
|
851
|
+
}
|
|
852
|
+
async sendDepositToVaultQueueCancel(sender, params) {
|
|
853
|
+
const strategyVault = this.getVault(params.strategyVaultAddress);
|
|
854
|
+
const assetAddress = (0, utils_1.toAddress)(params.assetAddress);
|
|
855
|
+
const sendValue = params.value ?? (0, core_1.toNano)(0.1);
|
|
856
|
+
await strategyVault.sendCancelDepositToVaultQueue(sender, sendValue, {
|
|
857
|
+
targetVaultAddress: (0, utils_1.toAddress)(params.depositToVaultQueue),
|
|
858
|
+
assetAddress,
|
|
859
|
+
queryId: params.queryId,
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
async sendWithdrawFromVaultQueueCancel(sender, params) {
|
|
863
|
+
const strategyVault = this.getVault(params.strategyVaultAddress);
|
|
864
|
+
const assetAddress = (0, utils_1.toAddress)(params.assetAddress);
|
|
865
|
+
const sendValue = params.value ?? (0, core_1.toNano)(0.1);
|
|
866
|
+
await strategyVault.sendCancelWithdrawFromVaultQueue(sender, sendValue, {
|
|
867
|
+
targetVaultAddress: (0, utils_1.toAddress)(params.withdrawFromVaultQueue),
|
|
868
|
+
assetAddress,
|
|
869
|
+
queryId: params.queryId,
|
|
870
|
+
});
|
|
421
871
|
}
|
|
422
872
|
async getRFQAuctionAddress(strategyVaultAddress, index) {
|
|
423
873
|
const strategyVault = this.getByContract(strategy_vault_1.StrategyVault, strategyVaultAddress);
|
|
424
|
-
return await strategyVault.
|
|
874
|
+
return await strategyVault.getRFQAddress(index);
|
|
425
875
|
}
|
|
426
876
|
async getRFQAuction(strategyVaultAddress, index) {
|
|
427
877
|
const strategyVault = this.getByContract(strategy_vault_1.StrategyVault, strategyVaultAddress);
|
|
428
|
-
const rfqAuction = this.getByContract(rfq_auction_1.RFQAuction, await strategyVault.
|
|
878
|
+
const rfqAuction = this.getByContract(rfq_auction_1.RFQAuction, await strategyVault.getRFQAddress(index));
|
|
429
879
|
return rfqAuction;
|
|
430
880
|
}
|
|
431
881
|
async sendCreateAmountRFQ(sender, params, value) {
|
|
432
882
|
const strategyVault = this.getVault(params.strategyVaultAddress);
|
|
433
883
|
const vaultData = await strategyVault.getVaultData();
|
|
434
884
|
const rfqIndex = vaultData.rfqIndex;
|
|
435
|
-
const rfqAuctionAddress = await strategyVault.
|
|
885
|
+
const rfqAuctionAddress = await strategyVault.getRFQAddress(rfqIndex);
|
|
436
886
|
const sellAssetAddress = (0, utils_1.toAddress)(params.sellAssetAddress);
|
|
437
887
|
const buyAssetAddress = (0, utils_1.toAddress)(params.buyAssetAddress);
|
|
438
888
|
const sellAssetRFQWallet = await this.getByContract(jetton_minter_1.JettonMinter, sellAssetAddress).getWalletAddress(rfqAuctionAddress);
|
|
@@ -475,7 +925,7 @@ class StrategyVaultBase extends service_1.ServiceBaseV1 {
|
|
|
475
925
|
const strategyVault = this.getVault(params.strategyVaultAddress);
|
|
476
926
|
const vaultData = await strategyVault.getVaultData();
|
|
477
927
|
const rfqIndex = vaultData.rfqIndex;
|
|
478
|
-
const rfqAuctionAddress = await strategyVault.
|
|
928
|
+
const rfqAuctionAddress = await strategyVault.getRFQAddress(rfqIndex);
|
|
479
929
|
const sellAssetAddress = (0, utils_1.toAddress)(params.sellAssetAddress);
|
|
480
930
|
const buyAssetAddress = (0, utils_1.toAddress)(params.buyAssetAddress);
|
|
481
931
|
const sellAssetRFQWallet = await this.getByContract(jetton_minter_1.JettonMinter, sellAssetAddress).getWalletAddress(rfqAuctionAddress);
|
|
@@ -590,7 +1040,7 @@ class StrategyVaultBase extends service_1.ServiceBaseV1 {
|
|
|
590
1040
|
async sendLiquidateToFactorial(sender, params, value) {
|
|
591
1041
|
const strategyVault = this.getByContract(strategy_vault_1.StrategyVault, params.strategyVaultAddress);
|
|
592
1042
|
const vaultData = await strategyVault.getVaultData();
|
|
593
|
-
const oraclePayload = await this.getOracleParamsV2(
|
|
1043
|
+
const oraclePayload = await this.getOracleParamsV2(strategyVault.address);
|
|
594
1044
|
const oracleCalculateGas = BigInt(Object.keys(vaultData.assets).length +
|
|
595
1045
|
Object.keys(vaultData.factorialPools).length) * (0, core_1.toNano)(0.05);
|
|
596
1046
|
await strategyVault.sendLiquidateToFactorial(sender, value ??
|
|
@@ -678,6 +1128,7 @@ class StrategyVaultBase extends service_1.ServiceBaseV1 {
|
|
|
678
1128
|
const { redstonePrices, onchainData: od } = await this.getRedstonePrices(assets, oracleConfig);
|
|
679
1129
|
const onchainData2 = await this.updateOnchainData(oracleConfig.assetOnchainDataInfo);
|
|
680
1130
|
const onchainData = { ...od, ...onchainData2 };
|
|
1131
|
+
this.updateOnchainInternalData(redstonePrices, onchainData);
|
|
681
1132
|
const prices = this.calculatePrices(redstonePrices, onchainData);
|
|
682
1133
|
const exposurePoolsData = {};
|
|
683
1134
|
for (let exposurePool of exposurePools) {
|
|
@@ -701,6 +1152,7 @@ class StrategyVaultBase extends service_1.ServiceBaseV1 {
|
|
|
701
1152
|
const { redstonePrices, onchainData: od } = await this.getRedstonePrices(assets, oracleConfig);
|
|
702
1153
|
const onchainData2 = await this.updateOnchainData(oracleConfig.assetOnchainDataInfo);
|
|
703
1154
|
const onchainData = { ...od, ...onchainData2 };
|
|
1155
|
+
this.updateOnchainInternalData(redstonePrices, onchainData);
|
|
704
1156
|
const prices = this.calculatePrices(redstonePrices, onchainData);
|
|
705
1157
|
const exposurePoolsData = {};
|
|
706
1158
|
for (let exposurePool of exposurePools) {
|