@affluent-org/sdk 0.0.1
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/.prettierrc +11 -0
- package/Refactoring.md +548 -0
- package/dist/_compiled/Account.compiled.json +1 -0
- package/dist/_compiled/Receipt.compiled.json +1 -0
- package/dist/_compiled/WTONWallet.compiled.json +1 -0
- package/dist/_compiled/index.d.ts +4 -0
- package/dist/_compiled/index.js +12 -0
- package/dist/affluent.d.ts +14 -0
- package/dist/affluent.js +20 -0
- package/dist/constants/constants.d.ts +2 -0
- package/dist/constants/constants.js +5 -0
- package/dist/constants/contracts.d.ts +9 -0
- package/dist/constants/contracts.js +18 -0
- package/dist/context.d.ts +43 -0
- package/dist/context.js +90 -0
- package/dist/contracts/common/type.d.ts +16 -0
- package/dist/contracts/common/type.js +2 -0
- package/dist/contracts/common/utils.d.ts +3 -0
- package/dist/contracts/common/utils.js +16 -0
- package/dist/contracts/core/account/index.d.ts +38 -0
- package/dist/contracts/core/account/index.js +128 -0
- package/dist/contracts/core/account/type.d.ts +18 -0
- package/dist/contracts/core/account/type.js +2 -0
- package/dist/contracts/core/pool/index.d.ts +149 -0
- package/dist/contracts/core/pool/index.js +379 -0
- package/dist/contracts/core/pool/serializer.d.ts +15 -0
- package/dist/contracts/core/pool/serializer.js +307 -0
- package/dist/contracts/core/pool/type.d.ts +136 -0
- package/dist/contracts/core/pool/type.js +2 -0
- package/dist/contracts/dedust-farm/MockDedustFarm.d.ts +41 -0
- package/dist/contracts/dedust-farm/MockDedustFarm.js +79 -0
- package/dist/contracts/external/tonstaker.d.ts +18 -0
- package/dist/contracts/external/tonstaker.js +26 -0
- package/dist/contracts/factory/factory.d.ts +24 -0
- package/dist/contracts/factory/factory.js +58 -0
- package/dist/contracts/factory/type.d.ts +11 -0
- package/dist/contracts/factory/type.js +2 -0
- package/dist/contracts/farm/distributor.d.ts +43 -0
- package/dist/contracts/farm/distributor.js +83 -0
- package/dist/contracts/farm/receipt.d.ts +40 -0
- package/dist/contracts/farm/receipt.js +68 -0
- package/dist/contracts/irm/jump-irm/serializer.d.ts +4 -0
- package/dist/contracts/irm/jump-irm/serializer.js +26 -0
- package/dist/contracts/irm/jump-irm/type.d.ts +8 -0
- package/dist/contracts/irm/jump-irm/type.js +2 -0
- package/dist/contracts/jetton/jetton-minter.d.ts +23 -0
- package/dist/contracts/jetton/jetton-minter.js +46 -0
- package/dist/contracts/jetton/jetton-wallet.d.ts +67 -0
- package/dist/contracts/jetton/jetton-wallet.js +119 -0
- package/dist/contracts/jetton/type.d.ts +7 -0
- package/dist/contracts/jetton/type.js +2 -0
- package/dist/contracts/liquid_token/dedust/minter.d.ts +56 -0
- package/dist/contracts/liquid_token/dedust/minter.js +112 -0
- package/dist/contracts/liquid_token/dedust/wallet.d.ts +127 -0
- package/dist/contracts/liquid_token/dedust/wallet.js +213 -0
- package/dist/contracts/liquid_token/stonfi/LFStonfiJettonMinter.d.ts +53 -0
- package/dist/contracts/liquid_token/stonfi/LFStonfiJettonMinter.js +110 -0
- package/dist/contracts/liquid_token/stonfi/LFStonfiJettonWallet.d.ts +169 -0
- package/dist/contracts/liquid_token/stonfi/LFStonfiJettonWallet.js +288 -0
- package/dist/contracts/oracle/composite-onchain-oracle/index.d.ts +108 -0
- package/dist/contracts/oracle/composite-onchain-oracle/index.js +185 -0
- package/dist/contracts/oracle/parser.d.ts +7 -0
- package/dist/contracts/oracle/parser.js +77 -0
- package/dist/contracts/oracle/redstone-onchain-oracle/index.d.ts +56 -0
- package/dist/contracts/oracle/redstone-onchain-oracle/index.js +159 -0
- package/dist/contracts/oracle/redstone-onchain-oracle/serializer.d.ts +4 -0
- package/dist/contracts/oracle/redstone-onchain-oracle/serializer.js +137 -0
- package/dist/contracts/oracle/redstone-onchain-oracle/type.d.ts +57 -0
- package/dist/contracts/oracle/redstone-onchain-oracle/type.js +18 -0
- package/dist/contracts/oracle/redstone-oracle/serializer.d.ts +3 -0
- package/dist/contracts/oracle/redstone-oracle/serializer.js +30 -0
- package/dist/contracts/oracle/redstone-oracle/type.d.ts +9 -0
- package/dist/contracts/oracle/redstone-oracle/type.js +2 -0
- package/dist/contracts/oracle/redstone-parser.d.ts +9 -0
- package/dist/contracts/oracle/redstone-parser.js +58 -0
- package/dist/contracts/rfq/rfq_auction/index.d.ts +216 -0
- package/dist/contracts/rfq/rfq_auction/index.js +334 -0
- package/dist/contracts/rfq/rfq_batch/index.d.ts +346 -0
- package/dist/contracts/rfq/rfq_batch/index.js +448 -0
- package/dist/contracts/rfq/rfq_event_emitter/index.d.ts +132 -0
- package/dist/contracts/rfq/rfq_event_emitter/index.js +143 -0
- package/dist/contracts/stonfi-farm/MockStonfiFarmItem.d.ts +41 -0
- package/dist/contracts/stonfi-farm/MockStonfiFarmItem.js +83 -0
- package/dist/contracts/stonfi-farm/MockStonfiFarmMinter.d.ts +45 -0
- package/dist/contracts/stonfi-farm/MockStonfiFarmMinter.js +92 -0
- package/dist/contracts/unknown-contract/index.d.ts +14 -0
- package/dist/contracts/unknown-contract/index.js +18 -0
- package/dist/contracts/vault/share-vault/index.d.ts +206 -0
- package/dist/contracts/vault/share-vault/index.js +373 -0
- package/dist/contracts/vault/strategy-vault/codec.d.ts +710 -0
- package/dist/contracts/vault/strategy-vault/codec.js +1256 -0
- package/dist/contracts/vault/strategy-vault/computation.d.ts +11 -0
- package/dist/contracts/vault/strategy-vault/computation.js +56 -0
- package/dist/contracts/vault/strategy-vault/constants.d.ts +163 -0
- package/dist/contracts/vault/strategy-vault/constants.js +170 -0
- package/dist/contracts/vault/strategy-vault/index.d.ts +587 -0
- package/dist/contracts/vault/strategy-vault/index.js +406 -0
- package/dist/contracts/vault/strategy-vault/type.d.ts +115 -0
- package/dist/contracts/vault/strategy-vault/type.js +2 -0
- package/dist/contracts/wton/jetton-minter.d.ts +35 -0
- package/dist/contracts/wton/jetton-minter.js +71 -0
- package/dist/contracts/wton/jetton-wallet.d.ts +90 -0
- package/dist/contracts/wton/jetton-wallet.js +153 -0
- package/dist/contracts/wton/type.d.ts +7 -0
- package/dist/contracts/wton/type.js +2 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +65 -0
- package/dist/lib/assert.d.ts +1 -0
- package/dist/lib/assert.js +9 -0
- package/dist/lib/query-cache.d.ts +5 -0
- package/dist/lib/query-cache.js +57 -0
- package/dist/lib/send-msg.d.ts +11 -0
- package/dist/lib/send-msg.js +9 -0
- package/dist/services/composite-oracle/computation.d.ts +55 -0
- package/dist/services/composite-oracle/computation.js +295 -0
- package/dist/services/composite-oracle/index.d.ts +45 -0
- package/dist/services/composite-oracle/index.js +110 -0
- package/dist/services/composite-oracle/query.d.ts +36 -0
- package/dist/services/composite-oracle/query.js +251 -0
- package/dist/services/composite-oracle/types.d.ts +82 -0
- package/dist/services/composite-oracle/types.js +11 -0
- package/dist/services/pool/computation.d.ts +75 -0
- package/dist/services/pool/computation.js +219 -0
- package/dist/services/pool/index.d.ts +94 -0
- package/dist/services/pool/index.js +139 -0
- package/dist/services/pool/oracle.d.ts +20 -0
- package/dist/services/pool/oracle.js +61 -0
- package/dist/services/pool/owner/index.d.ts +37 -0
- package/dist/services/pool/owner/index.js +76 -0
- package/dist/services/pool/owner/types.d.ts +18 -0
- package/dist/services/pool/owner/types.js +2 -0
- package/dist/services/pool/query.d.ts +64 -0
- package/dist/services/pool/query.js +282 -0
- package/dist/services/pool/user/index.d.ts +86 -0
- package/dist/services/pool/user/index.js +285 -0
- package/dist/services/pool/user/types.d.ts +44 -0
- package/dist/services/pool/user/types.js +2 -0
- package/dist/services/rfq-auction/index.d.ts +81 -0
- package/dist/services/rfq-auction/index.js +93 -0
- package/dist/services/rfq-auction/oracle.d.ts +19 -0
- package/dist/services/rfq-auction/oracle.js +60 -0
- package/dist/services/rfq-auction/query.d.ts +50 -0
- package/dist/services/rfq-auction/query.js +19 -0
- package/dist/services/rfq-auction/user/index.d.ts +63 -0
- package/dist/services/rfq-auction/user/index.js +218 -0
- package/dist/services/rfq-auction/user/types.d.ts +29 -0
- package/dist/services/rfq-auction/user/types.js +2 -0
- package/dist/services/rfq-batch/index.d.ts +78 -0
- package/dist/services/rfq-batch/index.js +132 -0
- package/dist/services/rfq-batch/oracle.d.ts +22 -0
- package/dist/services/rfq-batch/oracle.js +54 -0
- package/dist/services/rfq-batch/query.d.ts +46 -0
- package/dist/services/rfq-batch/query.js +34 -0
- package/dist/services/rfq-batch/user/index.d.ts +79 -0
- package/dist/services/rfq-batch/user/index.js +171 -0
- package/dist/services/rfq-batch/user/types.d.ts +37 -0
- package/dist/services/rfq-batch/user/types.js +2 -0
- package/dist/services/share-vault/computation.d.ts +24 -0
- package/dist/services/share-vault/computation.js +42 -0
- package/dist/services/share-vault/index.d.ts +90 -0
- package/dist/services/share-vault/index.js +128 -0
- package/dist/services/share-vault/manager/index.d.ts +40 -0
- package/dist/services/share-vault/manager/index.js +111 -0
- package/dist/services/share-vault/manager/types.d.ts +23 -0
- package/dist/services/share-vault/manager/types.js +2 -0
- package/dist/services/share-vault/owner/index.d.ts +64 -0
- package/dist/services/share-vault/owner/index.js +122 -0
- package/dist/services/share-vault/owner/types.d.ts +33 -0
- package/dist/services/share-vault/owner/types.js +2 -0
- package/dist/services/share-vault/query.d.ts +34 -0
- package/dist/services/share-vault/query.js +138 -0
- package/dist/services/share-vault/user/index.d.ts +33 -0
- package/dist/services/share-vault/user/index.js +106 -0
- package/dist/services/share-vault/user/types.d.ts +13 -0
- package/dist/services/share-vault/user/types.js +2 -0
- package/dist/services/strategy-vault/index.d.ts +2124 -0
- package/dist/services/strategy-vault/index.js +268 -0
- package/dist/services/strategy-vault/manager/index.d.ts +1968 -0
- package/dist/services/strategy-vault/manager/index.js +475 -0
- package/dist/services/strategy-vault/manager/types.d.ts +144 -0
- package/dist/services/strategy-vault/manager/types.js +2 -0
- package/dist/services/strategy-vault/oracle.d.ts +66 -0
- package/dist/services/strategy-vault/oracle.js +162 -0
- package/dist/services/strategy-vault/owner/index.d.ts +277 -0
- package/dist/services/strategy-vault/owner/index.js +333 -0
- package/dist/services/strategy-vault/owner/types.d.ts +146 -0
- package/dist/services/strategy-vault/owner/types.js +2 -0
- package/dist/services/strategy-vault/query.d.ts +138 -0
- package/dist/services/strategy-vault/query.js +59 -0
- package/dist/services/strategy-vault/user/index.d.ts +89 -0
- package/dist/services/strategy-vault/user/index.js +219 -0
- package/dist/services/strategy-vault/user/types.d.ts +46 -0
- package/dist/services/strategy-vault/user/types.js +2 -0
- package/dist/types/sender.d.ts +7 -0
- package/dist/types/sender.js +2 -0
- package/dist/utils/action-parser.d.ts +7 -0
- package/dist/utils/action-parser.js +20 -0
- package/dist/utils/external-message-hash.d.ts +45 -0
- package/dist/utils/external-message-hash.js +65 -0
- package/dist/utils/oracle/redstone/readonlyCachedRedstone.d.ts +3 -0
- package/dist/utils/oracle/redstone/readonlyCachedRedstone.js +25 -0
- package/dist/utils/oracle/redstone/redstoneHelper.d.ts +21 -0
- package/dist/utils/oracle/redstone/redstoneHelper.js +228 -0
- package/dist/utils/parser.d.ts +40 -0
- package/dist/utils/parser.js +580 -0
- package/dist/utils/pending-tracker/index.d.ts +14 -0
- package/dist/utils/pending-tracker/index.js +34 -0
- package/dist/utils/pending-tracker/trackable-sender.d.ts +16 -0
- package/dist/utils/pending-tracker/trackable-sender.js +87 -0
- package/dist/utils/pending-tracker/type.d.ts +78 -0
- package/dist/utils/pending-tracker/type.js +2 -0
- package/dist/utils/pending-tracker/v3-client.d.ts +31 -0
- package/dist/utils/pending-tracker/v3-client.js +104 -0
- package/dist/utils/risk_calculator/risk_calculator.d.ts +45 -0
- package/dist/utils/risk_calculator/risk_calculator.js +332 -0
- package/dist/utils/utils.d.ts +5 -0
- package/dist/utils/utils.js +12 -0
- package/package.json +46 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type ContractInfo = {
|
|
2
|
+
name: string;
|
|
3
|
+
type: "wton" | "token" | "pool" | "factory";
|
|
4
|
+
};
|
|
5
|
+
export declare const MAINNET_WTON = "EQDIKEz2BYLnTRWo5W5a6moZ9PXNtyOVOFF7noi8Ufv3axz_";
|
|
6
|
+
export declare const TESTNET_WTON = "EQBrWuWrQGw_xlm5XpImjWWSVsH56WFXfGm-j-VoP2njlC4s";
|
|
7
|
+
export declare const MAINNET_CONTRACTS: Record<string, ContractInfo>;
|
|
8
|
+
export declare const TESTNET_CONTRACTS: Record<string, ContractInfo>;
|
|
9
|
+
export declare function findAddressByType(contracts: Record<string, ContractInfo>, type: ContractInfo["type"]): string | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TESTNET_CONTRACTS = exports.MAINNET_CONTRACTS = exports.TESTNET_WTON = exports.MAINNET_WTON = void 0;
|
|
4
|
+
exports.findAddressByType = findAddressByType;
|
|
5
|
+
// WTON addresses
|
|
6
|
+
exports.MAINNET_WTON = "EQDIKEz2BYLnTRWo5W5a6moZ9PXNtyOVOFF7noi8Ufv3axz_";
|
|
7
|
+
exports.TESTNET_WTON = "EQBrWuWrQGw_xlm5XpImjWWSVsH56WFXfGm-j-VoP2njlC4s";
|
|
8
|
+
// Contract registry (address → info)
|
|
9
|
+
exports.MAINNET_CONTRACTS = {
|
|
10
|
+
[exports.MAINNET_WTON]: { name: "WTON", type: "wton" },
|
|
11
|
+
};
|
|
12
|
+
exports.TESTNET_CONTRACTS = {
|
|
13
|
+
[exports.TESTNET_WTON]: { name: "WTON", type: "wton" },
|
|
14
|
+
};
|
|
15
|
+
// Helper to find address by type
|
|
16
|
+
function findAddressByType(contracts, type) {
|
|
17
|
+
return Object.entries(contracts).find(([_, info]) => info.type === type)?.[0];
|
|
18
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Contract, OpenedContract, TonClient } from "@ton/ton";
|
|
2
|
+
import { Address } from "@ton/core";
|
|
3
|
+
import { AddressInput, AddressLike } from "./contracts/common/type";
|
|
4
|
+
import { ShareVault } from "./contracts/vault/share-vault";
|
|
5
|
+
import { StrategyVault } from "./contracts/vault/strategy-vault";
|
|
6
|
+
export type UnderlyingAssetType = {
|
|
7
|
+
type: "underlying-asset";
|
|
8
|
+
};
|
|
9
|
+
export type ShareVaultType = {
|
|
10
|
+
type: "share-vault";
|
|
11
|
+
data: Awaited<ReturnType<typeof ShareVault.parseVaultData>>;
|
|
12
|
+
};
|
|
13
|
+
export type StrategyVaultType = {
|
|
14
|
+
type: "strategy-vault";
|
|
15
|
+
data: Awaited<ReturnType<typeof StrategyVault.parseVaultData>>;
|
|
16
|
+
};
|
|
17
|
+
export type AssetType = UnderlyingAssetType | ShareVaultType | StrategyVaultType;
|
|
18
|
+
export type AffluentContextConfig = {
|
|
19
|
+
client: TonClient;
|
|
20
|
+
network: "testnet" | "mainnet" | "custom";
|
|
21
|
+
customWtonAddress?: string;
|
|
22
|
+
cacheTtl?: number;
|
|
23
|
+
};
|
|
24
|
+
export declare class AffluentContext {
|
|
25
|
+
private static instance;
|
|
26
|
+
readonly client: TonClient;
|
|
27
|
+
readonly network: "testnet" | "mainnet" | "custom";
|
|
28
|
+
readonly wtonAddress: Address;
|
|
29
|
+
private readonly cacheTtl;
|
|
30
|
+
private readonly openedContracts;
|
|
31
|
+
constructor(config: AffluentContextConfig);
|
|
32
|
+
static initialize(config: AffluentContextConfig): AffluentContext;
|
|
33
|
+
static getInstance(): AffluentContext;
|
|
34
|
+
static isInitialized(): boolean;
|
|
35
|
+
static reset(): void;
|
|
36
|
+
isWTON(address: AddressLike): boolean;
|
|
37
|
+
getByContract<T extends Contract>(contractType: {
|
|
38
|
+
createFromAddress(address: Address): T;
|
|
39
|
+
name?: string;
|
|
40
|
+
}, address: AddressInput): OpenedContract<T>;
|
|
41
|
+
private open;
|
|
42
|
+
getAssetType(assetAddress: AddressInput): Promise<AssetType>;
|
|
43
|
+
}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AffluentContext = void 0;
|
|
4
|
+
const contracts_1 = require("./constants/contracts");
|
|
5
|
+
const query_cache_1 = require("./lib/query-cache");
|
|
6
|
+
const core_1 = require("@ton/core");
|
|
7
|
+
const utils_1 = require("./contracts/common/utils");
|
|
8
|
+
const share_vault_1 = require("./contracts/vault/share-vault");
|
|
9
|
+
const strategy_vault_1 = require("./contracts/vault/strategy-vault");
|
|
10
|
+
class AffluentContext {
|
|
11
|
+
static instance = null;
|
|
12
|
+
client;
|
|
13
|
+
network;
|
|
14
|
+
wtonAddress;
|
|
15
|
+
cacheTtl;
|
|
16
|
+
openedContracts = new Map();
|
|
17
|
+
constructor(config) {
|
|
18
|
+
const { client, network, customWtonAddress, cacheTtl = 2500 } = config;
|
|
19
|
+
if (network === "custom" && !customWtonAddress) {
|
|
20
|
+
throw new Error("custom network requires customWtonAddress");
|
|
21
|
+
}
|
|
22
|
+
const wtonAddr = customWtonAddress ?? (network === "mainnet" ? contracts_1.MAINNET_WTON : contracts_1.TESTNET_WTON);
|
|
23
|
+
this.client = client;
|
|
24
|
+
this.network = network;
|
|
25
|
+
this.wtonAddress = core_1.Address.parse(wtonAddr);
|
|
26
|
+
this.cacheTtl = cacheTtl;
|
|
27
|
+
}
|
|
28
|
+
static initialize(config) {
|
|
29
|
+
if (AffluentContext.instance) {
|
|
30
|
+
throw new Error("AffluentContext already initialized. Call reset() first to reinitialize.");
|
|
31
|
+
}
|
|
32
|
+
AffluentContext.instance = new AffluentContext(config);
|
|
33
|
+
return AffluentContext.instance;
|
|
34
|
+
}
|
|
35
|
+
static getInstance() {
|
|
36
|
+
if (!AffluentContext.instance) {
|
|
37
|
+
throw new Error("AffluentContext not initialized. Call initialize() first.");
|
|
38
|
+
}
|
|
39
|
+
return AffluentContext.instance;
|
|
40
|
+
}
|
|
41
|
+
static isInitialized() {
|
|
42
|
+
return AffluentContext.instance !== null;
|
|
43
|
+
}
|
|
44
|
+
static reset() {
|
|
45
|
+
if (!AffluentContext.instance) {
|
|
46
|
+
throw new Error("AffluentContext not initialized. Call initialize() first.");
|
|
47
|
+
}
|
|
48
|
+
AffluentContext.instance = null;
|
|
49
|
+
}
|
|
50
|
+
isWTON(address) {
|
|
51
|
+
return (0, utils_1.toAddress)(address).equals(this.wtonAddress);
|
|
52
|
+
}
|
|
53
|
+
getByContract(contractType, address) {
|
|
54
|
+
const contract = contractType.createFromAddress((0, utils_1.toAddress)(address));
|
|
55
|
+
return this.open(contract);
|
|
56
|
+
}
|
|
57
|
+
open(contract) {
|
|
58
|
+
const key = `${contract.constructor.name}_${contract.address.toString()}`;
|
|
59
|
+
const cached = this.openedContracts.get(key);
|
|
60
|
+
if (cached) {
|
|
61
|
+
return cached;
|
|
62
|
+
}
|
|
63
|
+
const openedContract = (0, query_cache_1.withQueryCache)(this.client.open(contract), this.cacheTtl);
|
|
64
|
+
this.openedContracts.set(key, openedContract);
|
|
65
|
+
return openedContract;
|
|
66
|
+
}
|
|
67
|
+
async getAssetType(assetAddress) {
|
|
68
|
+
const address = (0, utils_1.toAddress)(assetAddress);
|
|
69
|
+
const state = await this.client.getContractState(address);
|
|
70
|
+
if (!state.data)
|
|
71
|
+
throw Error("no data");
|
|
72
|
+
const dataCell = core_1.Cell.fromBoc(state.data)[0];
|
|
73
|
+
try {
|
|
74
|
+
return {
|
|
75
|
+
type: "share-vault",
|
|
76
|
+
data: share_vault_1.ShareVault.parseVaultData(dataCell),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
catch (_) { }
|
|
80
|
+
try {
|
|
81
|
+
return {
|
|
82
|
+
type: "strategy-vault",
|
|
83
|
+
data: strategy_vault_1.StrategyVault.parseVaultData(dataCell),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (_) { }
|
|
87
|
+
return { type: "underlying-asset" };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.AffluentContext = AffluentContext;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Address, Cell } from "@ton/core";
|
|
2
|
+
export type Maybe<T> = T | null | undefined;
|
|
3
|
+
export type AddressLike = string | Address;
|
|
4
|
+
export interface Addressable {
|
|
5
|
+
address: Address;
|
|
6
|
+
}
|
|
7
|
+
export type AddressInput = Addressable | AddressLike;
|
|
8
|
+
/**
|
|
9
|
+
* Raw transaction message for sending via provider.send()
|
|
10
|
+
* Action layer returns this instead of sending directly
|
|
11
|
+
*/
|
|
12
|
+
export type TxMessage = {
|
|
13
|
+
to: Address;
|
|
14
|
+
value: bigint;
|
|
15
|
+
body: Cell;
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toAddress = toAddress;
|
|
4
|
+
const core_1 = require("@ton/core");
|
|
5
|
+
function toAddress(value) {
|
|
6
|
+
if (typeof value === "string") {
|
|
7
|
+
return core_1.Address.parse(value);
|
|
8
|
+
}
|
|
9
|
+
if (value instanceof core_1.Address) {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
if ("address" in value) {
|
|
13
|
+
return toAddress(value.address);
|
|
14
|
+
}
|
|
15
|
+
throw new Error("Invalid address");
|
|
16
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Address, Cell, Contract, ContractProvider, Sender, Slice } from "@ton/core";
|
|
2
|
+
import { AccountAssetState, AccountState } from "./type";
|
|
3
|
+
import { PoolState } from "../pool/type";
|
|
4
|
+
export type AccountConfig = {
|
|
5
|
+
pool: Address;
|
|
6
|
+
owner: Address;
|
|
7
|
+
};
|
|
8
|
+
export declare function accountConfigToCell(config: AccountConfig): Cell;
|
|
9
|
+
export declare class Account implements Contract {
|
|
10
|
+
readonly address: Address;
|
|
11
|
+
readonly init?: {
|
|
12
|
+
code: Cell;
|
|
13
|
+
data: Cell;
|
|
14
|
+
} | undefined;
|
|
15
|
+
constructor(address: Address, init?: {
|
|
16
|
+
code: Cell;
|
|
17
|
+
data: Cell;
|
|
18
|
+
} | undefined);
|
|
19
|
+
static createFromAddress(address: Address): Account;
|
|
20
|
+
static createFromConfig(config: AccountConfig, code: Cell, workchain?: number): Account;
|
|
21
|
+
getState(provider: ContractProvider): Promise<import("@ton/core").ContractState>;
|
|
22
|
+
sendDeploy(provider: ContractProvider, via: Sender, value: bigint): Promise<void>;
|
|
23
|
+
getAccountData(provider: ContractProvider): Promise<AccountState>;
|
|
24
|
+
static parseAccountData(data: Slice): {
|
|
25
|
+
pool: Address;
|
|
26
|
+
owner: Address;
|
|
27
|
+
status: Record<string, AccountAssetState>;
|
|
28
|
+
};
|
|
29
|
+
static haveBorrow(accountData: AccountState): boolean;
|
|
30
|
+
static haveAssets(accountData: AccountState): string[];
|
|
31
|
+
static convertShareToAmount(accountData: AccountState, poolData: PoolState): AccountState;
|
|
32
|
+
static applyDelta(accountData: AccountState, delta: Record<string, AccountAssetState>): {
|
|
33
|
+
status: Record<string, AccountAssetState>;
|
|
34
|
+
address: Address;
|
|
35
|
+
pool: Address;
|
|
36
|
+
owner: Address;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Account = void 0;
|
|
4
|
+
exports.accountConfigToCell = accountConfigToCell;
|
|
5
|
+
const core_1 = require("@ton/core");
|
|
6
|
+
function accountConfigToCell(config) {
|
|
7
|
+
return (0, core_1.beginCell)()
|
|
8
|
+
.storeAddress(config.pool)
|
|
9
|
+
.storeAddress(config.owner)
|
|
10
|
+
.storeDict(core_1.Dictionary.empty())
|
|
11
|
+
.storeDict(core_1.Dictionary.empty())
|
|
12
|
+
.endCell();
|
|
13
|
+
}
|
|
14
|
+
class Account {
|
|
15
|
+
address;
|
|
16
|
+
init;
|
|
17
|
+
constructor(address, init) {
|
|
18
|
+
this.address = address;
|
|
19
|
+
this.init = init;
|
|
20
|
+
}
|
|
21
|
+
static createFromAddress(address) {
|
|
22
|
+
return new Account(address);
|
|
23
|
+
}
|
|
24
|
+
static createFromConfig(config, code, workchain = 0) {
|
|
25
|
+
const data = accountConfigToCell(config);
|
|
26
|
+
const init = { code, data };
|
|
27
|
+
return new Account((0, core_1.contractAddress)(workchain, init), init);
|
|
28
|
+
}
|
|
29
|
+
async getState(provider) {
|
|
30
|
+
return await provider.getState();
|
|
31
|
+
}
|
|
32
|
+
async sendDeploy(provider, via, value) {
|
|
33
|
+
await provider.internal(via, {
|
|
34
|
+
value,
|
|
35
|
+
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY,
|
|
36
|
+
body: (0, core_1.beginCell)().endCell(),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async getAccountData(provider) {
|
|
40
|
+
const state = await provider.getState();
|
|
41
|
+
if (state.state.type !== "active")
|
|
42
|
+
throw "not active";
|
|
43
|
+
if (!state.state.data)
|
|
44
|
+
throw "not active";
|
|
45
|
+
const data = core_1.Cell.fromBoc(state.state.data)[0].beginParse();
|
|
46
|
+
return {
|
|
47
|
+
address: this.address,
|
|
48
|
+
...Account.parseAccountData(data),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
static parseAccountData(data) {
|
|
52
|
+
const pool = data.loadAddress();
|
|
53
|
+
const owner = data.loadAddress();
|
|
54
|
+
const statusDict = data.loadDict(core_1.Dictionary.Keys.Address(), DictioryValueAccountAsset);
|
|
55
|
+
const status = statusDict.keys().reduce((acc, cur) => {
|
|
56
|
+
acc[cur.toString()] = {
|
|
57
|
+
address: cur.toString(),
|
|
58
|
+
...statusDict.get(cur),
|
|
59
|
+
};
|
|
60
|
+
return acc;
|
|
61
|
+
}, {});
|
|
62
|
+
return {
|
|
63
|
+
pool,
|
|
64
|
+
owner,
|
|
65
|
+
status,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
static haveBorrow(accountData) {
|
|
69
|
+
const found = Object.values(accountData.status).find((item) => item.borrow > 0n);
|
|
70
|
+
return !!found;
|
|
71
|
+
}
|
|
72
|
+
static haveAssets(accountData) {
|
|
73
|
+
const assets = Object.entries(accountData.status)
|
|
74
|
+
.filter((item) => item[1].supply > 0n || item[1].borrow > 0n)
|
|
75
|
+
.map((item) => item[0]);
|
|
76
|
+
return assets;
|
|
77
|
+
}
|
|
78
|
+
static convertShareToAmount(accountData, poolData) {
|
|
79
|
+
const newStatus = {};
|
|
80
|
+
Object.entries(accountData.status).forEach(([assetAddress, statusInfo]) => {
|
|
81
|
+
const assetData = poolData.assets[assetAddress];
|
|
82
|
+
const supplyAmount = statusInfo.supply > 0n && assetData.totalSupplyShare > 0n
|
|
83
|
+
? (statusInfo.supply * assetData.totalSupplyAmount) / assetData.totalSupplyShare
|
|
84
|
+
: 0n;
|
|
85
|
+
const borrowAmount = statusInfo.borrow > 0n && assetData.totalBorrowShare > 0n
|
|
86
|
+
? (statusInfo.borrow * assetData.totalBorrowAmount) / assetData.totalBorrowShare
|
|
87
|
+
: 0n;
|
|
88
|
+
newStatus[assetAddress] = {
|
|
89
|
+
...statusInfo,
|
|
90
|
+
supply: supplyAmount,
|
|
91
|
+
borrow: borrowAmount,
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
return {
|
|
95
|
+
...accountData,
|
|
96
|
+
status: newStatus,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
static applyDelta(accountData, delta) {
|
|
100
|
+
const newStatus = {
|
|
101
|
+
...accountData.status,
|
|
102
|
+
};
|
|
103
|
+
Object.entries(delta).forEach(([assetAddress, deltaState]) => {
|
|
104
|
+
const statusInfo = accountData.status[assetAddress];
|
|
105
|
+
newStatus[assetAddress] = {
|
|
106
|
+
address: core_1.Address.parse(assetAddress),
|
|
107
|
+
supply: (statusInfo?.supply ?? 0n) + deltaState.supply,
|
|
108
|
+
borrow: (statusInfo?.borrow ?? 0n) + deltaState.borrow,
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
...accountData,
|
|
113
|
+
status: newStatus,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.Account = Account;
|
|
118
|
+
const DictioryValueAccountAsset = {
|
|
119
|
+
serialize: (src, builder) => { },
|
|
120
|
+
parse: (src) => {
|
|
121
|
+
const supply = src.loadCoins();
|
|
122
|
+
const borrow = src.loadCoins();
|
|
123
|
+
return {
|
|
124
|
+
supply,
|
|
125
|
+
borrow,
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Address } from "@ton/ton";
|
|
2
|
+
export type AccountState = {
|
|
3
|
+
address: Address;
|
|
4
|
+
pool: Address;
|
|
5
|
+
owner: Address;
|
|
6
|
+
status: Record<string, AccountAssetState>;
|
|
7
|
+
};
|
|
8
|
+
export type AccountAssetState = {
|
|
9
|
+
address: Address;
|
|
10
|
+
supply: bigint;
|
|
11
|
+
borrow: bigint;
|
|
12
|
+
};
|
|
13
|
+
export type AccountAssetStateWithDelta = {
|
|
14
|
+
address: Address;
|
|
15
|
+
supply: bigint;
|
|
16
|
+
borrow: bigint;
|
|
17
|
+
deltaCoefficient: bigint;
|
|
18
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { Address, Builder, Cell, Contract, ContractProvider, Sender, Slice } from "@ton/core";
|
|
2
|
+
import { LiquidateParams, TransferInParams, TransferOutMsgParams, PoolState, AssetState, PoolGasFee } from "./type";
|
|
3
|
+
/**
|
|
4
|
+
* Convert pool share to actual amount
|
|
5
|
+
*
|
|
6
|
+
* @param share - Share amount
|
|
7
|
+
* @param totalAmount - Total amount in pool
|
|
8
|
+
* @param totalShare - Total shares in pool
|
|
9
|
+
* @returns Actual amount
|
|
10
|
+
*/
|
|
11
|
+
export declare function shareToAmount(share: bigint, totalAmount: bigint, totalShare: bigint): bigint;
|
|
12
|
+
/**
|
|
13
|
+
* Convert pool share position to actual amounts
|
|
14
|
+
*
|
|
15
|
+
* @param position - Share-based position (supply/borrow shares)
|
|
16
|
+
* @param assetState - Pool asset state with total shares and amounts
|
|
17
|
+
* @returns Actual amounts (supply/borrow)
|
|
18
|
+
*/
|
|
19
|
+
export declare function positionShareToAmount(position: {
|
|
20
|
+
supply: bigint;
|
|
21
|
+
borrow: bigint;
|
|
22
|
+
}, assetState: {
|
|
23
|
+
totalSupplyAmount: bigint;
|
|
24
|
+
totalSupplyShare: bigint;
|
|
25
|
+
totalBorrowAmount: bigint;
|
|
26
|
+
totalBorrowShare: bigint;
|
|
27
|
+
}): {
|
|
28
|
+
supply: bigint;
|
|
29
|
+
borrow: bigint;
|
|
30
|
+
};
|
|
31
|
+
export declare class Pool implements Contract {
|
|
32
|
+
readonly address: Address;
|
|
33
|
+
readonly init?: {
|
|
34
|
+
code: Cell;
|
|
35
|
+
data: Cell;
|
|
36
|
+
} | undefined;
|
|
37
|
+
constructor(address: Address, init?: {
|
|
38
|
+
code: Cell;
|
|
39
|
+
data: Cell;
|
|
40
|
+
} | undefined);
|
|
41
|
+
static Op: {
|
|
42
|
+
supply: number;
|
|
43
|
+
withdraw: number;
|
|
44
|
+
borrow: number;
|
|
45
|
+
repay: number;
|
|
46
|
+
liquidate: number;
|
|
47
|
+
actionNotification: number;
|
|
48
|
+
Supply: number;
|
|
49
|
+
Withdraw: number;
|
|
50
|
+
Borrow: number;
|
|
51
|
+
Repay: number;
|
|
52
|
+
Liquidate: number;
|
|
53
|
+
ActionNotification: number;
|
|
54
|
+
ProvideAccountStatusAndLock: number;
|
|
55
|
+
TakeAsset: number;
|
|
56
|
+
UpdateAccountStatus: number;
|
|
57
|
+
ProcessBorrowActionResult: number;
|
|
58
|
+
ExecuteAction: number;
|
|
59
|
+
SetIrmConfig: number;
|
|
60
|
+
SetOwner: number;
|
|
61
|
+
SetFeeConfigurer: number;
|
|
62
|
+
};
|
|
63
|
+
static ErrorCodes: {
|
|
64
|
+
unauthorized: number;
|
|
65
|
+
invalidAsset: number;
|
|
66
|
+
invalidWallet: number;
|
|
67
|
+
invalidAddress: number;
|
|
68
|
+
alreadyInitialized: number;
|
|
69
|
+
notEnoughCash: number;
|
|
70
|
+
notEnoughShare: number;
|
|
71
|
+
notEnoughLiquidity: number;
|
|
72
|
+
notFoundPrice: number;
|
|
73
|
+
notFoundAccount: number;
|
|
74
|
+
enoughLiquidity: number;
|
|
75
|
+
notEnoughProtocolFee: number;
|
|
76
|
+
notBorrowableAsset: number;
|
|
77
|
+
alreadyExistAsset: number;
|
|
78
|
+
lockedAccount: number;
|
|
79
|
+
notEnoughGas: number;
|
|
80
|
+
actionTimeout: number;
|
|
81
|
+
seizeAssetIsRepayAsset: number;
|
|
82
|
+
unknownOp: number;
|
|
83
|
+
};
|
|
84
|
+
static Gas: {
|
|
85
|
+
baseFee: bigint;
|
|
86
|
+
forwardFee: bigint;
|
|
87
|
+
LiquidateionNotificationFee: bigint;
|
|
88
|
+
};
|
|
89
|
+
static createFromAddress(address: Address): Pool;
|
|
90
|
+
static createSupplyPayload(params: TransferInParams): Cell;
|
|
91
|
+
static createRepayPayload(params: TransferInParams): Cell;
|
|
92
|
+
static createLiquidatePayload(params: LiquidateParams): Cell;
|
|
93
|
+
static createWithdrawMsgBody(params: TransferOutMsgParams): Cell;
|
|
94
|
+
static createBorrowMsgBody(params: TransferOutMsgParams): Cell;
|
|
95
|
+
sendSetOwner(provider: ContractProvider, via: Sender, value: bigint, opts: {
|
|
96
|
+
newOwner: Address;
|
|
97
|
+
queryID?: number;
|
|
98
|
+
}): Promise<void>;
|
|
99
|
+
sendWithdraw(provider: ContractProvider, via: Sender, value: bigint, params: TransferOutMsgParams): Promise<Cell>;
|
|
100
|
+
sendBorrow(provider: ContractProvider, via: Sender, value: bigint, params: TransferOutMsgParams): Promise<Cell>;
|
|
101
|
+
static createSetIrmConfigMsgBody: (params: {
|
|
102
|
+
asset: Address;
|
|
103
|
+
irmConfig: Cell;
|
|
104
|
+
queryId?: number;
|
|
105
|
+
}) => Cell;
|
|
106
|
+
static createSetOwnerMsgBody(opts: {
|
|
107
|
+
newOwner: Address;
|
|
108
|
+
queryID?: number;
|
|
109
|
+
}): Cell;
|
|
110
|
+
static parseSetOwnerMsgBody(cell: Cell): {
|
|
111
|
+
op: number;
|
|
112
|
+
queryID: number;
|
|
113
|
+
newOwner: Address;
|
|
114
|
+
};
|
|
115
|
+
static createSetFeeConfigurerMsgBody: (params: {
|
|
116
|
+
feeConfigurer: Address;
|
|
117
|
+
queryId?: number;
|
|
118
|
+
}) => Cell;
|
|
119
|
+
static calculateGasFee(actionOp: number, baseFee: bigint, forwardFee: bigint, forwardTonAmount: bigint, useInternalOracle: boolean, useOracle: boolean, gas: PoolGasFee): bigint;
|
|
120
|
+
getState(provider: ContractProvider): Promise<import("@ton/core").ContractState>;
|
|
121
|
+
static simulateAccrueInterest(poolState: PoolState, time?: number): PoolState;
|
|
122
|
+
getPoolData(provider: ContractProvider): Promise<PoolState>;
|
|
123
|
+
static parsePoolData(data: Slice): {
|
|
124
|
+
id: bigint;
|
|
125
|
+
owner: Address | null;
|
|
126
|
+
feeConfigurer: Address | null;
|
|
127
|
+
protocolFeeRate: bigint;
|
|
128
|
+
oracle: Address | null;
|
|
129
|
+
oracleConfig: Cell | import("../../oracle/redstone-onchain-oracle/type").RedstoneOnchainOracleConfig | import("../../oracle/redstone-oracle/type").RedstonOracleConfig;
|
|
130
|
+
maxLoanLeverageRatio: bigint;
|
|
131
|
+
maxLoanVarRatio: bigint;
|
|
132
|
+
liquidateLeverageRatio: bigint;
|
|
133
|
+
liquidateVarRatio: bigint;
|
|
134
|
+
minLiquidateCloseRatio: bigint;
|
|
135
|
+
maxLiquidateCloseRatio: bigint;
|
|
136
|
+
assets: Record<string, AssetState>;
|
|
137
|
+
minimumGasFee: PoolGasFee;
|
|
138
|
+
oracleConfigRaw: Cell;
|
|
139
|
+
};
|
|
140
|
+
getAccountAddress(provider: ContractProvider, owner: Address): Promise<Address>;
|
|
141
|
+
static Dictionary: {
|
|
142
|
+
Values: {
|
|
143
|
+
Asset: () => {
|
|
144
|
+
serialize: (src: any, builder: Builder) => void;
|
|
145
|
+
parse: (src: Slice) => Omit<AssetState, "address">;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
}
|