@affluent-org/sdk 0.0.7 → 0.0.9

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.
@@ -3,9 +3,9 @@ import { MessageHash } from "../utils/external-message-hash";
3
3
  import { ToncenterTraceRaw } from "../utils/toncenter/type";
4
4
  import { ToncenterV3Client } from "../utils/pending-tracker/v3-client";
5
5
  export type Step = {
6
- from: Address;
7
- to: Address;
8
6
  op?: number;
7
+ from?: Address;
8
+ to: Address;
9
9
  description?: string;
10
10
  };
11
11
  export declare function findStepTx(trace: ToncenterTraceRaw, step: Step): import("../utils/toncenter/type").ToncenterTransactionRaw | undefined;
@@ -12,12 +12,12 @@ const jetton_wallet_1 = require("../contracts/jetton/jetton-wallet");
12
12
  const jetton_wallet_2 = require("../contracts/wton/jetton-wallet");
13
13
  function findStepTx(trace, step) {
14
14
  return Object.values(trace.transactions).find(tx => {
15
- if (tx.in_msg) {
16
- return (step.op ? Number(tx.in_msg.opcode) === step.op : true)
17
- && step.from.equals(core_1.Address.parse(tx.in_msg.source))
18
- && step.to.equals(core_1.Address.parse(tx.in_msg.destination));
19
- }
20
- return false;
15
+ if (!tx.in_msg)
16
+ return false;
17
+ const opMatch = step.op === undefined || Number(tx.in_msg.opcode) === step.op;
18
+ const fromMatch = step.from === undefined || (tx.in_msg.source && step.from.equals(core_1.Address.parse(tx.in_msg.source)));
19
+ const toMatch = step.to.equals(core_1.Address.parse(tx.in_msg.destination));
20
+ return opMatch && fromMatch && toMatch;
21
21
  });
22
22
  }
23
23
  function getOpAndQueryId(body) {
@@ -77,8 +77,8 @@ class PoolContext {
77
77
  }
78
78
  static fromPoolState(poolState) {
79
79
  const assets = {};
80
- Object.entries(poolState.assets)
81
- .forEach(([asset, assetState]) => {
80
+ const accrueInterestAssets = pool_1.Pool.applyAccrueInterest(poolState.assets, poolState.protocolFeeRate);
81
+ Object.entries(accrueInterestAssets).forEach(([asset, assetState]) => {
82
82
  assets[asset] = {
83
83
  amount: new AmountPosition(assetState.totalSupplyAmount, assetState.totalBorrowAmount),
84
84
  share: new SharePosition(assetState.totalSupplyShare, assetState.totalBorrowShare),
@@ -118,6 +118,7 @@ export declare class Pool implements Contract {
118
118
  }) => Cell;
119
119
  static calculateGasFee(actionOp: number, baseFee: bigint, forwardFee: bigint, forwardTonAmount: bigint, useInternalOracle: boolean, useOracle: boolean, gas: PoolGasFee): bigint;
120
120
  getState(provider: ContractProvider): Promise<import("@ton/core").ContractState>;
121
+ static applyAccrueInterest(assets: Record<string, AssetState>, protocolFeeRate: bigint, time?: number): Record<string, AssetState>;
121
122
  static simulateAccrueInterest(poolState: PoolState, time?: number): PoolState;
122
123
  getPoolData(provider: ContractProvider): Promise<PoolState>;
123
124
  static parsePoolData(data: Slice): {
@@ -245,17 +245,17 @@ class Pool {
245
245
  async getState(provider) {
246
246
  return await provider.getState();
247
247
  }
248
- static simulateAccrueInterest(poolState, time) {
248
+ static applyAccrueInterest(assets, protocolFeeRate, time) {
249
249
  const currentTime = BigInt(time ?? BigInt(Math.floor(Date.now() / 1000)));
250
250
  const newAssets = {};
251
- Object.entries(poolState.assets).forEach(([assetAddress, assetInfo]) => {
251
+ Object.entries(assets).forEach(([assetAddress, assetInfo]) => {
252
252
  if (assetInfo.totalBorrowShare === 0n) {
253
253
  newAssets[assetAddress] = assetInfo;
254
254
  }
255
255
  else {
256
256
  const timeDelta = currentTime - assetInfo.lastUpdatedTime;
257
257
  const interest = (timeDelta * assetInfo.totalBorrowAmount * assetInfo.storedInterestRate) / 10n ** 36n;
258
- const protocolFee = (interest * poolState.protocolFeeRate) / 10000n;
258
+ const protocolFee = (interest * protocolFeeRate) / 10000n;
259
259
  newAssets[assetAddress] = {
260
260
  ...assetInfo,
261
261
  totalBorrowAmount: assetInfo.totalBorrowAmount + interest,
@@ -265,6 +265,10 @@ class Pool {
265
265
  };
266
266
  }
267
267
  });
268
+ return newAssets;
269
+ }
270
+ static simulateAccrueInterest(poolState, time) {
271
+ const newAssets = Pool.applyAccrueInterest(poolState.assets, poolState.protocolFeeRate, time);
268
272
  return {
269
273
  ...poolState,
270
274
  assets: newAssets,
@@ -10,15 +10,12 @@ export type InternalMessageInput = {
10
10
  export declare function sendMsg<T>(sender: AddressSender, msg: {
11
11
  opts: T;
12
12
  input: InternalMessageInput;
13
- }): Promise<T & {
14
- seqno: number;
15
- }>;
13
+ }): Promise<T>;
16
14
  export declare function sendMsgAndWaitTx<T>(ctx: AffluentContext, sender: AddressSender, msg: {
17
15
  opts: T;
18
16
  input: InternalMessageInput;
19
- }): Promise<T & {
17
+ }): Promise<Awaited<T> & {
20
18
  getExternalHash: () => Promise<import("../utils/external-message-hash").MessageHash>;
21
- seqno: number;
22
19
  }>;
23
20
  export declare function sendMsgAndWaitTxSimple(ctx: AffluentContext, sender: AddressSender, msg: {
24
21
  input: InternalMessageInput;
@@ -7,14 +7,15 @@ const core_1 = require("@ton/core");
7
7
  const trackable_sender_1 = require("../utils/pending-tracker/trackable-sender");
8
8
  const trace_action_1 = require("../common/trace-action");
9
9
  async function sendMsg(sender, msg) {
10
- const seqno = await sender.getSeqno();
11
10
  const { opts, input } = msg;
12
11
  await sender.send({ ...input, sendMode: core_1.SendMode.PAY_GAS_SEPARATELY });
13
- return { ...opts, seqno };
12
+ return { ...opts };
14
13
  }
15
14
  async function sendMsgAndWaitTx(ctx, sender, msg) {
15
+ const seqnoRes = await ctx.client.provider(sender.address).get("seqno", []);
16
+ const seqno = seqnoRes.stack.readNumber();
16
17
  const result = await sendMsg(sender, msg);
17
- const getExternalHash = () => (0, trackable_sender_1.pollExternalTransfer)(ctx.client, sender.address, result.seqno);
18
+ const getExternalHash = () => (0, trackable_sender_1.pollExternalTransfer)(ctx.client, sender.address, seqno);
18
19
  return { ...result, getExternalHash };
19
20
  }
20
21
  async function sendMsgAndWaitTxSimple(ctx, sender, msg) {
@@ -55,7 +55,7 @@ async function createSupplyMsg(ctx, sender, params, value) {
55
55
  opts,
56
56
  input: {
57
57
  to: vaultWTONWallet.address,
58
- value: value ?? jetton_wallet_2.WTONWallet.Gas.ExternalTransfer,
58
+ value: value ?? jetton_wallet_2.WTONWallet.Gas.ExternalTransfer + opts.amount + opts.forwardTonAmount,
59
59
  body: vaultWTONWallet.createExternalTransferBody(opts),
60
60
  },
61
61
  };
@@ -70,15 +70,16 @@ class ShareVaultWithdrawTracer extends trace_action_1.TracerBase {
70
70
  minter: addresses.vault,
71
71
  description: "Burning Vault Tokens",
72
72
  }),
73
- ...(0, trace_action_1.createJettonReceiveSteps)({
74
- isWTON,
75
- sourceWallet: addresses.vaultAssetWallet,
76
- actorWallet: addresses.actorAssetWallet,
77
- actor: addresses.actor,
78
- description: "Receiving Asset",
79
- }),
73
+ // from omitted: could come from vault or pool
74
+ { to: addresses.actorAssetWallet, description: "Receiving Asset" },
80
75
  ];
81
- super(toncenterClient, extHash, type, queryId, steps);
76
+ const failStep = {
77
+ op: jetton_wallet_1.JettonWallet.Op.InternalTransfer,
78
+ from: addresses.vault,
79
+ to: addresses.actorVaultWallet,
80
+ description: "Refunding Vault Tokens",
81
+ };
82
+ super(toncenterClient, extHash, type, queryId, steps, failStep);
82
83
  }
83
84
  }
84
85
  exports.ShareVaultWithdrawTracer = ShareVaultWithdrawTracer;
@@ -212,8 +212,8 @@ export declare class StrategyVaultServiceV1 {
212
212
  vaultStateContext: import("../../common/transform").VaultStateContext;
213
213
  amountContext: import("../../common/transform").VaultAmountContext;
214
214
  valueContext: import("../../common/transform").VaultValueContext;
215
- nativeValueDecomposedContext: import("../../common/transform").VaultNativeValueDecomposedContext;
216
215
  nativeAmountDecomposedContext: import("../../common/transform").VaultNativeAmountDecomposedContext;
216
+ nativeValueDecomposedContext: import("../../common/transform").VaultNativeValueDecomposedContext;
217
217
  priceInfo: import("../composite-oracle").CompositeOracleResult & {
218
218
  targetVaultAddress: string;
219
219
  price: bigint;
@@ -144,8 +144,8 @@ export declare function getValuationContext(ctx: AffluentContext, vaultAddress:
144
144
  vaultStateContext: VaultStateContext;
145
145
  amountContext: import("../../common/transform").VaultAmountContext;
146
146
  valueContext: import("../../common/transform").VaultValueContext;
147
- nativeValueDecomposedContext: VaultNativeValueDecomposedContext;
148
147
  nativeAmountDecomposedContext: VaultNativeAmountDecomposedContext;
148
+ nativeValueDecomposedContext: VaultNativeValueDecomposedContext;
149
149
  priceInfo: import("../composite-oracle").CompositeOracleResult & {
150
150
  targetVaultAddress: string;
151
151
  price: bigint;
@@ -87,14 +87,14 @@ async function getValuationContext(ctx, vaultAddress) {
87
87
  const vaultStateContext = transform_1.VaultStateContext.fromStrategyVaultState(vaultData);
88
88
  const amountContext = vaultStateContext.toAmountContext(poolContexts);
89
89
  const valueContext = amountContext.toValueContext(priceInfo.allPrices);
90
- const nativeValueDecomposedContext = transform_1.VaultNativeValueDecomposedContext.fromValueContext(valueContext, priceInfo.allPrices);
91
90
  const nativeAmountDecomposedContext = transform_1.VaultNativeAmountDecomposedContext.fromAmountContext(amountContext, priceInfo.allPrices);
91
+ const nativeValueDecomposedContext = transform_1.VaultNativeValueDecomposedContext.fromValueContext(valueContext, priceInfo.allPrices);
92
92
  return {
93
93
  vaultStateContext,
94
94
  amountContext,
95
95
  valueContext,
96
- nativeValueDecomposedContext,
97
96
  nativeAmountDecomposedContext,
97
+ nativeValueDecomposedContext,
98
98
  priceInfo,
99
99
  };
100
100
  }
@@ -95,8 +95,8 @@ class StrategyVaultWithdrawTracer extends trace_action_1.TracerBase {
95
95
  ];
96
96
  const failStep = {
97
97
  op: jetton_wallet_1.JettonWallet.Op.InternalTransfer,
98
- from: addresses.vaultWithdrawAssetWallet,
99
- to: addresses.actorWithdrawAssetWallet,
98
+ from: addresses.vault,
99
+ to: addresses.actorVaultWallet,
100
100
  description: "Refunding Withdraw Asset",
101
101
  };
102
102
  super(toncenterClient, extHash, type, queryId, steps, failStep);
@@ -1,7 +1,6 @@
1
1
  import { Address, Sender, SenderArguments } from "@ton/core";
2
2
  export interface AddressSender extends Sender {
3
3
  readonly address: Address;
4
- getSeqno(): Promise<number>;
5
4
  }
6
5
  export interface MultiSender extends AddressSender {
7
6
  multiSend(args: SenderArguments[]): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@affluent-org/sdk",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "affluent-sdk",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {