@affluent-org/sdk 0.0.5 → 0.0.7
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 +15 -21
- package/dist/common/transform.js +63 -150
- package/dist/common/types.d.ts +9 -13
- package/dist/common/types.js +2 -2
- 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/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/computation.d.ts +3 -8
- package/dist/services/composite-oracle/computation.js +91 -56
- package/dist/services/composite-oracle/index.js +4 -5
- package/dist/services/composite-oracle/query.js +1 -3
- package/dist/services/pool/computation.js +9 -61
- package/dist/services/pool/index.d.ts +10 -59
- package/dist/services/pool/index.js +71 -8
- 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 +55 -6
- 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 +9 -26
- package/dist/services/rfq-batch/index.js +48 -10
- 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 +12 -56
- package/dist/services/share-vault/index.js +57 -10
- package/dist/services/share-vault/query.js +1 -1
- 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 +68 -1981
- package/dist/services/strategy-vault/index.js +214 -53
- 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.js +1 -1
- 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/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
package/dist/affluent.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { PoolServiceV1 as PoolV1 } from "./services/pool";
|
|
2
2
|
import { ShareVaultServiceV1 as ShareVaultV1 } from "./services/share-vault";
|
|
3
|
-
import {
|
|
3
|
+
import { StrategyVaultServiceV1 } from "./services/strategy-vault";
|
|
4
4
|
import { RFQAuctionServiceV1 } from "./services/rfq-auction";
|
|
5
5
|
import { RFQBatchServiceV1 } from "./services/rfq-batch";
|
|
6
|
-
export { PoolV1, ShareVaultV1,
|
|
6
|
+
export { PoolV1, ShareVaultV1, StrategyVaultServiceV1, RFQAuctionServiceV1 as RFQAuctionV1, RFQBatchServiceV1 as RFQBatchV1 };
|
|
7
7
|
declare const _default: {
|
|
8
8
|
PoolV1: typeof PoolV1;
|
|
9
9
|
ShareVaultV1: typeof ShareVaultV1;
|
|
10
|
-
StrategyVaultV1: typeof
|
|
10
|
+
StrategyVaultV1: typeof StrategyVaultServiceV1;
|
|
11
11
|
RFQAuctionV1: typeof RFQAuctionServiceV1;
|
|
12
12
|
RFQBatchV1: typeof RFQBatchServiceV1;
|
|
13
13
|
};
|
package/dist/affluent.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RFQBatchV1 = exports.RFQAuctionV1 = exports.
|
|
3
|
+
exports.RFQBatchV1 = exports.RFQAuctionV1 = exports.StrategyVaultServiceV1 = exports.ShareVaultV1 = exports.PoolV1 = void 0;
|
|
4
4
|
const pool_1 = require("./services/pool");
|
|
5
5
|
Object.defineProperty(exports, "PoolV1", { enumerable: true, get: function () { return pool_1.PoolServiceV1; } });
|
|
6
6
|
const share_vault_1 = require("./services/share-vault");
|
|
7
7
|
Object.defineProperty(exports, "ShareVaultV1", { enumerable: true, get: function () { return share_vault_1.ShareVaultServiceV1; } });
|
|
8
8
|
const strategy_vault_1 = require("./services/strategy-vault");
|
|
9
|
-
Object.defineProperty(exports, "
|
|
9
|
+
Object.defineProperty(exports, "StrategyVaultServiceV1", { enumerable: true, get: function () { return strategy_vault_1.StrategyVaultServiceV1; } });
|
|
10
10
|
const rfq_auction_1 = require("./services/rfq-auction");
|
|
11
11
|
Object.defineProperty(exports, "RFQAuctionV1", { enumerable: true, get: function () { return rfq_auction_1.RFQAuctionServiceV1; } });
|
|
12
12
|
const rfq_batch_1 = require("./services/rfq-batch");
|
|
@@ -14,7 +14,7 @@ Object.defineProperty(exports, "RFQBatchV1", { enumerable: true, get: function (
|
|
|
14
14
|
exports.default = {
|
|
15
15
|
PoolV1: pool_1.PoolServiceV1,
|
|
16
16
|
ShareVaultV1: share_vault_1.ShareVaultServiceV1,
|
|
17
|
-
StrategyVaultV1: strategy_vault_1.
|
|
17
|
+
StrategyVaultV1: strategy_vault_1.StrategyVaultServiceV1,
|
|
18
18
|
RFQAuctionV1: rfq_auction_1.RFQAuctionServiceV1,
|
|
19
19
|
RFQBatchV1: rfq_batch_1.RFQBatchServiceV1,
|
|
20
20
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IAmountPosition, SyntheticCompositions, VaultCompositions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Try to decompose a synthetic/vault asset to its underlying assets
|
|
4
|
+
* Returns null if asset is native (no decomposition needed)
|
|
5
|
+
*/
|
|
6
|
+
export declare function tryNativeDecomposeAsset(asset: string, position: IAmountPosition, syntheticCompositions: SyntheticCompositions, vaultCompositions: VaultCompositions): Record<string, IAmountPosition>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// Position Decomposition Helpers
|
|
4
|
+
// ============================================================
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.tryNativeDecomposeAsset = tryNativeDecomposeAsset;
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
const helper_1 = require("./helper");
|
|
9
|
+
/**
|
|
10
|
+
* Try to decompose a synthetic/vault asset to its underlying assets
|
|
11
|
+
* Returns null if asset is native (no decomposition needed)
|
|
12
|
+
*/
|
|
13
|
+
function tryNativeDecomposeAsset(asset, position, syntheticCompositions, vaultCompositions) {
|
|
14
|
+
const data = syntheticCompositions[asset];
|
|
15
|
+
const result = {};
|
|
16
|
+
const vault = vaultCompositions[asset];
|
|
17
|
+
if (vault) {
|
|
18
|
+
// VAULT: Strategy Vault - uses decomposed positions
|
|
19
|
+
const vaultAmountCTX = vault.amountContext;
|
|
20
|
+
result;
|
|
21
|
+
Object.entries(vaultAmountCTX.decompose())
|
|
22
|
+
.forEach(([addr, pos]) => {
|
|
23
|
+
const vaultDecomposed = tryNativeDecomposeAsset(addr, position.cross(pos, vaultAmountCTX.totalSupply), syntheticCompositions, vaultCompositions);
|
|
24
|
+
(0, helper_1.applyPositions)(result, vaultDecomposed);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
else if (data?.assetType === types_1.CompositeAssetType.SYNTHETIC1 &&
|
|
28
|
+
"underlyingReserve" in data &&
|
|
29
|
+
data.underlyingReserve &&
|
|
30
|
+
data.totalSupply) {
|
|
31
|
+
// SYNTHETIC1: single underlying asset (e.g. stTON, tsTON)
|
|
32
|
+
const ratio = data.underlyingReserve;
|
|
33
|
+
const total = data.totalSupply;
|
|
34
|
+
const decomposed = tryNativeDecomposeAsset(data.underlyingAddress.toString(), position.muldiv(ratio, total), syntheticCompositions, vaultCompositions);
|
|
35
|
+
(0, helper_1.applyPositions)(result, decomposed);
|
|
36
|
+
}
|
|
37
|
+
else if (data?.assetType === types_1.CompositeAssetType.SYNTHETIC2 &&
|
|
38
|
+
"underlying0Reserve" in data &&
|
|
39
|
+
data.underlying0Reserve &&
|
|
40
|
+
data.underlying1Reserve &&
|
|
41
|
+
data.totalSupply) {
|
|
42
|
+
// SYNTHETIC2: two underlying assets (e.g. LP tokens)
|
|
43
|
+
const total = data.totalSupply;
|
|
44
|
+
const decomposed0 = tryNativeDecomposeAsset(data.underlying0Address.toString(), position.muldiv(data.underlying0Reserve, total), syntheticCompositions, vaultCompositions);
|
|
45
|
+
const decomposed1 = tryNativeDecomposeAsset(data.underlying1Address.toString(), position.muldiv(data.underlying1Reserve, total), syntheticCompositions, vaultCompositions);
|
|
46
|
+
(0, helper_1.applyPositions)(result, decomposed0);
|
|
47
|
+
(0, helper_1.applyPositions)(result, decomposed1);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// NATIVE: native asset (e.g. TON, USDT)
|
|
51
|
+
result[asset] = position.addPosition(result[asset]);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IPosition } from "./types";
|
|
2
|
+
export declare function copyPositions<P extends IPosition>(src: Record<string, P>): Record<string, P>;
|
|
3
|
+
export declare function applyPositions<P extends IPosition>(dst: Record<string, P>, src: Record<string, P>): void;
|
|
4
|
+
export declare function mergePositions<P extends IPosition>(a: Record<string, P>, b: Record<string, P>): void;
|
|
5
|
+
export declare function mapPositions<A extends string, P extends IPosition, R>(src: Record<A, P>, mapFn: (asset: A, position: P) => R): Record<A, R>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copyPositions = copyPositions;
|
|
4
|
+
exports.applyPositions = applyPositions;
|
|
5
|
+
exports.mergePositions = mergePositions;
|
|
6
|
+
exports.mapPositions = mapPositions;
|
|
7
|
+
function copyPositions(src) {
|
|
8
|
+
const result = {};
|
|
9
|
+
Object.entries(src)
|
|
10
|
+
.forEach(([asset, position]) => {
|
|
11
|
+
result[asset] = position.clone();
|
|
12
|
+
});
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
function applyPositions(dst, src) {
|
|
16
|
+
Object.entries(src)
|
|
17
|
+
.forEach(([asset, position]) => {
|
|
18
|
+
dst[asset] = position.addPosition(dst[asset]);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function mergePositions(a, b) {
|
|
22
|
+
return applyPositions(copyPositions(a), b);
|
|
23
|
+
}
|
|
24
|
+
function mapPositions(src, mapFn) {
|
|
25
|
+
const result = {};
|
|
26
|
+
Object.entries(copyPositions(src))
|
|
27
|
+
.forEach(([asset, position]) => result[asset] = mapFn(asset, position));
|
|
28
|
+
return result;
|
|
29
|
+
}
|
package/dist/common/service.d.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { Contract, OpenedContract, TonClient } from "@ton/ton";
|
|
2
2
|
import { ContractCache } from "./cache";
|
|
3
3
|
import { Address, Sender } from "@ton/core";
|
|
4
|
-
import { AddressInput } from "../contracts/common/type";
|
|
4
|
+
import { AddressInput, AddressLike } from "../contracts/common/type";
|
|
5
|
+
import { AssetType } from "./type";
|
|
6
|
+
import { ContractVersions } from "./versions";
|
|
7
|
+
import { AssetPriceInfo, OnchainDataInfo } from "../contracts/oracle/redstone-onchain-oracle/type";
|
|
5
8
|
export declare class ServiceBaseV1 {
|
|
6
9
|
readonly client: TonClient;
|
|
7
10
|
readonly network: "testnet" | "mainnet" | "custom";
|
|
11
|
+
static assetTypes: Record<string, AssetType>;
|
|
8
12
|
contracts: Record<string, string>;
|
|
9
13
|
readonly contractCache: ContractCache;
|
|
10
|
-
|
|
14
|
+
cache_ttl: number;
|
|
15
|
+
contractVersion: ContractVersions;
|
|
11
16
|
constructor(client: TonClient, network: "testnet" | "mainnet" | "custom", custom_contracts?: Record<string, string>, cache_ttl?: number);
|
|
17
|
+
isWTON(address: AddressLike): boolean;
|
|
12
18
|
getByContract<T extends Contract>(contractType: {
|
|
13
19
|
createFromAddress(address: Address): T;
|
|
14
20
|
name?: string;
|
|
@@ -17,4 +23,6 @@ export declare class ServiceBaseV1 {
|
|
|
17
23
|
getWalletSeq(address: Address): Promise<number>;
|
|
18
24
|
waitWalletSeq(address: Address, nextSeqno: number, sleepInterval?: number): Promise<number>;
|
|
19
25
|
deployWTONWallet(sender: Sender, owner: AddressInput): Promise<number>;
|
|
26
|
+
getAssetType(assetAddress: AddressInput): Promise<AssetType>;
|
|
27
|
+
updateOnchainInternalData(prices: AssetPriceInfo, onchainData: OnchainDataInfo): AssetPriceInfo;
|
|
20
28
|
}
|
package/dist/common/service.js
CHANGED
|
@@ -6,13 +6,20 @@ const cache_1 = require("./cache");
|
|
|
6
6
|
const core_1 = require("@ton/core");
|
|
7
7
|
const utils_1 = require("../contracts/common/utils");
|
|
8
8
|
const jetton_minter_1 = require("../contracts/wton/jetton-minter");
|
|
9
|
+
const share_vault_1 = require("../contracts/vault/share-vault");
|
|
10
|
+
const strategy_vault_1 = require("../contracts/vault/strategy-vault");
|
|
11
|
+
const versions_1 = require("./versions");
|
|
12
|
+
const type_1 = require("../contracts/oracle/redstone-onchain-oracle/type");
|
|
13
|
+
const redstone_onchain_oracle_1 = require("../contracts/oracle/redstone-onchain-oracle");
|
|
9
14
|
class ServiceBaseV1 {
|
|
10
15
|
client;
|
|
11
16
|
network;
|
|
17
|
+
static assetTypes = {};
|
|
12
18
|
contracts;
|
|
13
19
|
contractCache;
|
|
14
|
-
cache_ttl
|
|
15
|
-
|
|
20
|
+
cache_ttl;
|
|
21
|
+
contractVersion;
|
|
22
|
+
constructor(client, network, custom_contracts, cache_ttl = 2500) {
|
|
16
23
|
this.client = client;
|
|
17
24
|
this.network = network;
|
|
18
25
|
if (network === "custom" && !custom_contracts)
|
|
@@ -24,7 +31,11 @@ class ServiceBaseV1 {
|
|
|
24
31
|
? contracts_1.TESTNET_CONTRACTS
|
|
25
32
|
: custom_contracts;
|
|
26
33
|
this.contractCache = cache_1.ContractCache.getInstance();
|
|
27
|
-
this.cache_ttl = cache_ttl
|
|
34
|
+
this.cache_ttl = cache_ttl;
|
|
35
|
+
this.contractVersion = new versions_1.ContractVersions();
|
|
36
|
+
}
|
|
37
|
+
isWTON(address) {
|
|
38
|
+
return (0, utils_1.toAddress)(address).toString() === this.contracts.WTON;
|
|
28
39
|
}
|
|
29
40
|
getByContract(contractType, address_) {
|
|
30
41
|
const address = (0, utils_1.toAddress)(address_);
|
|
@@ -65,5 +76,47 @@ class ServiceBaseV1 {
|
|
|
65
76
|
});
|
|
66
77
|
return this.waitWalletSeq(sender.address, lastSeqno + 1);
|
|
67
78
|
}
|
|
79
|
+
async getAssetType(assetAddress) {
|
|
80
|
+
const address = (0, utils_1.toAddress)(assetAddress);
|
|
81
|
+
const state = await this.client.getContractState(address);
|
|
82
|
+
if (!state.data)
|
|
83
|
+
throw Error("no data");
|
|
84
|
+
const dataCell = core_1.Cell.fromBoc(state.data)[0];
|
|
85
|
+
try {
|
|
86
|
+
const assetInfo = {
|
|
87
|
+
type: "share-vault",
|
|
88
|
+
data: share_vault_1.ShareVault.parseVaultData(dataCell),
|
|
89
|
+
};
|
|
90
|
+
ServiceBaseV1.assetTypes[address.toString()] = assetInfo;
|
|
91
|
+
return assetInfo;
|
|
92
|
+
}
|
|
93
|
+
catch (_) { }
|
|
94
|
+
try {
|
|
95
|
+
const assetInfo = {
|
|
96
|
+
type: "strategy-vault",
|
|
97
|
+
data: strategy_vault_1.StrategyVault.parseVaultData(dataCell),
|
|
98
|
+
};
|
|
99
|
+
ServiceBaseV1.assetTypes[address.toString()] = assetInfo;
|
|
100
|
+
return assetInfo;
|
|
101
|
+
}
|
|
102
|
+
catch (_) { }
|
|
103
|
+
const assetInfo = {
|
|
104
|
+
type: "underlying-asset",
|
|
105
|
+
};
|
|
106
|
+
ServiceBaseV1.assetTypes[address.toString()] = assetInfo;
|
|
107
|
+
return assetInfo;
|
|
108
|
+
}
|
|
109
|
+
updateOnchainInternalData(prices, onchainData) {
|
|
110
|
+
for (const [asset, data] of Object.entries(onchainData)) {
|
|
111
|
+
if (data.sourceType === redstone_onchain_oracle_1.RedstoneOnchainOracle.SourceType.internal) {
|
|
112
|
+
prices[asset] = {
|
|
113
|
+
type: type_1.AssetType.Native,
|
|
114
|
+
price: data.price,
|
|
115
|
+
timestamp: Date.now(),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return prices;
|
|
120
|
+
}
|
|
68
121
|
}
|
|
69
122
|
exports.ServiceBaseV1 = ServiceBaseV1;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Address, Cell } from "@ton/core";
|
|
2
|
+
import { MessageHash } from "../utils/external-message-hash";
|
|
3
|
+
import { ToncenterTraceRaw } from "../utils/toncenter/type";
|
|
4
|
+
import { ToncenterV3Client } from "../utils/pending-tracker/v3-client";
|
|
5
|
+
export type Step = {
|
|
6
|
+
from: Address;
|
|
7
|
+
to: Address;
|
|
8
|
+
op?: number;
|
|
9
|
+
description?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function findStepTx(trace: ToncenterTraceRaw, step: Step): import("../utils/toncenter/type").ToncenterTransactionRaw | undefined;
|
|
12
|
+
export declare function getOpAndQueryId(body: Cell): {
|
|
13
|
+
op: number;
|
|
14
|
+
queryId: bigint;
|
|
15
|
+
};
|
|
16
|
+
export type JettonSendParams = {
|
|
17
|
+
isWTON: boolean;
|
|
18
|
+
actor: Address;
|
|
19
|
+
actorWallet: Address;
|
|
20
|
+
targetWallet: Address;
|
|
21
|
+
target: Address;
|
|
22
|
+
description?: string;
|
|
23
|
+
};
|
|
24
|
+
export type JettonReceiveParams = {
|
|
25
|
+
isWTON: boolean;
|
|
26
|
+
sourceWallet: Address;
|
|
27
|
+
actorWallet: Address;
|
|
28
|
+
description?: string;
|
|
29
|
+
};
|
|
30
|
+
export type BurnParams = {
|
|
31
|
+
actor: Address;
|
|
32
|
+
actorWallet: Address;
|
|
33
|
+
minter: Address;
|
|
34
|
+
description?: string;
|
|
35
|
+
};
|
|
36
|
+
export type MintParams = {
|
|
37
|
+
minter: Address;
|
|
38
|
+
actorWallet: Address;
|
|
39
|
+
description?: string;
|
|
40
|
+
};
|
|
41
|
+
export declare function createJettonSendSteps(params: JettonSendParams): Step[];
|
|
42
|
+
/**
|
|
43
|
+
* Starts from InternalTransfer (skips Transfer to avoid order issues with multi-destination sends)
|
|
44
|
+
* WTON: adds UnwrapNotification when actor is provided
|
|
45
|
+
*/
|
|
46
|
+
export declare function createJettonReceiveSteps(params: JettonReceiveParams & {
|
|
47
|
+
actor?: Address;
|
|
48
|
+
}): Step[];
|
|
49
|
+
export declare function createBurnSteps(params: BurnParams): Step[];
|
|
50
|
+
export declare function createMintSteps(params: MintParams): Step[];
|
|
51
|
+
export declare abstract class TracerBase<T> {
|
|
52
|
+
protected toncenterClient: ToncenterV3Client;
|
|
53
|
+
readonly extHash: MessageHash;
|
|
54
|
+
readonly type: T;
|
|
55
|
+
readonly queryId: bigint;
|
|
56
|
+
readonly steps: Step[];
|
|
57
|
+
readonly failStep?: Step | undefined;
|
|
58
|
+
static Progress: {
|
|
59
|
+
Pending: number;
|
|
60
|
+
Completed: number;
|
|
61
|
+
Failed: number;
|
|
62
|
+
Unknown: number;
|
|
63
|
+
};
|
|
64
|
+
static WaitConfig: {
|
|
65
|
+
MaxRetries: number;
|
|
66
|
+
IntervalMs: number;
|
|
67
|
+
};
|
|
68
|
+
protected waitingStep: number;
|
|
69
|
+
protected done: boolean;
|
|
70
|
+
constructor(toncenterClient: ToncenterV3Client, extHash: MessageHash, type: T, queryId: bigint, steps: Step[], failStep?: Step | undefined);
|
|
71
|
+
setToncenterClient(toncenterClient: ToncenterV3Client): this;
|
|
72
|
+
update(trace?: ToncenterTraceRaw): Promise<void>;
|
|
73
|
+
getWaitingStep(): {
|
|
74
|
+
progress: number;
|
|
75
|
+
description: string | undefined;
|
|
76
|
+
};
|
|
77
|
+
isTerminal(): boolean;
|
|
78
|
+
wait(): Promise<{
|
|
79
|
+
progress: number;
|
|
80
|
+
description: string | undefined;
|
|
81
|
+
}>;
|
|
82
|
+
}
|
|
83
|
+
export type SimpleTracerParams = {
|
|
84
|
+
extHash: MessageHash;
|
|
85
|
+
queryId: bigint;
|
|
86
|
+
actor: Address;
|
|
87
|
+
target: Address;
|
|
88
|
+
op: number;
|
|
89
|
+
};
|
|
90
|
+
export declare class SimpleTracer extends TracerBase<"simple"> {
|
|
91
|
+
constructor(toncenterClient: ToncenterV3Client, params: SimpleTracerParams);
|
|
92
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimpleTracer = exports.TracerBase = void 0;
|
|
4
|
+
exports.findStepTx = findStepTx;
|
|
5
|
+
exports.getOpAndQueryId = getOpAndQueryId;
|
|
6
|
+
exports.createJettonSendSteps = createJettonSendSteps;
|
|
7
|
+
exports.createJettonReceiveSteps = createJettonReceiveSteps;
|
|
8
|
+
exports.createBurnSteps = createBurnSteps;
|
|
9
|
+
exports.createMintSteps = createMintSteps;
|
|
10
|
+
const core_1 = require("@ton/core");
|
|
11
|
+
const jetton_wallet_1 = require("../contracts/jetton/jetton-wallet");
|
|
12
|
+
const jetton_wallet_2 = require("../contracts/wton/jetton-wallet");
|
|
13
|
+
function findStepTx(trace, step) {
|
|
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;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function getOpAndQueryId(body) {
|
|
24
|
+
const slice = body.beginParse();
|
|
25
|
+
const op = slice.loadUint(32);
|
|
26
|
+
const queryId = slice.loadUintBig(64);
|
|
27
|
+
return { op, queryId };
|
|
28
|
+
}
|
|
29
|
+
function createJettonSendSteps(params) {
|
|
30
|
+
const { isWTON, actor, actorWallet, targetWallet, target, description } = params;
|
|
31
|
+
if (isWTON) {
|
|
32
|
+
return [
|
|
33
|
+
{ op: jetton_wallet_2.WTONWallet.Op.ExternalTransfer, from: actor, to: targetWallet, description },
|
|
34
|
+
{ op: jetton_wallet_2.WTONWallet.Op.TransferNotification, from: targetWallet, to: target, description },
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
return [
|
|
38
|
+
{ op: jetton_wallet_1.JettonWallet.Op.Transfer, from: actor, to: actorWallet, description },
|
|
39
|
+
{ op: jetton_wallet_1.JettonWallet.Op.InternalTransfer, from: actorWallet, to: targetWallet, description },
|
|
40
|
+
{ op: jetton_wallet_1.JettonWallet.Op.TransferNotification, from: targetWallet, to: target, description },
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Starts from InternalTransfer (skips Transfer to avoid order issues with multi-destination sends)
|
|
45
|
+
* WTON: adds UnwrapNotification when actor is provided
|
|
46
|
+
*/
|
|
47
|
+
function createJettonReceiveSteps(params) {
|
|
48
|
+
const { isWTON, sourceWallet, actorWallet, actor, description } = params;
|
|
49
|
+
const Op = isWTON ? jetton_wallet_2.WTONWallet.Op : jetton_wallet_1.JettonWallet.Op;
|
|
50
|
+
const steps = [
|
|
51
|
+
{ op: Op.InternalTransfer, from: sourceWallet, to: actorWallet, description },
|
|
52
|
+
];
|
|
53
|
+
if (isWTON && actor) {
|
|
54
|
+
steps.push({ op: jetton_wallet_2.WTONWallet.Op.UnwrapNotification, from: actorWallet, to: actor, description: "Unwrapping WTON" });
|
|
55
|
+
}
|
|
56
|
+
return steps;
|
|
57
|
+
}
|
|
58
|
+
function createBurnSteps(params) {
|
|
59
|
+
const { actor, actorWallet, minter, description } = params;
|
|
60
|
+
return [
|
|
61
|
+
{ op: jetton_wallet_1.JettonWallet.Op.Burn, from: actor, to: actorWallet, description },
|
|
62
|
+
{ op: jetton_wallet_1.JettonWallet.Op.BurnNotification, from: actorWallet, to: minter, description },
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
function createMintSteps(params) {
|
|
66
|
+
const { minter, actorWallet, description } = params;
|
|
67
|
+
return [
|
|
68
|
+
{ op: jetton_wallet_1.JettonWallet.Op.InternalTransfer, from: minter, to: actorWallet, description },
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
// ============================================================
|
|
72
|
+
// TracerBase
|
|
73
|
+
// ============================================================
|
|
74
|
+
class TracerBase {
|
|
75
|
+
toncenterClient;
|
|
76
|
+
extHash;
|
|
77
|
+
type;
|
|
78
|
+
queryId;
|
|
79
|
+
steps;
|
|
80
|
+
failStep;
|
|
81
|
+
static Progress = {
|
|
82
|
+
Pending: 0,
|
|
83
|
+
Completed: 1,
|
|
84
|
+
Failed: -1,
|
|
85
|
+
Unknown: -2,
|
|
86
|
+
};
|
|
87
|
+
static WaitConfig = {
|
|
88
|
+
MaxRetries: 30,
|
|
89
|
+
IntervalMs: 2000,
|
|
90
|
+
};
|
|
91
|
+
waitingStep;
|
|
92
|
+
done;
|
|
93
|
+
constructor(toncenterClient, extHash, type, queryId, steps, failStep) {
|
|
94
|
+
this.toncenterClient = toncenterClient;
|
|
95
|
+
this.extHash = extHash;
|
|
96
|
+
this.type = type;
|
|
97
|
+
this.queryId = queryId;
|
|
98
|
+
this.steps = steps;
|
|
99
|
+
this.failStep = failStep;
|
|
100
|
+
this.waitingStep = 0;
|
|
101
|
+
this.done = false;
|
|
102
|
+
}
|
|
103
|
+
setToncenterClient(toncenterClient) {
|
|
104
|
+
this.toncenterClient = toncenterClient;
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
async update(trace) {
|
|
108
|
+
trace ??= await this.toncenterClient.pollDetailedTrace(this.extHash.base64);
|
|
109
|
+
if (trace?.trace_info?.trace_state === 'complete')
|
|
110
|
+
this.done = true;
|
|
111
|
+
if (this.waitingStep < 0)
|
|
112
|
+
return;
|
|
113
|
+
if (this.waitingStep >= this.steps.length)
|
|
114
|
+
return;
|
|
115
|
+
const step = this.steps[this.waitingStep];
|
|
116
|
+
const stepTx = findStepTx(trace, step);
|
|
117
|
+
if (stepTx) {
|
|
118
|
+
this.waitingStep++;
|
|
119
|
+
this.update(trace);
|
|
120
|
+
}
|
|
121
|
+
if (this.failStep && findStepTx(trace, this.failStep)) {
|
|
122
|
+
this.waitingStep = TracerBase.Progress.Failed;
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (trace.trace_info?.trace_state === 'complete' && this.waitingStep < this.steps.length) {
|
|
126
|
+
this.waitingStep = TracerBase.Progress.Unknown;
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
getWaitingStep() {
|
|
131
|
+
if (this.done && this.waitingStep === this.steps.length)
|
|
132
|
+
return {
|
|
133
|
+
progress: TracerBase.Progress.Completed,
|
|
134
|
+
description: "Completed"
|
|
135
|
+
};
|
|
136
|
+
if (this.waitingStep === TracerBase.Progress.Failed)
|
|
137
|
+
return {
|
|
138
|
+
progress: TracerBase.Progress.Failed,
|
|
139
|
+
description: this.failStep?.description
|
|
140
|
+
};
|
|
141
|
+
if (this.waitingStep === TracerBase.Progress.Unknown)
|
|
142
|
+
return {
|
|
143
|
+
progress: TracerBase.Progress.Unknown,
|
|
144
|
+
description: "Unknown error"
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
progress: this.waitingStep / this.steps.length,
|
|
148
|
+
description: this.steps[this.waitingStep].description,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
isTerminal() {
|
|
152
|
+
return this.done || this.waitingStep < 0;
|
|
153
|
+
}
|
|
154
|
+
async wait() {
|
|
155
|
+
const { MaxRetries, IntervalMs } = TracerBase.WaitConfig;
|
|
156
|
+
for (let i = 0; i < MaxRetries; i++) {
|
|
157
|
+
await this.update();
|
|
158
|
+
if (this.isTerminal()) {
|
|
159
|
+
const result = this.getWaitingStep();
|
|
160
|
+
console.log(result);
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
;
|
|
164
|
+
await new Promise(r => setTimeout(r, IntervalMs));
|
|
165
|
+
}
|
|
166
|
+
const result = this.getWaitingStep();
|
|
167
|
+
console.log(result);
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.TracerBase = TracerBase;
|
|
172
|
+
class SimpleTracer extends TracerBase {
|
|
173
|
+
constructor(toncenterClient, params) {
|
|
174
|
+
const { extHash, queryId, actor, target, op } = params;
|
|
175
|
+
const steps = [
|
|
176
|
+
{ op, from: actor, to: target, description: "Executing" },
|
|
177
|
+
];
|
|
178
|
+
const failStep = {
|
|
179
|
+
op: 0xffffffff,
|
|
180
|
+
from: target,
|
|
181
|
+
to: actor,
|
|
182
|
+
description: "Bounced",
|
|
183
|
+
};
|
|
184
|
+
super(toncenterClient, extHash, "simple", queryId, steps, failStep);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.SimpleTracer = SimpleTracer;
|
|
@@ -2,14 +2,16 @@ import { Address, Cell } from "@ton/core";
|
|
|
2
2
|
import { PoolState } from "../contracts/core/pool/type";
|
|
3
3
|
import { ShareVaultState } from "../contracts/vault/share-vault";
|
|
4
4
|
import { StrategyVaultState } from "../contracts/vault/strategy-vault";
|
|
5
|
-
import { Prices, IPosition, ISharePosition, IValuePosition, IAmountPosition, IPoolAsset, IPoolContext, IVaultStateContext, IVaultAmountContext, IVaultValueContext, IPoolAmountPositions, IPoolValuePositions, IPoolSharePositions, IPoolContexts
|
|
5
|
+
import { Prices, IPosition, ISharePosition, IValuePosition, IAmountPosition, IPoolAsset, IPoolContext, IVaultStateContext, IVaultAmountContext, IVaultValueContext, IPoolAmountPositions, IPoolValuePositions, IPoolSharePositions, IPoolContexts } from "./types";
|
|
6
6
|
export declare class Position implements IPosition {
|
|
7
|
-
supply: bigint;
|
|
8
|
-
borrow: bigint;
|
|
7
|
+
readonly supply: bigint;
|
|
8
|
+
readonly borrow: bigint;
|
|
9
9
|
constructor(supply?: bigint, borrow?: bigint);
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
add(supply: bigint, borrow: bigint): this;
|
|
11
|
+
addPosition(position?: typeof this): this;
|
|
12
|
+
muldiv(numerator: bigint, denominator: bigint): this;
|
|
12
13
|
clone(): this;
|
|
14
|
+
cross(other: typeof this, denominator: bigint): this;
|
|
13
15
|
}
|
|
14
16
|
export declare class SharePosition extends Position implements ISharePosition {
|
|
15
17
|
readonly _brand: 'SharePosition';
|
|
@@ -26,15 +28,6 @@ export declare class AmountPosition extends Position implements IAmountPosition
|
|
|
26
28
|
toValuePosition(price: bigint): ValuePosition;
|
|
27
29
|
net(): bigint;
|
|
28
30
|
}
|
|
29
|
-
export declare class AmountPositionWithAddress extends AmountPosition implements IAmountPositionWithAddress {
|
|
30
|
-
address: Address;
|
|
31
|
-
constructor(address: Address, supply: bigint, borrow: bigint);
|
|
32
|
-
static from(data: {
|
|
33
|
-
address: Address;
|
|
34
|
-
supply: bigint;
|
|
35
|
-
borrow: bigint;
|
|
36
|
-
}): AmountPositionWithAddress;
|
|
37
|
-
}
|
|
38
31
|
export declare class PoolAsset implements IPoolAsset {
|
|
39
32
|
amount: AmountPosition;
|
|
40
33
|
share: SharePosition;
|
|
@@ -65,22 +58,24 @@ export declare class VaultAmountContext implements IVaultAmountContext {
|
|
|
65
58
|
readonly assets: Record<string, IAmountPosition>;
|
|
66
59
|
readonly pools: IPoolAmountPositions;
|
|
67
60
|
constructor(address: string, totalSupply: bigint, assets: Record<string, IAmountPosition>, pools: IPoolAmountPositions);
|
|
68
|
-
static fromVaultStateContext(VaultStateContext:
|
|
61
|
+
static fromVaultStateContext(VaultStateContext: IVaultStateContext, poolContexts: IPoolContexts): VaultAmountContext;
|
|
69
62
|
toValueContext(prices: Prices): VaultValueContext;
|
|
70
|
-
|
|
63
|
+
decompose(): Record<string, IAmountPosition>;
|
|
64
|
+
nativeDecompose(prices: Prices): VaultNativeAmountDecomposedContext;
|
|
71
65
|
}
|
|
72
66
|
export declare class VaultValueContext implements IVaultValueContext {
|
|
73
67
|
readonly address: string;
|
|
68
|
+
readonly totalSupply: bigint;
|
|
74
69
|
readonly assets: Record<string, IValuePosition>;
|
|
75
70
|
readonly pools: IPoolValuePositions;
|
|
76
|
-
constructor(address: string, assets: Record<string, IValuePosition>, pools: IPoolValuePositions);
|
|
71
|
+
constructor(address: string, totalSupply: bigint, assets: Record<string, IValuePosition>, pools: IPoolValuePositions);
|
|
77
72
|
static fromAmountContext(amountContext: VaultAmountContext, prices: Prices): VaultValueContext;
|
|
78
73
|
get totalValue(): bigint;
|
|
79
|
-
|
|
74
|
+
get price(): bigint;
|
|
75
|
+
decompose(): Record<string, IValuePosition>;
|
|
80
76
|
}
|
|
81
77
|
export declare class VaultNativeValueDecomposedContext extends VaultValueContext {
|
|
82
78
|
static fromValueContext(valueContext: VaultValueContext, prices: Prices): VaultNativeValueDecomposedContext;
|
|
83
|
-
static decomposeContext(valueContext: Record<string, IValuePosition>, prices: Prices, nativeAssets: Record<string, IValuePosition>): Record<string, IValuePosition>;
|
|
84
79
|
net(): Record<string, IValuePosition>;
|
|
85
80
|
}
|
|
86
81
|
export declare class VaultNativeAmountDecomposedContext {
|
|
@@ -88,6 +83,5 @@ export declare class VaultNativeAmountDecomposedContext {
|
|
|
88
83
|
readonly totalSupply: bigint;
|
|
89
84
|
readonly assets: Record<string, IAmountPosition>;
|
|
90
85
|
constructor(address: string, totalSupply: bigint, assets: Record<string, IAmountPosition>);
|
|
91
|
-
|
|
92
|
-
static fromDecomposedValueContext(decomposedValueContext: VaultValueContext, prices: Prices): VaultNativeAmountDecomposedContext;
|
|
86
|
+
static fromAmountContext(valueContext: VaultAmountContext, prices: Prices): VaultNativeAmountDecomposedContext;
|
|
93
87
|
}
|