@affluent-org/sdk 0.0.2 → 0.0.4
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/build/Account.compiled.json +1 -0
- package/dist/build/Receipt.compiled.json +1 -0
- package/dist/build/WTONWallet.compiled.json +1 -0
- package/dist/common/cache.d.ts +16 -0
- package/dist/common/cache.js +96 -0
- package/dist/common/service.d.ts +20 -0
- package/dist/common/service.js +69 -0
- package/dist/common/type.d.ts +14 -0
- package/dist/common/type.js +2 -0
- package/dist/common/unknown-contract.d.ts +14 -0
- package/dist/common/unknown-contract.js +18 -0
- package/dist/common/versions.d.ts +14 -0
- package/dist/common/versions.js +22 -0
- package/dist/constants/pool.d.ts +1 -0
- package/dist/constants/pool.js +2 -0
- package/dist/contracts/_mock/simple-oracle.d.ts +34 -0
- package/dist/contracts/_mock/simple-oracle.js +73 -0
- package/dist/contracts/vault/share-vault/type.d.ts +30 -0
- package/dist/contracts/vault/share-vault/type.js +2 -0
- package/dist/contracts/vault/strategy-vault/utils.d.ts +6 -0
- package/dist/contracts/vault/strategy-vault/utils.js +32 -0
- package/dist/factorial.d.ts +14 -0
- package/dist/factorial.js +20 -0
- package/dist/farm.d.ts +92 -0
- package/dist/farm.js +209 -0
- package/dist/monitor.d.ts +57 -0
- package/dist/monitor.js +527 -0
- package/dist/monitorCacheV1.d.ts +52 -0
- package/dist/monitorCacheV1.js +504 -0
- package/dist/oracle/oracle-v2.d.ts +39 -0
- package/dist/oracle/oracle-v2.js +151 -0
- package/dist/oracle/oracle.d.ts +107 -0
- package/dist/oracle/oracle.js +392 -0
- package/dist/periphery.d.ts +259 -0
- package/dist/periphery.js +1087 -0
- package/dist/pool.d.ts +216 -0
- package/dist/pool.js +2298 -0
- package/dist/poolCacheV1.d.ts +139 -0
- package/dist/poolCacheV1.js +1841 -0
- package/dist/rfq-auction.d.ts +75 -0
- package/dist/rfq-auction.js +220 -0
- package/dist/rfq-batch.d.ts +112 -0
- package/dist/rfq-batch.js +284 -0
- package/dist/services/share-vault/computation.d.ts +14 -17
- package/dist/services/share-vault/computation.js +39 -0
- package/dist/services/share-vault/index.d.ts +37 -0
- package/dist/services/share-vault/index.js +12 -3
- package/dist/services/share-vault/query.d.ts +38 -8
- package/dist/services/share-vault/query.js +20 -27
- package/dist/services/share-vault/type.d.ts +19 -0
- package/dist/services/share-vault/type.js +2 -0
- package/dist/services/share-vault/user/index.js +3 -1
- package/dist/services/strategy-vault/computation.d.ts +1 -0
- package/dist/services/strategy-vault/computation.js +15 -0
- package/dist/services/strategy-vault/index.d.ts +139 -0
- package/dist/services/strategy-vault/index.js +9 -0
- package/dist/services/strategy-vault/query.d.ts +147 -0
- package/dist/services/strategy-vault/query.js +72 -0
- package/dist/services/strategy-vault/type.d.ts +2 -0
- package/dist/services/strategy-vault/type.js +2 -0
- package/dist/share-vault.d.ts +91 -0
- package/dist/share-vault.js +747 -0
- package/dist/stonfi.d.ts +18 -0
- package/dist/stonfi.js +76 -0
- package/dist/strategy_vault/base.d.ts +399 -0
- package/dist/strategy_vault/base.js +1199 -0
- package/dist/strategy_vault/index.d.ts +3 -0
- package/dist/strategy_vault/index.js +7 -0
- package/dist/strategy_vault/steps.d.ts +49 -0
- package/dist/strategy_vault/steps.js +170 -0
- package/dist/types/action.d.ts +55 -0
- package/dist/types/action.js +2 -0
- package/dist/types/address.d.ts +7 -0
- package/dist/types/address.js +2 -0
- package/dist/types/messages.d.ts +7 -0
- package/dist/types/messages.js +2 -0
- package/dist/types/params.d.ts +19 -0
- package/dist/types/params.js +2 -0
- package/dist/types/pool.d.ts +83 -0
- package/dist/types/pool.js +2 -0
- package/dist/types/transaction.d.ts +40 -0
- package/dist/types/transaction.js +2 -0
- package/dist/utils/_parse_temp/JumpIRM.d.ts +37 -0
- package/dist/utils/_parse_temp/JumpIRM.js +71 -0
- package/dist/utils/_parse_temp/Pool.d.ts +559 -0
- package/dist/utils/_parse_temp/Pool.js +1023 -0
- package/dist/utils/_parse_temp/ShareVault.d.ts +264 -0
- package/dist/utils/_parse_temp/ShareVault.js +479 -0
- package/dist/utils/_parse_temp/StrategyVault.d.ts +729 -0
- package/dist/utils/_parse_temp/StrategyVault.js +1865 -0
- package/dist/utils/_parse_temp/parseMsgBody.d.ts +13 -0
- package/dist/utils/_parse_temp/parseMsgBody.js +313 -0
- package/dist/utils/assert.d.ts +1 -0
- package/dist/utils/assert.js +9 -0
- package/dist/utils/client-for-parameter.d.ts +12 -0
- package/dist/utils/client-for-parameter.js +97 -0
- package/dist/utils/oracle/index.d.ts +4 -0
- package/dist/utils/oracle/index.js +19 -0
- package/dist/utils/oracle/redstone/helper.d.ts +22 -0
- package/dist/utils/oracle/redstone/helper.js +186 -0
- package/dist/utils/tracer.d.ts +13 -0
- package/dist/utils/tracer.js +137 -0
- package/dist/utils/tracker/index.d.ts +5 -0
- package/dist/utils/tracker/index.js +118 -0
- package/dist/utils/tracker/query-id-generactor.d.ts +2 -0
- package/dist/utils/tracker/query-id-generactor.js +12 -0
- package/dist/utils/tracker/type.d.ts +34 -0
- package/dist/utils/tracker/type.js +2 -0
- package/package.json +1 -1
package/dist/farm.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FarmV1 = void 0;
|
|
7
|
+
const ton_1 = require("@ton/ton");
|
|
8
|
+
const contracts_1 = require("./constants/contracts");
|
|
9
|
+
const pool_1 = require("./contracts/core/pool");
|
|
10
|
+
const tracker_1 = require("./utils/tracker");
|
|
11
|
+
const parser_1 = require("./utils/parser");
|
|
12
|
+
const query_id_generactor_1 = require("./utils/tracker/query-id-generactor");
|
|
13
|
+
const Receipt_compiled_json_1 = __importDefault(require("./build/Receipt.compiled.json"));
|
|
14
|
+
const receipt_1 = require("./contracts/farm/receipt");
|
|
15
|
+
const distributor_1 = require("./contracts/farm/distributor");
|
|
16
|
+
const generateRandomQueryId = (senderAddress) => {
|
|
17
|
+
const randomCell = (0, ton_1.beginCell)().storeCoins(Date.now()).storeCoins(Math.floor(Math.random() * 1000000000000)).endCell();
|
|
18
|
+
const queryId = (0, query_id_generactor_1.generateQueryId)(toAddress(senderAddress), randomCell);
|
|
19
|
+
return queryId;
|
|
20
|
+
};
|
|
21
|
+
const toAddress = (value) => {
|
|
22
|
+
if (value instanceof ton_1.Address) {
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
return ton_1.Address.parse(value);
|
|
26
|
+
};
|
|
27
|
+
const toString = (value) => {
|
|
28
|
+
if (value instanceof ton_1.Address) {
|
|
29
|
+
return value.toString();
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
};
|
|
33
|
+
class FarmV1 {
|
|
34
|
+
network;
|
|
35
|
+
client;
|
|
36
|
+
contracts;
|
|
37
|
+
// user -> asset -> wallet
|
|
38
|
+
walletAddresses = {};
|
|
39
|
+
// user -> pool -> account
|
|
40
|
+
accountAddresses = {};
|
|
41
|
+
constructor(client, network, custom_contracts) {
|
|
42
|
+
this.client = client;
|
|
43
|
+
this.network = network;
|
|
44
|
+
if (network === "custom" && !custom_contracts)
|
|
45
|
+
throw "should provide custom contracts";
|
|
46
|
+
this.contracts =
|
|
47
|
+
network === "mainnet"
|
|
48
|
+
? contracts_1.MAINNET_CONTRACTS
|
|
49
|
+
: network === "testnet"
|
|
50
|
+
? contracts_1.TESTNET_CONTRACTS
|
|
51
|
+
: custom_contracts;
|
|
52
|
+
}
|
|
53
|
+
async getAccountAddress(owner, pool) {
|
|
54
|
+
this.accountAddresses[owner] ||= {};
|
|
55
|
+
if (!this.accountAddresses[owner][pool]) {
|
|
56
|
+
const poolContract = this.client.open(pool_1.Pool.createFromAddress(toAddress(pool)));
|
|
57
|
+
this.accountAddresses[owner][pool] = await poolContract.getAccountAddress(toAddress(owner));
|
|
58
|
+
}
|
|
59
|
+
return this.accountAddresses[owner][pool];
|
|
60
|
+
}
|
|
61
|
+
async findAndCallback(target, step, createdLt, callbackFn) {
|
|
62
|
+
const matchedTx = await (0, tracker_1.findTx)(this.client, toAddress(target), createdLt.toString(), step);
|
|
63
|
+
step.matchedTx = matchedTx;
|
|
64
|
+
if (matchedTx.inMessage?.body) {
|
|
65
|
+
const parsed = (0, parser_1.parseActionNotification)(matchedTx.inMessage.body);
|
|
66
|
+
if (parsed) {
|
|
67
|
+
step.actionNotificationResult = parsed;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (callbackFn)
|
|
71
|
+
callbackFn(step);
|
|
72
|
+
return matchedTx;
|
|
73
|
+
}
|
|
74
|
+
async claimFactorialRewardAndWaitTx(sender, params, callbackFn) {
|
|
75
|
+
let receipt = this.client.open(receipt_1.Receipt.createFromConfig({
|
|
76
|
+
distributor: toAddress(params.distributorAddress),
|
|
77
|
+
owner: toAddress(params.senderAddress),
|
|
78
|
+
}, ton_1.Cell.fromHex(Receipt_compiled_json_1.default.hex)));
|
|
79
|
+
let gas = (0, ton_1.toNano)(0.25);
|
|
80
|
+
if (await this.client.isContractDeployed(receipt.address)) {
|
|
81
|
+
receipt = this.client.open(receipt_1.Receipt.createFromAddress(receipt.address));
|
|
82
|
+
gas += (0, ton_1.toNano)(0.05);
|
|
83
|
+
}
|
|
84
|
+
const queryId = generateRandomQueryId(params.senderAddress);
|
|
85
|
+
await receipt.sendClaim(sender, params.gas || gas, {
|
|
86
|
+
queryId,
|
|
87
|
+
rewardProofCell: params.proofCell,
|
|
88
|
+
response: toAddress(params.responseAddress),
|
|
89
|
+
receipient: toAddress(params.receipientAddress),
|
|
90
|
+
});
|
|
91
|
+
const steps = [];
|
|
92
|
+
steps.push({
|
|
93
|
+
queryId,
|
|
94
|
+
description: "Sending the tx",
|
|
95
|
+
from: toAddress(params.senderAddress),
|
|
96
|
+
to: receipt.address,
|
|
97
|
+
opcode: receipt_1.Receipt.Op.Claim,
|
|
98
|
+
});
|
|
99
|
+
steps.push({
|
|
100
|
+
queryId,
|
|
101
|
+
description: "Check claimed amount",
|
|
102
|
+
from: receipt.address,
|
|
103
|
+
to: toAddress(params.distributorAddress),
|
|
104
|
+
opcode: receipt_1.Receipt.Op.Claim,
|
|
105
|
+
});
|
|
106
|
+
steps.push({
|
|
107
|
+
queryId,
|
|
108
|
+
description: "Transfer claim reward",
|
|
109
|
+
from: toAddress(params.distributorAddress),
|
|
110
|
+
to: toAddress(params.senderAddress),
|
|
111
|
+
opcode: distributor_1.Distributor.Op.TransferReward,
|
|
112
|
+
});
|
|
113
|
+
(async () => {
|
|
114
|
+
const matchedTx0 = await this.findAndCallback(toAddress(params.senderAddress), steps[0], "0", callbackFn);
|
|
115
|
+
const matchedTx1 = await this.findAndCallback(toAddress(params.distributorAddress), steps[1], matchedTx0.lt.toString(), callbackFn);
|
|
116
|
+
const matchedTx2 = await this.findAndCallback(toAddress(params.senderAddress), steps[2], matchedTx1.lt.toString(), callbackFn);
|
|
117
|
+
})();
|
|
118
|
+
return {
|
|
119
|
+
action: {
|
|
120
|
+
type: "distributor-claim",
|
|
121
|
+
params,
|
|
122
|
+
queryId,
|
|
123
|
+
},
|
|
124
|
+
steps,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
async findTx(action, callbackFn) {
|
|
128
|
+
if (action.type == "distributor-claim") {
|
|
129
|
+
return this.findFactorialClaimTx(BigInt(action.queryId), action.params, callbackFn);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async findFactorialClaimTx(queryId, params, callbackFn) {
|
|
133
|
+
let receipt = this.client.open(receipt_1.Receipt.createFromConfig({
|
|
134
|
+
distributor: toAddress(params.distributorAddress),
|
|
135
|
+
owner: toAddress(params.senderAddress),
|
|
136
|
+
}, ton_1.Cell.fromHex(Receipt_compiled_json_1.default.hex)));
|
|
137
|
+
if (await this.client.isContractDeployed(receipt.address)) {
|
|
138
|
+
receipt = this.client.open(receipt_1.Receipt.createFromAddress(receipt.address));
|
|
139
|
+
}
|
|
140
|
+
const steps = [];
|
|
141
|
+
steps.push({
|
|
142
|
+
queryId,
|
|
143
|
+
description: "Sending the tx",
|
|
144
|
+
from: toAddress(params.senderAddress),
|
|
145
|
+
to: receipt.address,
|
|
146
|
+
opcode: receipt_1.Receipt.Op.Claim,
|
|
147
|
+
});
|
|
148
|
+
steps.push({
|
|
149
|
+
queryId,
|
|
150
|
+
description: "Check claimed amount",
|
|
151
|
+
from: receipt.address,
|
|
152
|
+
to: toAddress(params.distributorAddress),
|
|
153
|
+
opcode: receipt_1.Receipt.Op.Claim,
|
|
154
|
+
});
|
|
155
|
+
steps.push({
|
|
156
|
+
queryId,
|
|
157
|
+
description: "Transfer claim reward",
|
|
158
|
+
from: toAddress(params.distributorAddress),
|
|
159
|
+
to: toAddress(params.senderAddress),
|
|
160
|
+
opcode: distributor_1.Distributor.Op.TransferReward,
|
|
161
|
+
});
|
|
162
|
+
(async () => {
|
|
163
|
+
const matchedTx0 = await this.findAndCallback(toAddress(params.senderAddress), steps[0], "0", callbackFn);
|
|
164
|
+
const matchedTx1 = await this.findAndCallback(toAddress(params.distributorAddress), steps[1], matchedTx0.lt.toString(), callbackFn);
|
|
165
|
+
const matchedTx2 = await this.findAndCallback(toAddress(params.senderAddress), steps[2], matchedTx1.lt.toString(), callbackFn);
|
|
166
|
+
})();
|
|
167
|
+
return {
|
|
168
|
+
action: {
|
|
169
|
+
type: "distributor-claim",
|
|
170
|
+
params,
|
|
171
|
+
queryId,
|
|
172
|
+
},
|
|
173
|
+
steps,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
async getDistributorData(distributorAddress) {
|
|
177
|
+
const distributor = this.client.open(distributor_1.Distributor.createFromAddress(toAddress(distributorAddress)));
|
|
178
|
+
return await distributor.getDistributorData();
|
|
179
|
+
}
|
|
180
|
+
async getReceiptData(distributorAddress, userAddress) {
|
|
181
|
+
let receipt = this.client.open(receipt_1.Receipt.createFromConfig({
|
|
182
|
+
distributor: toAddress(distributorAddress),
|
|
183
|
+
owner: toAddress(userAddress),
|
|
184
|
+
}, ton_1.Cell.fromHex(Receipt_compiled_json_1.default.hex)));
|
|
185
|
+
if (await this.client.isContractDeployed(receipt.address)) {
|
|
186
|
+
return {
|
|
187
|
+
deployed: true,
|
|
188
|
+
...(await receipt.getReceiptData())
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
return {
|
|
193
|
+
deployed: false,
|
|
194
|
+
owner: userAddress,
|
|
195
|
+
distributor: distributorAddress,
|
|
196
|
+
claimed: 0n,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
async setDistributorRootHash(sender, params) {
|
|
201
|
+
const distributor = this.client.open(distributor_1.Distributor.createFromAddress(toAddress(params.distributorAddress)));
|
|
202
|
+
const queryId = generateRandomQueryId(params.senderAddress);
|
|
203
|
+
await distributor.sendSetRewardRootHash(sender, params.gas || (0, ton_1.toNano)(0.02), {
|
|
204
|
+
queryId,
|
|
205
|
+
newHash: params.newRootHash,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
exports.FarmV1 = FarmV1;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Address, TonClient } from "@ton/ton";
|
|
2
|
+
import { RiskResult } from "./types/pool";
|
|
3
|
+
import { PoolState } from "./contracts/core/pool/type";
|
|
4
|
+
import { OnchainDataInfo } from "./contracts/oracle/redstone-onchain-oracle/type";
|
|
5
|
+
import { TxCallBackFn, TxStep } from "./utils/tracker/type";
|
|
6
|
+
import { AssetPriceInfo } from "./contracts/oracle/redstone-onchain-oracle/type";
|
|
7
|
+
import { AccountAssetState, AccountState } from "./contracts/core/account/type";
|
|
8
|
+
export declare class MonitorV1 {
|
|
9
|
+
network: "testnet" | "mainnet" | "custom";
|
|
10
|
+
client: TonClient;
|
|
11
|
+
contracts: Record<string, string>;
|
|
12
|
+
private walletAddresses;
|
|
13
|
+
private accountAddresses;
|
|
14
|
+
constructor(client: TonClient, network: "testnet" | "mainnet" | "custom", custom_contracts?: Record<string, string>);
|
|
15
|
+
private getJettonWalletAddress;
|
|
16
|
+
getAccountAddress(owner: string, pool: string): Promise<Address>;
|
|
17
|
+
findAndCallback(target: Address, step: TxStep, createdLt: string | bigint, callbackFn?: TxCallBackFn): Promise<import("./utils/tracker/type").MatchedTxResult>;
|
|
18
|
+
updateOnchainData(onchainDataInfo: OnchainDataInfo): Promise<OnchainDataInfo>;
|
|
19
|
+
getRedstonePrices(assets: string[], poolData: any): Promise<{
|
|
20
|
+
redstonePrices: AssetPriceInfo;
|
|
21
|
+
onchainData: any;
|
|
22
|
+
}>;
|
|
23
|
+
getRedstonePricesNew(assets: string[], oracleConfig: any): Promise<{
|
|
24
|
+
redstonePrices: AssetPriceInfo;
|
|
25
|
+
onchainData: any;
|
|
26
|
+
}>;
|
|
27
|
+
calculatePrices(_prices: AssetPriceInfo, oracleData: any): AssetPriceInfo;
|
|
28
|
+
decomposeAccountStatus(accountStatus: Record<string, AccountAssetState>, prices: AssetPriceInfo, onchainData: OnchainDataInfo): Record<string, Omit<AccountAssetState, "address">>;
|
|
29
|
+
calculateRisk(decomposedAccountStatus: Record<string, Omit<AccountAssetState, "address">>, prices: AssetPriceInfo, poolData: PoolState): {
|
|
30
|
+
result: boolean;
|
|
31
|
+
healthy: boolean;
|
|
32
|
+
unhealthy: boolean;
|
|
33
|
+
collateral: bigint;
|
|
34
|
+
debt: bigint;
|
|
35
|
+
risk: bigint;
|
|
36
|
+
riskRatio: bigint;
|
|
37
|
+
leverageRatio: bigint;
|
|
38
|
+
};
|
|
39
|
+
getOracleRequestParams(assets: string[], oracleConfig: any): Promise<{
|
|
40
|
+
feedIds: bigint[];
|
|
41
|
+
redstoneAssetNames: any[];
|
|
42
|
+
requestAssets: Address[];
|
|
43
|
+
redstoneAssets: Address[];
|
|
44
|
+
}>;
|
|
45
|
+
isHealthy(poolAddress: Address | string, ownerAddress: Address | string): Promise<RiskResult>;
|
|
46
|
+
getPricesNew(assets: string[], oracleConfig: any): Promise<AssetPriceInfo>;
|
|
47
|
+
getAssetPricesInPool(poolAddress: Address | string): Promise<AssetPriceInfo>;
|
|
48
|
+
getAssetPricesInVault(vaultAddress: Address | string): Promise<AssetPriceInfo>;
|
|
49
|
+
getPrices(poolAddress: Address | string): Promise<AssetPriceInfo>;
|
|
50
|
+
getPricesAndOnchainData(poolData: any): Promise<{
|
|
51
|
+
prices: AssetPriceInfo;
|
|
52
|
+
onchainData: any;
|
|
53
|
+
}>;
|
|
54
|
+
getPoolData(poolAddress: Address | string): Promise<PoolState>;
|
|
55
|
+
getAccountData(address: Address | string): Promise<AccountState>;
|
|
56
|
+
calculateHealth(_poolData: PoolState, _accountData: AccountState, prices: any, onchainData: any): RiskResult;
|
|
57
|
+
}
|