@affluent-org/sdk 0.0.9 → 0.0.11

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.
@@ -506,7 +506,7 @@ export declare function parseExecuteStrategyMsgBody(cell: Cell): {
506
506
  };
507
507
  export declare function createSupplyToFactorialMsgBody(pool: Address, asset: Address, amount: bigint, response: Address, queryID?: number): Cell;
508
508
  export declare function createWithdrawFromFactorialMsgBody(oracleParams: Cell, pool: Address, asset: Address, amount: bigint, isShare: boolean, response: Address, queryID?: number): Cell;
509
- export declare function createBorrowFromFactorialMsgBody(oracleParams: Cell, pool: Address, asset: Address, amount: bigint, isShare: boolean, response: Address, queryID?: number): Cell;
509
+ export declare function createBorrowFromFactorialMsgBody(oracleParams: Cell, poolOracleParams: Cell, pool: Address, asset: Address, amount: bigint, isShare: boolean, response: Address, queryID?: number): Cell;
510
510
  export declare function createRepayToFactorialMsgBody(pool: Address, asset: Address, amount: bigint, response: Address, queryID?: number): Cell;
511
511
  export declare function createLiquidateToFactorialMsgBody(oracleParams: Cell, pool: Address, borrower: Address, repayAsset: Address, seizeAsset: Address, repayAmount: bigint, response: Address, queryID?: number): Cell;
512
512
  export declare function parseSupplyToFactorialMsgBody(cell: Cell): {
@@ -1003,8 +1003,8 @@ function createSupplyToFactorialMsgBody(pool, asset, amount, response, queryID)
1003
1003
  function createWithdrawFromFactorialMsgBody(oracleParams, pool, asset, amount, isShare, response, queryID) {
1004
1004
  return (0, core_1.beginCell)().storeUint(constants_1.Op.ExecuteStrategy, 32).storeUint(queryID ?? 0, 64).storeRef(oracleParams).storeUint(constants_1.Op.WithdrawFromFactorial, 32).storeAddress(pool).storeAddress(asset).storeCoins(amount).storeBit(isShare).storeAddress(response).endCell();
1005
1005
  }
1006
- function createBorrowFromFactorialMsgBody(oracleParams, pool, asset, amount, isShare, response, queryID) {
1007
- return (0, core_1.beginCell)().storeUint(constants_1.Op.ExecuteStrategy, 32).storeUint(queryID ?? 0, 64).storeUint(constants_1.Op.BorrowFromFactorial, 32).storeMaybeRef(oracleParams).storeRef(oracleParams).storeAddress(pool).storeAddress(asset).storeCoins(amount).storeBit(isShare).storeAddress(response).endCell();
1006
+ function createBorrowFromFactorialMsgBody(oracleParams, poolOracleParams, pool, asset, amount, isShare, response, queryID) {
1007
+ return (0, core_1.beginCell)().storeUint(constants_1.Op.ExecuteStrategy, 32).storeUint(queryID ?? 0, 64).storeUint(constants_1.Op.BorrowFromFactorial, 32).storeMaybeRef(oracleParams).storeRef(poolOracleParams).storeAddress(pool).storeAddress(asset).storeCoins(amount).storeBit(isShare).storeAddress(response).endCell();
1008
1008
  }
1009
1009
  function createRepayToFactorialMsgBody(pool, asset, amount, response, queryID) {
1010
1010
  return (0, core_1.beginCell)().storeUint(constants_1.Op.ExecuteStrategy, 32).storeUint(queryID ?? 0, 64).storeUint(constants_1.Op.RepayToFactorial, 32).storeAddress(pool).storeAddress(asset).storeCoins(amount).storeAddress(response).endCell();
@@ -300,14 +300,12 @@ async function buildOracleParamsCell(assets, oracleConfig, pools, vaults) {
300
300
  const signers = new Set(oracleConfig.signers
301
301
  .map((s) => s.toLowerCase()));
302
302
  let helper;
303
- if (setEqual(signers, restonSigners)) {
304
- helper = (0, redstoneHelper_1.createRedstoneHelper)("prod");
305
- }
306
- else if (setEqual(signers, affluentSigners)) {
303
+ if (setEqual(signers, affluentSigners)) {
307
304
  helper = (0, redstoneHelper_1.createRedstoneCustomHelper)("http://aggregatora3loa-ktesxzhb-780180176.ap-northeast-2.elb.amazonaws.com");
308
305
  }
309
306
  else {
310
- throw new Error(`Invalid signers: ${[...signers]}`);
307
+ // setEqual(signers, restonSigners)
308
+ helper = (0, redstoneHelper_1.createRedstoneHelper)("prod");
311
309
  }
312
310
  // Fetch payload
313
311
  const payload = await helper.createPayload(requestParams.redstoneAssetNames);
@@ -81,7 +81,7 @@ async function createSupplyMsg(ctx, sender, params, value) {
81
81
  opts,
82
82
  input: {
83
83
  to: poolWTONWallet.address,
84
- value: value ?? jetton_wallet_2.WTONWallet.Gas.ExternalTransfer,
84
+ value: value ?? jetton_wallet_2.WTONWallet.Gas.ExternalTransfer + opts.amount + opts.forwardTonAmount,
85
85
  body: poolWTONWallet.createExternalTransferBody(opts),
86
86
  },
87
87
  };
@@ -207,7 +207,7 @@ async function createRepayMsg(ctx, sender, params, value) {
207
207
  opts,
208
208
  input: {
209
209
  to: poolWTONWallet.address,
210
- value: value ?? jetton_wallet_2.WTONWallet.Gas.ExternalTransfer,
210
+ value: value ?? jetton_wallet_2.WTONWallet.Gas.ExternalTransfer + opts.amount + opts.forwardTonAmount,
211
211
  body: poolWTONWallet.createExternalTransferBody(opts),
212
212
  },
213
213
  };
@@ -265,7 +265,7 @@ async function createLiquidateMsg(ctx, sender, params, value) {
265
265
  opts,
266
266
  input: {
267
267
  to: poolWTONWallet.address,
268
- value: value ?? jetton_wallet_2.WTONWallet.Gas.ExternalTransfer,
268
+ value: value ?? jetton_wallet_2.WTONWallet.Gas.ExternalTransfer + opts.amount + opts.forwardTonAmount,
269
269
  body: poolWTONWallet.createExternalTransferBody(opts),
270
270
  },
271
271
  };
@@ -31,6 +31,25 @@ export declare function createSlippageBidMsg(ctx: AffluentContext, sender: Addre
31
31
  to: import("@ton/core").Address;
32
32
  value: bigint;
33
33
  body: Cell;
34
+ init: {
35
+ code: Cell;
36
+ data: Cell;
37
+ } | undefined;
38
+ };
39
+ } | {
40
+ opts: {
41
+ recipient: import("@ton/core").Address;
42
+ response: import("@ton/core").Address;
43
+ amount: bigint;
44
+ forwardTonAmount: bigint;
45
+ forwardPayload: Cell;
46
+ queryId: bigint | undefined;
47
+ };
48
+ input: {
49
+ to: import("@ton/core").Address;
50
+ value: bigint;
51
+ body: Cell;
52
+ init?: undefined;
34
53
  };
35
54
  }>;
36
55
  export declare function createCancelBidMsg(ctx: AffluentContext, params: CancelBidParams, value?: bigint): Promise<{
@@ -74,7 +74,7 @@ async function createAmountBidMsg(ctx, sender, params, value) {
74
74
  opts,
75
75
  input: {
76
76
  to: wtonWallet.address,
77
- value: value ?? gas,
77
+ value: value ?? gas + opts.amount + forwardTonAmount,
78
78
  body: wtonWallet.createExternalTransferBody(opts),
79
79
  },
80
80
  };
@@ -140,8 +140,9 @@ async function createSlippageBidMsg(ctx, sender, params, value) {
140
140
  opts,
141
141
  input: {
142
142
  to: wtonWallet.address,
143
- value: value ?? gas,
143
+ value: value ?? gas + opts.amount + forwardTonAmount,
144
144
  body: wtonWallet.createExternalTransferBody(opts),
145
+ init: wtonWallet.init
145
146
  },
146
147
  };
147
148
  }
@@ -70,7 +70,7 @@ async function createWithdrawFromPoolMsg(ctx, params, value) {
70
70
  .storeUint(share_vault_1.ShareVault.Op.WithdrawFromPool, 32)
71
71
  .storeUint(opts.queryID ?? 0, 64)
72
72
  .storeAddress(poolAddress)
73
- .storeUint(opts.isShare ? 1 : 0, 1)
73
+ .storeBit(opts.isShare)
74
74
  .storeCoins(params.amount)
75
75
  .endCell();
76
76
  return {
@@ -541,6 +541,8 @@ export declare function createWithdrawFromFactorialMsg(ctx: AffluentContext, sen
541
541
  };
542
542
  poolData: import("../../..").PoolState;
543
543
  poolOraclePayload: Cell;
544
+ oraclePayload: Cell;
545
+ oracleCalculateGas: bigint;
544
546
  poolAddress: Address;
545
547
  assetAddress: Address;
546
548
  };
@@ -553,6 +555,7 @@ export declare function createWithdrawFromFactorialMsg(ctx: AffluentContext, sen
553
555
  export declare function createLiquidateToFactorialMsg(ctx: AffluentContext, sender: AddressSender, params: LiquidateToFactorialParams, value?: bigint): Promise<{
554
556
  opts: {
555
557
  strategyVault: import("@ton/core").OpenedContract<StrategyVault>;
558
+ pool: import("@ton/core").OpenedContract<Pool>;
556
559
  vaultData: {
557
560
  globalDepositValueCap: bigint;
558
561
  withdrawFeeRate: number;
@@ -676,6 +679,8 @@ export declare function createLiquidateToFactorialMsg(ctx: AffluentContext, send
676
679
  balance: bigint;
677
680
  code: Cell;
678
681
  };
682
+ poolData: import("../../..").PoolState;
683
+ poolOraclePayload: Cell;
679
684
  oraclePayload: Cell;
680
685
  oracleCalculateGas: bigint;
681
686
  poolAddress: Address;
@@ -43,7 +43,6 @@ const oracle_1 = require("../oracle");
43
43
  const share_vault_2 = require("../../share-vault");
44
44
  const computation_1 = require("../../../contracts/vault/strategy-vault/computation");
45
45
  const query_1 = require("../query");
46
- const oracle_2 = require("../oracle");
47
46
  __exportStar(require("./types"), exports);
48
47
  // ============================================================
49
48
  // Factorial Pool Operations
@@ -72,16 +71,19 @@ async function createBorrowFromFactorialMsg(ctx, sender, params, value) {
72
71
  params.assetAddress.toString(),
73
72
  ...Object.keys(vaultData.assets),
74
73
  ]);
75
- const oracleCalculateGas = BigInt(Object.keys(vaultData.assets).length + Object.keys(vaultData.factorialPools).length) * (0, core_1.toNano)(0.05);
76
- const poolAddress = (0, utils_1.toAddress)(params.poolAddress);
77
74
  const assetAddress = (0, utils_1.toAddress)(params.assetAddress);
75
+ const poolAddress = (0, utils_1.toAddress)(params.poolAddress);
76
+ const pool = ctx.getByContract(pool_1.Pool, poolAddress);
77
+ const poolData = await pool.getPoolData();
78
+ const poolOraclePayload = await oracleLibs.getOracleParamsForPool(poolData);
78
79
  const to = strategyVault.address;
80
+ const body = strategy_vault_1.StrategyVault.createBorrowFromFactorialMsgBody(oraclePayload, poolOraclePayload, poolAddress, assetAddress, params.assetAmount, params.isShare, sender.address, params.queryId);
81
+ const oracleCalculateGas = BigInt(Object.keys(vaultData.assets).length + Object.keys(vaultData.factorialPools).length) * (0, core_1.toNano)(0.05);
79
82
  const resolvedValue = value ??
80
83
  vaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.FactorialTransferOut] +
81
84
  vaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.ExecuteStrategy] +
82
85
  oracleCalculateGas +
83
86
  (0, core_1.toNano)(0.1);
84
- const body = strategy_vault_1.StrategyVault.createBorrowFromFactorialMsgBody(oraclePayload, poolAddress, assetAddress, params.assetAmount, params.isShare, sender.address, params.queryId);
85
87
  return {
86
88
  opts: { strategyVault, vaultData, oraclePayload, oracleCalculateGas, poolAddress, assetAddress },
87
89
  input: { to, value: resolvedValue, body },
@@ -113,20 +115,32 @@ async function createWithdrawFromFactorialMsg(ctx, sender, params, value) {
113
115
  const poolAddress = (0, utils_1.toAddress)(params.poolAddress);
114
116
  const assetAddress = (0, utils_1.toAddress)(params.assetAddress);
115
117
  const to = strategyVault.address;
118
+ const oracleCalculateGas = BigInt(Object.keys(vaultData.assets).length + Object.keys(vaultData.factorialPools).length) * (0, core_1.toNano)(0.05);
116
119
  const resolvedValue = value ??
117
120
  vaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.FactorialTransferOut] +
118
121
  vaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.ExecuteStrategy] +
122
+ oracleCalculateGas +
119
123
  (0, core_1.toNano)(0.1);
120
124
  const body = strategy_vault_1.StrategyVault.createWithdrawFromFactorialMsgBody(poolOraclePayload, poolAddress, assetAddress, params.assetAmount, params.isShare, sender.address, params.queryId);
125
+ const { oracleParams: oraclePayload } = await oracleLibs.getOracleParamsForStrategyVaultV2(vaultData, [
126
+ params.assetAddress.toString(),
127
+ ...Object.keys(vaultData.assets),
128
+ ]);
121
129
  return {
122
- opts: { strategyVault, pool, vaultData, poolData, poolOraclePayload, poolAddress, assetAddress },
130
+ opts: { strategyVault, pool, vaultData, poolData, poolOraclePayload, oraclePayload, oracleCalculateGas, poolAddress, assetAddress },
123
131
  input: { to, value: resolvedValue, body },
124
132
  };
125
133
  }
126
134
  async function createLiquidateToFactorialMsg(ctx, sender, params, value) {
127
135
  const strategyVault = ctx.getByContract(strategy_vault_1.StrategyVault, params.strategyVaultAddress);
136
+ const pool = ctx.getByContract(pool_1.Pool, params.poolAddress);
137
+ const oracleLibs = new oracle_1.OracleHelper(ctx);
128
138
  const vaultData = await strategyVault.getVaultData();
129
- const oraclePayload = await (0, oracle_2.getOracleParams)(ctx, strategyVault.address);
139
+ const poolData = await pool.getPoolData();
140
+ const poolOraclePayload = await oracleLibs.getOracleParamsForPool(poolData, [
141
+ params.repayAssetAddress.toString(),
142
+ params.seizeAssetAddress.toString(),
143
+ ]);
130
144
  const oracleCalculateGas = BigInt(Object.keys(vaultData.assets).length + Object.keys(vaultData.factorialPools).length) * (0, core_1.toNano)(0.05);
131
145
  const poolAddress = (0, utils_1.toAddress)(params.poolAddress);
132
146
  const borrowerAddress = (0, utils_1.toAddress)(params.borrowerAddress);
@@ -138,9 +152,14 @@ async function createLiquidateToFactorialMsg(ctx, sender, params, value) {
138
152
  vaultData.gasConfig[strategy_vault_1.StrategyVault.GasKey.ExecuteStrategy] +
139
153
  oracleCalculateGas +
140
154
  (0, core_1.toNano)(0.1);
141
- const body = strategy_vault_1.StrategyVault.createLiquidateToFactorialMsgBody(oraclePayload, poolAddress, borrowerAddress, repayAssetAddress, seizeAssetAddress, params.repayAmount, sender.address, params.queryId);
155
+ const { oracleParams: oraclePayload } = await oracleLibs.getOracleParamsForStrategyVaultV2(vaultData, [
156
+ params.repayAssetAddress.toString(),
157
+ params.seizeAssetAddress.toString(),
158
+ ...Object.keys(vaultData.assets),
159
+ ]);
160
+ const body = strategy_vault_1.StrategyVault.createLiquidateToFactorialMsgBody(poolOraclePayload, poolAddress, borrowerAddress, repayAssetAddress, seizeAssetAddress, params.repayAmount, sender.address, params.queryId);
142
161
  return {
143
- opts: { strategyVault, vaultData, oraclePayload, oracleCalculateGas, poolAddress, borrowerAddress, repayAssetAddress, seizeAssetAddress },
162
+ opts: { strategyVault, pool, vaultData, poolData, poolOraclePayload, oraclePayload, oracleCalculateGas, poolAddress, borrowerAddress, repayAssetAddress, seizeAssetAddress },
144
163
  input: { to, value: resolvedValue, body },
145
164
  };
146
165
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@affluent-org/sdk",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "affluent-sdk",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {