@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
|
@@ -0,0 +1,1087 @@
|
|
|
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.PeripheryV1 = 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 jetton_minter_1 = require("./contracts/jetton/jetton-minter");
|
|
11
|
+
const jetton_wallet_1 = require("./contracts/jetton/jetton-wallet");
|
|
12
|
+
const tracker_1 = require("./utils/tracker");
|
|
13
|
+
const query_id_generactor_1 = require("./utils/tracker/query-id-generactor");
|
|
14
|
+
const parser_1 = require("./utils/parser");
|
|
15
|
+
const minter_1 = require("./contracts/liquid_token/dedust/minter");
|
|
16
|
+
const LFStonfiJettonWallet_1 = require("./contracts/liquid_token/stonfi/LFStonfiJettonWallet");
|
|
17
|
+
const wallet_1 = require("./contracts/liquid_token/dedust/wallet");
|
|
18
|
+
const LFStonfiJettonMinter_1 = require("./contracts/liquid_token/stonfi/LFStonfiJettonMinter");
|
|
19
|
+
const account_1 = require("./contracts/core/account");
|
|
20
|
+
const client_for_parameter_1 = require("./utils/client-for-parameter");
|
|
21
|
+
const Account_compiled_json_1 = __importDefault(require("./build/Account.compiled.json"));
|
|
22
|
+
const TIMEOUT_SEC = 2 * 60 * 1000;
|
|
23
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
24
|
+
const toAddress = (value) => {
|
|
25
|
+
if (value instanceof ton_1.Address) {
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
return ton_1.Address.parse(value);
|
|
29
|
+
};
|
|
30
|
+
const toString = (value) => {
|
|
31
|
+
if (value instanceof ton_1.Address) {
|
|
32
|
+
return value.toString();
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
};
|
|
36
|
+
const generateRandomQueryId = (senderAddress) => {
|
|
37
|
+
const randomCell = (0, ton_1.beginCell)()
|
|
38
|
+
.storeCoins(Date.now())
|
|
39
|
+
.storeCoins(Math.floor(Math.random() * 1000000000000))
|
|
40
|
+
.endCell();
|
|
41
|
+
const queryId = (0, query_id_generactor_1.generateQueryId)(toAddress(senderAddress), randomCell);
|
|
42
|
+
return queryId;
|
|
43
|
+
};
|
|
44
|
+
class PeripheryV1 {
|
|
45
|
+
client;
|
|
46
|
+
contracts;
|
|
47
|
+
// user -> asset -> wallet
|
|
48
|
+
walletAddresses = {};
|
|
49
|
+
constructor(client, network, custom_contracts) {
|
|
50
|
+
this.client = client;
|
|
51
|
+
if (network === "custom" && !custom_contracts)
|
|
52
|
+
throw "should provide custom contracts";
|
|
53
|
+
this.contracts =
|
|
54
|
+
network === "mainnet"
|
|
55
|
+
? contracts_1.MAINNET_CONTRACTS
|
|
56
|
+
: network === "testnet"
|
|
57
|
+
? contracts_1.TESTNET_CONTRACTS
|
|
58
|
+
: custom_contracts;
|
|
59
|
+
}
|
|
60
|
+
async getJettonWalletAddress(owner, jetton) {
|
|
61
|
+
if (!this.walletAddresses[owner]) {
|
|
62
|
+
this.walletAddresses[owner] = {};
|
|
63
|
+
}
|
|
64
|
+
if (!this.walletAddresses[owner][jetton]) {
|
|
65
|
+
const jettonMinter = this.client.open(jetton_minter_1.JettonMinter.createFromAddress(toAddress(jetton)));
|
|
66
|
+
this.walletAddresses[owner][jetton] = await jettonMinter.getWalletAddress(toAddress(owner));
|
|
67
|
+
}
|
|
68
|
+
return this.walletAddresses[owner][jetton];
|
|
69
|
+
}
|
|
70
|
+
async deployWallet(sender, tokenAddress, targetAddress, gas) {
|
|
71
|
+
const jettonMinter = this.client.open(minter_1.LFDedustJettonMinter.createFromAddress(toAddress(tokenAddress)));
|
|
72
|
+
await jettonMinter.sendDeployWallet(sender, {
|
|
73
|
+
recipient: toAddress(targetAddress),
|
|
74
|
+
value: gas || (0, ton_1.toNano)(0.1),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async deployWLPWalletAndWaitTx(sender, params, callbackFn) {
|
|
78
|
+
const jettonMinter = this.client.open(minter_1.LFDedustJettonMinter.createFromAddress(toAddress(params.tokenAddress)));
|
|
79
|
+
const queryId = generateRandomQueryId(params.senderAddress);
|
|
80
|
+
await jettonMinter.sendDeployWallet(sender, {
|
|
81
|
+
queryId,
|
|
82
|
+
recipient: toAddress(params.targetAddress),
|
|
83
|
+
value: params.gas || (0, ton_1.toNano)(0.1),
|
|
84
|
+
});
|
|
85
|
+
const wlpWalletAddress = await jettonMinter.getWalletAddress(toAddress(params.targetAddress));
|
|
86
|
+
const steps = [];
|
|
87
|
+
steps.push(...[
|
|
88
|
+
{
|
|
89
|
+
queryId,
|
|
90
|
+
description: "tx send",
|
|
91
|
+
from: toAddress(params.senderAddress),
|
|
92
|
+
to: toAddress(params.tokenAddress),
|
|
93
|
+
opcode: minter_1.LFDedustJettonMinter.Op.DeployWallet,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
queryId,
|
|
97
|
+
description: "deploy",
|
|
98
|
+
from: toAddress(params.tokenAddress),
|
|
99
|
+
to: toAddress(wlpWalletAddress),
|
|
100
|
+
},
|
|
101
|
+
]);
|
|
102
|
+
(async () => {
|
|
103
|
+
const matchedTx0 = await this.findAndCallback(toAddress(params.senderAddress), steps[0], "0", callbackFn);
|
|
104
|
+
const matchedTx1 = await this.findAndCallback(wlpWalletAddress, steps[1], matchedTx0.lt.toString(), callbackFn);
|
|
105
|
+
})();
|
|
106
|
+
return steps;
|
|
107
|
+
}
|
|
108
|
+
async initializeLFWallet(sender, lfTokenAddress, targetAddress) {
|
|
109
|
+
const targetJettonWalletAddress = await this.getJettonWalletAddress(toString(targetAddress), toString(lfTokenAddress));
|
|
110
|
+
const targetLFJettonWallet = this.client.open(wallet_1.LFDedustJettonWallet.createFromAddress(targetJettonWalletAddress));
|
|
111
|
+
const a = await targetLFJettonWallet.sendInitialize(sender, (0, ton_1.toNano)(0.06));
|
|
112
|
+
}
|
|
113
|
+
async deployWLPWalletAndWaitTx2(sender, params, callbackFn) {
|
|
114
|
+
const jettonMinter = this.client.open(minter_1.LFDedustJettonMinter.createFromAddress(toAddress(params.tokenAddress)));
|
|
115
|
+
let poolAddress;
|
|
116
|
+
try {
|
|
117
|
+
const jettonMinter = this.client.open(minter_1.LFDedustJettonMinter.createFromAddress(toAddress(params.tokenAddress)));
|
|
118
|
+
poolAddress = (await jettonMinter.getWLPJettonData()).poolAddress;
|
|
119
|
+
}
|
|
120
|
+
catch (e) {
|
|
121
|
+
const jettonMinter = this.client.open(LFStonfiJettonMinter_1.LFStonfiJettonMinter.createFromAddress(toAddress(params.tokenAddress)));
|
|
122
|
+
poolAddress = (await jettonMinter.getWLPJettonData()).poolAddress;
|
|
123
|
+
}
|
|
124
|
+
// console.log("poolAddress", poolAddress);
|
|
125
|
+
const pool = this.client.open(pool_1.Pool.createFromAddress(poolAddress));
|
|
126
|
+
const accountAddress = await pool.getAccountAddress(toAddress(params.targetAddress));
|
|
127
|
+
const queryId = generateRandomQueryId(params.senderAddress);
|
|
128
|
+
// console.log("deployed?", await this.client.isContractDeployed(accountAddress) ? "true" : "false");
|
|
129
|
+
if (!(await this.client.isContractDeployed(accountAddress))) {
|
|
130
|
+
const clientForParameter = new client_for_parameter_1.TonClientForParameter(this.client.parameters);
|
|
131
|
+
const jettonMinter = clientForParameter.open(minter_1.LFDedustJettonMinter.createFromAddress(toAddress(params.tokenAddress)));
|
|
132
|
+
const deployWalletParams = await jettonMinter.sendDeployWallet(sender, {
|
|
133
|
+
queryId,
|
|
134
|
+
recipient: toAddress(params.targetAddress),
|
|
135
|
+
value: params.gas || (0, ton_1.toNano)(0.1),
|
|
136
|
+
});
|
|
137
|
+
const account = clientForParameter.open(account_1.Account.createFromConfig({
|
|
138
|
+
pool: poolAddress,
|
|
139
|
+
owner: toAddress(params.targetAddress),
|
|
140
|
+
}, ton_1.Cell.fromHex(Account_compiled_json_1.default.hex)));
|
|
141
|
+
const deployAccountParams = await account.sendDeploy(sender, (0, ton_1.toNano)(0.02));
|
|
142
|
+
// console.log("deployWalletParams ", deployWalletParams)
|
|
143
|
+
// console.log("deployAccountParams ", deployAccountParams)
|
|
144
|
+
if (sender.multiSend) {
|
|
145
|
+
await sender.multiSend([deployWalletParams, deployAccountParams]);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
await jettonMinter.sendDeployWallet(sender, {
|
|
150
|
+
queryId,
|
|
151
|
+
recipient: toAddress(params.targetAddress),
|
|
152
|
+
value: params.gas || (0, ton_1.toNano)(0.1),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
const wlpWalletAddress = await jettonMinter.getWalletAddress(toAddress(params.targetAddress));
|
|
156
|
+
const steps = [];
|
|
157
|
+
steps.push(...[
|
|
158
|
+
{
|
|
159
|
+
queryId,
|
|
160
|
+
description: "tx send",
|
|
161
|
+
from: toAddress(params.senderAddress),
|
|
162
|
+
to: toAddress(params.tokenAddress),
|
|
163
|
+
opcode: minter_1.LFDedustJettonMinter.Op.DeployWallet,
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
queryId,
|
|
167
|
+
description: "deploy",
|
|
168
|
+
from: toAddress(params.tokenAddress),
|
|
169
|
+
to: toAddress(wlpWalletAddress),
|
|
170
|
+
},
|
|
171
|
+
]);
|
|
172
|
+
(async () => {
|
|
173
|
+
const matchedTx0 = await this.findAndCallback(toAddress(params.senderAddress), steps[0], "0", callbackFn);
|
|
174
|
+
const matchedTx1 = await this.findAndCallback(wlpWalletAddress, steps[1], matchedTx0.lt.toString(), callbackFn);
|
|
175
|
+
})();
|
|
176
|
+
return steps;
|
|
177
|
+
}
|
|
178
|
+
async seize(sender, senderAddress, lfTokenAddress, targetAddress, responseAddress, amount, gas) {
|
|
179
|
+
const senderJettonWalletAddress = await this.getJettonWalletAddress(toString(senderAddress), toString(lfTokenAddress));
|
|
180
|
+
const senderLFJettonWallet = this.client.open(wallet_1.LFDedustJettonWallet.createFromAddress(senderJettonWalletAddress));
|
|
181
|
+
const result = await senderLFJettonWallet.sendSeize(sender, {
|
|
182
|
+
amount,
|
|
183
|
+
value: (0, ton_1.toNano)(0.11),
|
|
184
|
+
targetAddress: toAddress(targetAddress),
|
|
185
|
+
responseAddress: toAddress(responseAddress),
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
async wrapDedustLPAndWaitTx(sender, params, callbackFn) {
|
|
189
|
+
const dedustWLPMinter = this.client.open(minter_1.LFDedustJettonMinter.createFromAddress(toAddress(params.wlpTokenAddress)));
|
|
190
|
+
const wlpData = await dedustWLPMinter.getWLPJettonData();
|
|
191
|
+
const underlyingAssetAddress = wlpData.assetAddress;
|
|
192
|
+
const underlyingAsset = this.client.open(jetton_minter_1.JettonMinter.createFromAddress(toAddress(underlyingAssetAddress)));
|
|
193
|
+
const senderWLPWalletAddress = await dedustWLPMinter.getWalletAddress(toAddress(params.senderAddress));
|
|
194
|
+
const senderLPWalletAddress = await underlyingAsset.getWalletAddress(toAddress(params.senderAddress));
|
|
195
|
+
const wlpLPWalletAddress = await underlyingAsset.getWalletAddress(toAddress(senderWLPWalletAddress));
|
|
196
|
+
const senderLPWallet = this.client.open(jetton_wallet_1.JettonWallet.createFromAddress(senderLPWalletAddress));
|
|
197
|
+
if (!(await this.client.isContractDeployed(senderWLPWalletAddress))) {
|
|
198
|
+
throw "not deployed lf wallet";
|
|
199
|
+
}
|
|
200
|
+
const queryId = generateRandomQueryId(params.senderAddress);
|
|
201
|
+
await senderLPWallet.sendTransfer(sender, params.gas || (0, ton_1.toNano)(0.1), {
|
|
202
|
+
queryId,
|
|
203
|
+
recipient: toAddress(senderWLPWalletAddress),
|
|
204
|
+
response: toAddress(params.senderAddress),
|
|
205
|
+
amount: params.amount,
|
|
206
|
+
forwardTonAmount: (0, ton_1.toNano)(0.02),
|
|
207
|
+
});
|
|
208
|
+
const steps = [];
|
|
209
|
+
steps.push(...[
|
|
210
|
+
{
|
|
211
|
+
queryId,
|
|
212
|
+
description: "tx send",
|
|
213
|
+
from: toAddress(params.senderAddress),
|
|
214
|
+
to: senderLPWallet.address,
|
|
215
|
+
opcode: jetton_wallet_1.JettonWallet.Op.Transfer,
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
queryId,
|
|
219
|
+
description: "mint",
|
|
220
|
+
from: toAddress(wlpLPWalletAddress),
|
|
221
|
+
to: senderWLPWalletAddress,
|
|
222
|
+
opcode: jetton_wallet_1.JettonWallet.Op.TransferNotification,
|
|
223
|
+
},
|
|
224
|
+
]);
|
|
225
|
+
(async () => {
|
|
226
|
+
const matchedTx0 = await this.findAndCallback(toAddress(params.senderAddress), steps[0], "0", callbackFn);
|
|
227
|
+
const matchedTx1 = await this.findAndCallback(senderWLPWalletAddress, steps[1], matchedTx0.lt.toString(), callbackFn);
|
|
228
|
+
})();
|
|
229
|
+
return steps;
|
|
230
|
+
}
|
|
231
|
+
async wrapStonfiLPAndWaitTx(sender, params, callbackFn) {
|
|
232
|
+
const stonfiWLPMinter = this.client.open(LFStonfiJettonMinter_1.LFStonfiJettonMinter.createFromAddress(toAddress(params.wlpTokenAddress)));
|
|
233
|
+
const wlpData = await stonfiWLPMinter.getWLPJettonData();
|
|
234
|
+
// console.log("wlpData", wlpData);
|
|
235
|
+
const underlyingAssetAddress = wlpData.assetAddress;
|
|
236
|
+
const underlyingAsset = this.client.open(jetton_minter_1.JettonMinter.createFromAddress(toAddress(underlyingAssetAddress)));
|
|
237
|
+
const senderWLPWalletAddress = await stonfiWLPMinter.getWalletAddress(toAddress(params.senderAddress));
|
|
238
|
+
const senderLPWalletAddress = await underlyingAsset.getWalletAddress(toAddress(params.senderAddress));
|
|
239
|
+
const wlpLPWalletAddress = await underlyingAsset.getWalletAddress(toAddress(senderWLPWalletAddress));
|
|
240
|
+
const senderLPWallet = this.client.open(jetton_wallet_1.JettonWallet.createFromAddress(senderLPWalletAddress));
|
|
241
|
+
if (!(await this.client.isContractDeployed(senderWLPWalletAddress))) {
|
|
242
|
+
throw "not deployed lf wallet";
|
|
243
|
+
}
|
|
244
|
+
const queryId = generateRandomQueryId(params.senderAddress);
|
|
245
|
+
await senderLPWallet.sendTransfer(sender, params.gas || (0, ton_1.toNano)(0.1), {
|
|
246
|
+
queryId,
|
|
247
|
+
recipient: toAddress(senderWLPWalletAddress),
|
|
248
|
+
response: toAddress(params.senderAddress),
|
|
249
|
+
amount: params.amount,
|
|
250
|
+
forwardTonAmount: (0, ton_1.toNano)(0.02),
|
|
251
|
+
});
|
|
252
|
+
const steps = [];
|
|
253
|
+
steps.push(...[
|
|
254
|
+
{
|
|
255
|
+
queryId,
|
|
256
|
+
description: "tx send",
|
|
257
|
+
from: toAddress(params.senderAddress),
|
|
258
|
+
to: senderLPWallet.address,
|
|
259
|
+
opcode: jetton_wallet_1.JettonWallet.Op.Transfer,
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
queryId,
|
|
263
|
+
description: "mint",
|
|
264
|
+
from: toAddress(wlpLPWalletAddress),
|
|
265
|
+
to: senderWLPWalletAddress,
|
|
266
|
+
opcode: jetton_wallet_1.JettonWallet.Op.TransferNotification,
|
|
267
|
+
},
|
|
268
|
+
]);
|
|
269
|
+
(async () => {
|
|
270
|
+
const matchedTx0 = await this.findAndCallback(toAddress(params.senderAddress), steps[0], "0", callbackFn);
|
|
271
|
+
const matchedTx1 = await this.findAndCallback(senderWLPWalletAddress, steps[1], matchedTx0.lt.toString(), callbackFn);
|
|
272
|
+
})();
|
|
273
|
+
return steps;
|
|
274
|
+
}
|
|
275
|
+
async unwrapDedustWLPAndWaitTx(sender, params, callbackFn) {
|
|
276
|
+
const dedustWLPMinter = this.client.open(minter_1.LFDedustJettonMinter.createFromAddress(toAddress(params.wlpTokenAddress)));
|
|
277
|
+
const wlpData = await dedustWLPMinter.getWLPJettonData();
|
|
278
|
+
const underlyingAssetAddress = wlpData.assetAddress;
|
|
279
|
+
const underlyingAsset = this.client.open(jetton_minter_1.JettonMinter.createFromAddress(toAddress(underlyingAssetAddress)));
|
|
280
|
+
const senderWLPWalletAddress = await this.getJettonWalletAddress(toString(params.senderAddress), toString(params.wlpTokenAddress));
|
|
281
|
+
const senderWLPWallet = this.client.open(wallet_1.LFDedustJettonWallet.createFromAddress(senderWLPWalletAddress));
|
|
282
|
+
const wlpWalletData = await senderWLPWallet.getLiquidFarmData();
|
|
283
|
+
if (wlpWalletData.balance < params.amount) {
|
|
284
|
+
throw "not enough balance";
|
|
285
|
+
}
|
|
286
|
+
if (wlpWalletData.lockedAssetBalance < params.amount) {
|
|
287
|
+
throw "not enough locked asset balance";
|
|
288
|
+
}
|
|
289
|
+
const recipientLPWalletAddress = await underlyingAsset.getWalletAddress(toAddress(params.recipientAddress));
|
|
290
|
+
const wlpLPWalletAddress = await underlyingAsset.getWalletAddress(toAddress(senderWLPWalletAddress));
|
|
291
|
+
const queryId = generateRandomQueryId(params.senderAddress);
|
|
292
|
+
await senderWLPWallet.sendBurn(sender, {
|
|
293
|
+
value: params.gas || (0, ton_1.toNano)(0.2),
|
|
294
|
+
queryId,
|
|
295
|
+
amount: params.amount,
|
|
296
|
+
recipientAddress: toAddress(params.recipientAddress),
|
|
297
|
+
responseAddress: toAddress(params.responseAddress),
|
|
298
|
+
});
|
|
299
|
+
const steps = [];
|
|
300
|
+
steps.push(...[
|
|
301
|
+
{
|
|
302
|
+
queryId,
|
|
303
|
+
description: "tx send",
|
|
304
|
+
from: toAddress(params.senderAddress),
|
|
305
|
+
to: senderWLPWalletAddress,
|
|
306
|
+
opcode: wallet_1.LFDedustJettonWallet.Op.Burn,
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
queryId,
|
|
310
|
+
description: "send lp",
|
|
311
|
+
from: wlpLPWalletAddress,
|
|
312
|
+
to: recipientLPWalletAddress,
|
|
313
|
+
opcode: jetton_wallet_1.JettonWallet.Op.InternalTransfer,
|
|
314
|
+
},
|
|
315
|
+
]);
|
|
316
|
+
(async () => {
|
|
317
|
+
const matchedTx0 = await this.findAndCallback(toAddress(params.senderAddress), steps[0], "0", callbackFn);
|
|
318
|
+
const matchedTx1 = await this.findAndCallback(recipientLPWalletAddress, steps[1], matchedTx0.lt.toString(), callbackFn);
|
|
319
|
+
})();
|
|
320
|
+
return steps;
|
|
321
|
+
}
|
|
322
|
+
async unwrapStonfiWLPAndWaitTx(sender, params, callbackFn) {
|
|
323
|
+
const stonfiWLPMinter = this.client.open(LFStonfiJettonMinter_1.LFStonfiJettonMinter.createFromAddress(toAddress(params.wlpTokenAddress)));
|
|
324
|
+
const wlpData = await stonfiWLPMinter.getWLPJettonData();
|
|
325
|
+
const underlyingAssetAddress = wlpData.assetAddress;
|
|
326
|
+
const underlyingAsset = this.client.open(jetton_minter_1.JettonMinter.createFromAddress(toAddress(underlyingAssetAddress)));
|
|
327
|
+
const senderWLPWalletAddress = await this.getJettonWalletAddress(toString(params.senderAddress), toString(params.wlpTokenAddress));
|
|
328
|
+
const senderWLPWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(senderWLPWalletAddress));
|
|
329
|
+
const wlpWalletData = await senderWLPWallet.getLiquidFarmData();
|
|
330
|
+
if (wlpWalletData.balance < params.amount) {
|
|
331
|
+
throw "not enough balance";
|
|
332
|
+
}
|
|
333
|
+
if (wlpWalletData.lockedAssetBalance < params.amount) {
|
|
334
|
+
throw "not enough locked asset balance";
|
|
335
|
+
}
|
|
336
|
+
if (wlpWalletData.lockedAssetCash < params.amount) {
|
|
337
|
+
throw "not enough locked asset cash";
|
|
338
|
+
}
|
|
339
|
+
const recipientLPWalletAddress = await underlyingAsset.getWalletAddress(toAddress(params.recipientAddress));
|
|
340
|
+
const wlpLPWalletAddress = await underlyingAsset.getWalletAddress(toAddress(senderWLPWalletAddress));
|
|
341
|
+
const queryId = generateRandomQueryId(params.senderAddress);
|
|
342
|
+
await senderWLPWallet.sendBurn(sender, {
|
|
343
|
+
value: params.gas || (0, ton_1.toNano)(0.2),
|
|
344
|
+
queryId,
|
|
345
|
+
amount: params.amount,
|
|
346
|
+
recipientAddress: toAddress(params.recipientAddress),
|
|
347
|
+
responseAddress: toAddress(params.responseAddress),
|
|
348
|
+
});
|
|
349
|
+
const steps = [];
|
|
350
|
+
steps.push(...[
|
|
351
|
+
{
|
|
352
|
+
queryId,
|
|
353
|
+
description: "tx send",
|
|
354
|
+
from: toAddress(params.senderAddress),
|
|
355
|
+
to: senderWLPWalletAddress,
|
|
356
|
+
opcode: wallet_1.LFDedustJettonWallet.Op.Burn,
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
queryId,
|
|
360
|
+
description: "send lp",
|
|
361
|
+
from: wlpLPWalletAddress,
|
|
362
|
+
to: recipientLPWalletAddress,
|
|
363
|
+
opcode: jetton_wallet_1.JettonWallet.Op.InternalTransfer,
|
|
364
|
+
},
|
|
365
|
+
]);
|
|
366
|
+
(async () => {
|
|
367
|
+
const matchedTx0 = await this.findAndCallback(toAddress(params.senderAddress), steps[0], "0", callbackFn);
|
|
368
|
+
const matchedTx1 = await this.findAndCallback(recipientLPWalletAddress, steps[1], matchedTx0.lt.toString(), callbackFn);
|
|
369
|
+
})();
|
|
370
|
+
return steps;
|
|
371
|
+
}
|
|
372
|
+
async seizeDedustLPAndWaitTx(sender, params, callbackFn) {
|
|
373
|
+
const dedustWLPMinter = this.client.open(minter_1.LFDedustJettonMinter.createFromAddress(toAddress(params.wlpTokenAddress)));
|
|
374
|
+
const wlpData = await dedustWLPMinter.getWLPJettonData();
|
|
375
|
+
const underlyingAssetAddress = wlpData.assetAddress;
|
|
376
|
+
const senderWLPWalletAddress = await this.getJettonWalletAddress(toString(params.senderAddress), toString(params.wlpTokenAddress));
|
|
377
|
+
const targetWLPWalletAddress = await this.getJettonWalletAddress(toString(params.targetAddress), toString(params.wlpTokenAddress));
|
|
378
|
+
const senderWLPWallet = this.client.open(wallet_1.LFDedustJettonWallet.createFromAddress(senderWLPWalletAddress));
|
|
379
|
+
const wlpWalletData = await senderWLPWallet.getLiquidFarmData();
|
|
380
|
+
if (wlpWalletData.balance - wlpWalletData.lockedAssetBalance <
|
|
381
|
+
params.amount) {
|
|
382
|
+
throw "not enough balance";
|
|
383
|
+
}
|
|
384
|
+
const targetWLPWallet = this.client.open(wallet_1.LFDedustJettonWallet.createFromAddress(targetWLPWalletAddress));
|
|
385
|
+
const targetWlpWalletData = await targetWLPWallet.getLiquidFarmData();
|
|
386
|
+
let balance = targetWlpWalletData.balance;
|
|
387
|
+
if (targetWlpWalletData.poolAccountAddress &&
|
|
388
|
+
targetWlpWalletData.connectedWithPoolAccount) {
|
|
389
|
+
targetWlpWalletData.poolAccountAddress;
|
|
390
|
+
const targetAccount = this.client.open(account_1.Account.createFromAddress(targetWlpWalletData.poolAccountAddress));
|
|
391
|
+
const accountData = await targetAccount.getAccountData();
|
|
392
|
+
if (accountData.status[toString(params.wlpTokenAddress)]) {
|
|
393
|
+
balance += accountData.status[toString(params.wlpTokenAddress)].supply;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
if (targetWlpWalletData.lockedAssetBalance - balance < params.amount) {
|
|
397
|
+
throw "not enough liquidity";
|
|
398
|
+
}
|
|
399
|
+
const queryId = generateRandomQueryId(params.senderAddress);
|
|
400
|
+
const result = await senderWLPWallet.sendSeize(sender, {
|
|
401
|
+
value: (0, ton_1.toNano)(0.11),
|
|
402
|
+
queryId,
|
|
403
|
+
targetAddress: toAddress(params.targetAddress),
|
|
404
|
+
responseAddress: toAddress(params.responseAddress),
|
|
405
|
+
amount: params.amount,
|
|
406
|
+
});
|
|
407
|
+
const underlyingAsset = this.client.open(jetton_minter_1.JettonMinter.createFromAddress(underlyingAssetAddress));
|
|
408
|
+
const targetWlpLpWalletAddress = await underlyingAsset.getWalletAddress(targetWLPWalletAddress);
|
|
409
|
+
const senderLpWalletAddress = await underlyingAsset.getWalletAddress(toAddress(params.senderAddress));
|
|
410
|
+
const steps = [];
|
|
411
|
+
steps.push(...[
|
|
412
|
+
{
|
|
413
|
+
queryId,
|
|
414
|
+
description: "tx send",
|
|
415
|
+
from: toAddress(params.senderAddress),
|
|
416
|
+
to: senderWLPWallet.address,
|
|
417
|
+
opcode: wallet_1.LFDedustJettonWallet.Op.Seize,
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
queryId,
|
|
421
|
+
description: "mint",
|
|
422
|
+
from: toAddress(targetWlpLpWalletAddress),
|
|
423
|
+
to: senderLpWalletAddress,
|
|
424
|
+
opcode: jetton_wallet_1.JettonWallet.Op.InternalTransfer,
|
|
425
|
+
},
|
|
426
|
+
]);
|
|
427
|
+
(async () => {
|
|
428
|
+
const matchedTx0 = await this.findAndCallback(toAddress(params.senderAddress), steps[0], "0", callbackFn);
|
|
429
|
+
const matchedTx1 = await this.findAndCallback(senderLpWalletAddress, steps[1], matchedTx0.lt.toString(), callbackFn);
|
|
430
|
+
})();
|
|
431
|
+
return steps;
|
|
432
|
+
}
|
|
433
|
+
async seizeStonfiLPAndWaitTx(sender, params, callbackFn) {
|
|
434
|
+
const stonfiWLPMinter = this.client.open(LFStonfiJettonMinter_1.LFStonfiJettonMinter.createFromAddress(toAddress(params.wlpTokenAddress)));
|
|
435
|
+
const wlpData = await stonfiWLPMinter.getWLPJettonData();
|
|
436
|
+
const underlyingAssetAddress = wlpData.assetAddress;
|
|
437
|
+
const underlyingAsset = this.client.open(jetton_minter_1.JettonMinter.createFromAddress(underlyingAssetAddress));
|
|
438
|
+
const senderLpWalletAddress = await underlyingAsset.getWalletAddress(toAddress(params.senderAddress));
|
|
439
|
+
const senderWLPWalletAddress = await this.getJettonWalletAddress(toString(params.senderAddress), toString(params.wlpTokenAddress));
|
|
440
|
+
const targetWLPWalletAddress = await this.getJettonWalletAddress(toString(params.targetAddress), toString(params.wlpTokenAddress));
|
|
441
|
+
const senderWLPWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(senderWLPWalletAddress));
|
|
442
|
+
const wlpWalletData = await senderWLPWallet.getLiquidFarmData();
|
|
443
|
+
if (wlpWalletData.balance - wlpWalletData.lockedAssetBalance <
|
|
444
|
+
params.amount) {
|
|
445
|
+
throw "not enough balance";
|
|
446
|
+
}
|
|
447
|
+
const targetWLPWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(targetWLPWalletAddress));
|
|
448
|
+
const targetWlpWalletData = await targetWLPWallet.getLiquidFarmData();
|
|
449
|
+
if (targetWlpWalletData.lockedAssetCash < params.amount) {
|
|
450
|
+
throw "not enough balance, try to unfarm & sync";
|
|
451
|
+
}
|
|
452
|
+
let balance = targetWlpWalletData.balance;
|
|
453
|
+
if (targetWlpWalletData.poolAccountAddress &&
|
|
454
|
+
targetWlpWalletData.connectedWithPoolAccount) {
|
|
455
|
+
targetWlpWalletData.poolAccountAddress;
|
|
456
|
+
const targetAccount = this.client.open(account_1.Account.createFromAddress(targetWlpWalletData.poolAccountAddress));
|
|
457
|
+
const accountData = await targetAccount.getAccountData();
|
|
458
|
+
if (accountData.status[toString(params.wlpTokenAddress)]) {
|
|
459
|
+
balance += accountData.status[toString(params.wlpTokenAddress)].supply;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (targetWlpWalletData.lockedAssetBalance - balance < params.amount) {
|
|
463
|
+
throw "not enough liquidity";
|
|
464
|
+
}
|
|
465
|
+
const targetWlpLpWalletAddress = await underlyingAsset.getWalletAddress(targetWLPWalletAddress);
|
|
466
|
+
const targetWlpLpWallet = this.client.open(jetton_wallet_1.JettonWallet.createFromAddress(targetWlpLpWalletAddress));
|
|
467
|
+
const targetWlpLpWalletData = await targetWlpLpWallet.getWalletData();
|
|
468
|
+
const queryId = generateRandomQueryId(params.senderAddress);
|
|
469
|
+
const result = await senderWLPWallet.sendSeize(sender, {
|
|
470
|
+
value: (0, ton_1.toNano)(0.11),
|
|
471
|
+
queryId,
|
|
472
|
+
targetAddress: toAddress(params.targetAddress),
|
|
473
|
+
responseAddress: toAddress(params.responseAddress),
|
|
474
|
+
amount: params.amount,
|
|
475
|
+
});
|
|
476
|
+
const steps = [];
|
|
477
|
+
steps.push(...[
|
|
478
|
+
{
|
|
479
|
+
queryId,
|
|
480
|
+
description: "tx send",
|
|
481
|
+
from: toAddress(params.senderAddress),
|
|
482
|
+
to: senderWLPWallet.address,
|
|
483
|
+
opcode: wallet_1.LFDedustJettonWallet.Op.Seize,
|
|
484
|
+
},
|
|
485
|
+
{
|
|
486
|
+
queryId,
|
|
487
|
+
description: "mint",
|
|
488
|
+
from: toAddress(targetWlpLpWalletAddress),
|
|
489
|
+
to: senderLpWalletAddress,
|
|
490
|
+
opcode: jetton_wallet_1.JettonWallet.Op.InternalTransfer,
|
|
491
|
+
},
|
|
492
|
+
]);
|
|
493
|
+
(async () => {
|
|
494
|
+
const matchedTx0 = await this.findAndCallback(toAddress(params.senderAddress), steps[0], "0", callbackFn);
|
|
495
|
+
const matchedTx1 = await this.findAndCallback(senderLpWalletAddress, steps[1], matchedTx0.lt.toString(), callbackFn);
|
|
496
|
+
})();
|
|
497
|
+
return steps;
|
|
498
|
+
}
|
|
499
|
+
async syncStonfiWLPAndWaitTx(sender, params, callbackFn) {
|
|
500
|
+
const stonfiWLPMinter = this.client.open(LFStonfiJettonMinter_1.LFStonfiJettonMinter.createFromAddress(toAddress(params.wlpTokenAddress)));
|
|
501
|
+
const wlpData = await stonfiWLPMinter.getWLPJettonData();
|
|
502
|
+
const queryId = generateRandomQueryId(params.senderAddress);
|
|
503
|
+
const targetWLPWalletAddress = await this.getJettonWalletAddress(toString(params.targetAddress), toString(params.wlpTokenAddress));
|
|
504
|
+
const targetWLPWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(targetWLPWalletAddress));
|
|
505
|
+
await targetWLPWallet.sendSyncLockedAssetCash(sender, params.gas || (0, ton_1.toNano)(0.16), {
|
|
506
|
+
queryId,
|
|
507
|
+
});
|
|
508
|
+
const underlyingAsset = this.client.open(jetton_minter_1.JettonMinter.createFromAddress(toAddress(wlpData.assetAddress)));
|
|
509
|
+
const targetWlpLPWalletAddress = await underlyingAsset.getWalletAddress(toAddress(targetWLPWalletAddress));
|
|
510
|
+
const steps = [];
|
|
511
|
+
steps.push(...[
|
|
512
|
+
{
|
|
513
|
+
queryId,
|
|
514
|
+
description: "tx send",
|
|
515
|
+
from: toAddress(params.senderAddress),
|
|
516
|
+
to: targetWLPWalletAddress,
|
|
517
|
+
opcode: LFStonfiJettonWallet_1.LFStonfiJettonWallet.Op.SyncLockedAssetCash,
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
queryId,
|
|
521
|
+
description: "sync",
|
|
522
|
+
from: toAddress(targetWlpLPWalletAddress),
|
|
523
|
+
to: targetWLPWalletAddress,
|
|
524
|
+
opcode: jetton_wallet_1.JettonWallet.Op.TransferNotification,
|
|
525
|
+
},
|
|
526
|
+
]);
|
|
527
|
+
(async () => {
|
|
528
|
+
const matchedTx0 = await this.findAndCallback(toAddress(params.senderAddress), steps[0], "0", callbackFn);
|
|
529
|
+
const matchedTx1 = await this.findAndCallback(targetWLPWalletAddress, steps[1], matchedTx0.lt.toString(), callbackFn);
|
|
530
|
+
})();
|
|
531
|
+
return steps;
|
|
532
|
+
}
|
|
533
|
+
async isSeizableDedustLP(params) {
|
|
534
|
+
const dedustWLPMinter = this.client.open(minter_1.LFDedustJettonMinter.createFromAddress(toAddress(params.wlpTokenAddress)));
|
|
535
|
+
const wlpData = await dedustWLPMinter.getWLPJettonData();
|
|
536
|
+
if (params.senderAddress) {
|
|
537
|
+
const senderWLPWalletAddress = await this.getJettonWalletAddress(toString(params.senderAddress), toString(params.wlpTokenAddress));
|
|
538
|
+
const senderWLPWallet = this.client.open(wallet_1.LFDedustJettonWallet.createFromAddress(senderWLPWalletAddress));
|
|
539
|
+
const wlpWalletData = await senderWLPWallet.getLiquidFarmData();
|
|
540
|
+
if (wlpWalletData.balance - wlpWalletData.lockedAssetBalance <
|
|
541
|
+
params.amount) {
|
|
542
|
+
return {
|
|
543
|
+
seizable: false,
|
|
544
|
+
errorType: 1,
|
|
545
|
+
message: "not enough seizer's wlp balance",
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
const targetWLPWalletAddress = await this.getJettonWalletAddress(toString(params.targetAddress), toString(params.wlpTokenAddress));
|
|
550
|
+
const targetWLPWallet = this.client.open(wallet_1.LFDedustJettonWallet.createFromAddress(targetWLPWalletAddress));
|
|
551
|
+
const targetWlpWalletData = await targetWLPWallet.getLiquidFarmData();
|
|
552
|
+
let balance = targetWlpWalletData.balance;
|
|
553
|
+
if (targetWlpWalletData.poolAccountAddress &&
|
|
554
|
+
targetWlpWalletData.connectedWithPoolAccount) {
|
|
555
|
+
targetWlpWalletData.poolAccountAddress;
|
|
556
|
+
const targetAccount = this.client.open(account_1.Account.createFromAddress(targetWlpWalletData.poolAccountAddress));
|
|
557
|
+
const accountData = await targetAccount.getAccountData();
|
|
558
|
+
if (accountData.status[toString(params.wlpTokenAddress)]) {
|
|
559
|
+
balance += accountData.status[toString(params.wlpTokenAddress)].supply;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
if (targetWlpWalletData.lockedAssetBalance - balance < params.amount) {
|
|
563
|
+
return {
|
|
564
|
+
seizable: false,
|
|
565
|
+
errorType: 2,
|
|
566
|
+
message: "not enough liquidity",
|
|
567
|
+
wlpBalance: balance,
|
|
568
|
+
lockedAssetBalance: targetWlpWalletData.lockedAssetBalance,
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
return {
|
|
572
|
+
seizable: true,
|
|
573
|
+
wlpBalance: balance,
|
|
574
|
+
lockedAssetBalance: targetWlpWalletData.lockedAssetBalance,
|
|
575
|
+
seizableAmount: targetWlpWalletData.lockedAssetBalance - balance,
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
async isSeizableStonfiLP(params) {
|
|
579
|
+
const stonfiWLPMinter = this.client.open(LFStonfiJettonMinter_1.LFStonfiJettonMinter.createFromAddress(toAddress(params.wlpTokenAddress)));
|
|
580
|
+
const wlpData = await stonfiWLPMinter.getWLPJettonData();
|
|
581
|
+
if (params.senderAddress) {
|
|
582
|
+
const senderWLPWalletAddress = await this.getJettonWalletAddress(toString(params.senderAddress), toString(params.wlpTokenAddress));
|
|
583
|
+
const senderWLPWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(senderWLPWalletAddress));
|
|
584
|
+
const wlpWalletData = await senderWLPWallet.getLiquidFarmData();
|
|
585
|
+
if (wlpWalletData.balance - wlpWalletData.lockedAssetBalance <
|
|
586
|
+
params.amount) {
|
|
587
|
+
return {
|
|
588
|
+
seizable: false,
|
|
589
|
+
errorType: 1,
|
|
590
|
+
message: "not enough seizer's wlp balance",
|
|
591
|
+
balance: wlpWalletData.balance - wlpWalletData.lockedAssetBalance,
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
const targetWLPWalletAddress = await this.getJettonWalletAddress(toString(params.targetAddress), toString(params.wlpTokenAddress));
|
|
596
|
+
const targetWLPWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(targetWLPWalletAddress));
|
|
597
|
+
const targetWlpWalletData = await targetWLPWallet.getLiquidFarmData();
|
|
598
|
+
let balance = targetWlpWalletData.balance;
|
|
599
|
+
if (targetWlpWalletData.poolAccountAddress &&
|
|
600
|
+
targetWlpWalletData.connectedWithPoolAccount) {
|
|
601
|
+
targetWlpWalletData.poolAccountAddress;
|
|
602
|
+
const targetAccount = this.client.open(account_1.Account.createFromAddress(targetWlpWalletData.poolAccountAddress));
|
|
603
|
+
const accountData = await targetAccount.getAccountData();
|
|
604
|
+
if (accountData.status[toString(params.wlpTokenAddress)]) {
|
|
605
|
+
balance += accountData.status[toString(params.wlpTokenAddress)].supply;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
if (targetWlpWalletData.lockedAssetBalance - balance < params.amount) {
|
|
609
|
+
return {
|
|
610
|
+
seizable: false,
|
|
611
|
+
errorType: 2,
|
|
612
|
+
message: "not enough liquidity",
|
|
613
|
+
wlpBalance: balance,
|
|
614
|
+
lockedAssetBalance: targetWlpWalletData.lockedAssetBalance,
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
if (targetWlpWalletData.lockedAssetCash < params.amount) {
|
|
618
|
+
const underlyingAssetAddress = wlpData.assetAddress;
|
|
619
|
+
const underlyingAsset = this.client.open(jetton_minter_1.JettonMinter.createFromAddress(underlyingAssetAddress));
|
|
620
|
+
const targetWlpLpWalletAddress = await underlyingAsset.getWalletAddress(targetWLPWalletAddress);
|
|
621
|
+
const targetWlpLpWallet = this.client.open(jetton_wallet_1.JettonWallet.createFromAddress(targetWlpLpWalletAddress));
|
|
622
|
+
const targetWlpLpWalletData = await targetWlpLpWallet.getWalletData();
|
|
623
|
+
const result = {
|
|
624
|
+
seizable: false,
|
|
625
|
+
errorType: 3,
|
|
626
|
+
wlpBalance: balance,
|
|
627
|
+
message: "",
|
|
628
|
+
lockedAssetBalance: targetWlpWalletData.lockedAssetBalance,
|
|
629
|
+
lockedAssetCash: targetWlpWalletData.lockedAssetCash,
|
|
630
|
+
};
|
|
631
|
+
if (targetWlpWalletData.lockedAssetBalance === targetWlpLpWalletData.balance) {
|
|
632
|
+
result.message += "not enough locked asset cash, try to sync";
|
|
633
|
+
}
|
|
634
|
+
else {
|
|
635
|
+
result.message += "not enough locked asset cash, try to unfarm";
|
|
636
|
+
result.nfts = await this.getStonfiWLPFarmedNfts({
|
|
637
|
+
wlpTokenAddress: params.wlpTokenAddress,
|
|
638
|
+
targetAddress: params.targetAddress,
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
return result;
|
|
642
|
+
}
|
|
643
|
+
return {
|
|
644
|
+
seizable: true,
|
|
645
|
+
wlpBalance: balance,
|
|
646
|
+
lockedAssetBalance: targetWlpWalletData.lockedAssetBalance,
|
|
647
|
+
seizableAmount: targetWlpWalletData.lockedAssetBalance - balance,
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
async farmStonfiWLPAndWaitTx(sender, params, callbackFn) {
|
|
651
|
+
const stonfiWLPMinter = this.client.open(LFStonfiJettonMinter_1.LFStonfiJettonMinter.createFromAddress(toAddress(params.wlpTokenAddress)));
|
|
652
|
+
const wlpData = await stonfiWLPMinter.getWLPJettonData();
|
|
653
|
+
const senderWLPWalletAddress = await this.getJettonWalletAddress(toString(params.senderAddress), toString(params.wlpTokenAddress));
|
|
654
|
+
const senderWLPWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(senderWLPWalletAddress));
|
|
655
|
+
const farmLPWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(senderWLPWalletAddress));
|
|
656
|
+
const queryId = generateRandomQueryId(params.senderAddress);
|
|
657
|
+
const result = await senderWLPWallet.sendFarm(sender, params.gas || (0, ton_1.toNano)(0.5), {
|
|
658
|
+
queryId,
|
|
659
|
+
amount: params.amount,
|
|
660
|
+
response: toAddress(params.responseAddress),
|
|
661
|
+
forwardTonAmount: (0, ton_1.toNano)(0.35),
|
|
662
|
+
});
|
|
663
|
+
const steps = [];
|
|
664
|
+
steps.push(...[
|
|
665
|
+
{
|
|
666
|
+
queryId,
|
|
667
|
+
description: "tx send",
|
|
668
|
+
from: toAddress(params.senderAddress),
|
|
669
|
+
to: senderWLPWallet.address,
|
|
670
|
+
opcode: LFStonfiJettonWallet_1.LFStonfiJettonWallet.Op.Farm,
|
|
671
|
+
},
|
|
672
|
+
{
|
|
673
|
+
queryId,
|
|
674
|
+
description: "farm notification",
|
|
675
|
+
to: wlpData.farmAddress,
|
|
676
|
+
opcode: jetton_wallet_1.JettonWallet.Op.TransferNotification,
|
|
677
|
+
},
|
|
678
|
+
{
|
|
679
|
+
queryId,
|
|
680
|
+
description: "mint",
|
|
681
|
+
from: senderWLPWallet.address,
|
|
682
|
+
to: toAddress(params.senderAddress),
|
|
683
|
+
opcode: jetton_wallet_1.JettonWallet.Op.Excesses,
|
|
684
|
+
},
|
|
685
|
+
]);
|
|
686
|
+
(async () => {
|
|
687
|
+
const matchedTx0 = await this.findAndCallback(toAddress(params.senderAddress), steps[0], "0", callbackFn);
|
|
688
|
+
const matchedTx1 = await this.findAndCallback(wlpData.farmAddress, steps[1], matchedTx0.lt.toString(), callbackFn);
|
|
689
|
+
const matchedTx2 = await this.findAndCallback(senderWLPWallet.address, steps[2], matchedTx1.lt.toString(), callbackFn);
|
|
690
|
+
})();
|
|
691
|
+
return steps;
|
|
692
|
+
}
|
|
693
|
+
async unfarmStonfiWLPAndWaitTx(sender, params, callbackFn) {
|
|
694
|
+
const stonfiWLPMinter = this.client.open(LFStonfiJettonMinter_1.LFStonfiJettonMinter.createFromAddress(toAddress(params.wlpTokenAddress)));
|
|
695
|
+
const wlpData = await stonfiWLPMinter.getWLPJettonData();
|
|
696
|
+
const targetWLPWalletAddress = await this.getJettonWalletAddress(toString(params.targetAddress), toString(params.wlpTokenAddress));
|
|
697
|
+
const targetWLPWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(targetWLPWalletAddress));
|
|
698
|
+
const underlyingAsset = this.client.open(jetton_minter_1.JettonMinter.createFromAddress(toAddress(wlpData.assetAddress)));
|
|
699
|
+
const wlpLPWalletAddress = await underlyingAsset.getWalletAddress(toAddress(targetWLPWalletAddress));
|
|
700
|
+
const farmLPWalletAddress = await underlyingAsset.getWalletAddress(toAddress(wlpData.farmAddress));
|
|
701
|
+
const queryId = generateRandomQueryId(params.senderAddress);
|
|
702
|
+
await targetWLPWallet.sendUnfarm(sender, params.gas || (0, ton_1.toNano)(0.42), {
|
|
703
|
+
queryId,
|
|
704
|
+
nftAddress: toAddress(params.nftAddress),
|
|
705
|
+
});
|
|
706
|
+
const steps = [];
|
|
707
|
+
steps.push(...[
|
|
708
|
+
{
|
|
709
|
+
queryId,
|
|
710
|
+
description: "tx send",
|
|
711
|
+
from: toAddress(params.senderAddress),
|
|
712
|
+
to: targetWLPWalletAddress,
|
|
713
|
+
opcode: LFStonfiJettonWallet_1.LFStonfiJettonWallet.Op.Unfarm,
|
|
714
|
+
},
|
|
715
|
+
{
|
|
716
|
+
queryId,
|
|
717
|
+
description: "unfarm notification",
|
|
718
|
+
from: toAddress(params.nftAddress),
|
|
719
|
+
to: wlpData.farmAddress,
|
|
720
|
+
opcode: 0xa1312496,
|
|
721
|
+
},
|
|
722
|
+
{
|
|
723
|
+
queryId,
|
|
724
|
+
description: "transfer",
|
|
725
|
+
from: farmLPWalletAddress,
|
|
726
|
+
to: wlpLPWalletAddress,
|
|
727
|
+
opcode: jetton_wallet_1.JettonWallet.Op.InternalTransfer,
|
|
728
|
+
},
|
|
729
|
+
]);
|
|
730
|
+
(async () => {
|
|
731
|
+
const matchedTx0 = await this.findAndCallback(toAddress(params.senderAddress), steps[0], "0", callbackFn);
|
|
732
|
+
const matchedTx1 = await this.findAndCallback(wlpData.farmAddress, steps[1], matchedTx0.lt.toString(), callbackFn);
|
|
733
|
+
const matchedTx2 = await this.findAndCallback(wlpLPWalletAddress, steps[2], matchedTx1.lt.toString(), callbackFn);
|
|
734
|
+
})();
|
|
735
|
+
return steps;
|
|
736
|
+
}
|
|
737
|
+
async getStonfiWLPFarmedNfts(params) {
|
|
738
|
+
throw Error("Not implemented");
|
|
739
|
+
// const response = await axios.get(`https://626wfskayjpoilzz7czxsfed7q0xiymi.lambda-url.ap-northeast-2.on.aws/?owner=${toString(params.targetAddress)}`);
|
|
740
|
+
// const targetWLPWalletAddress = await this.getJettonWalletAddress(
|
|
741
|
+
// toString(params.targetAddress),
|
|
742
|
+
// toString(params.wlpTokenAddress)
|
|
743
|
+
// );
|
|
744
|
+
// const lp = response.data.data.find((item: any) => item.lfWalletAddress === toString(targetWLPWalletAddress));
|
|
745
|
+
// if (!lp) return [];
|
|
746
|
+
// const nftStatus = await Promise.all(lp.nftItems.map((item: any) => this.getStonfiFarmingData(item)));
|
|
747
|
+
// const activeNfts = nftStatus.filter(item => item.status === 1);
|
|
748
|
+
// return activeNfts.map(item => item.address);
|
|
749
|
+
}
|
|
750
|
+
async lock(sender, senderAddress, lpTokenAddress, lfTokenAddress, amount, gas) {
|
|
751
|
+
const senderJettonWalletAddress = await this.getJettonWalletAddress(toString(senderAddress), toString(lpTokenAddress));
|
|
752
|
+
const senderJettonWallet = this.client.open(jetton_wallet_1.JettonWallet.createFromAddress(senderJettonWalletAddress));
|
|
753
|
+
const target = await this.getJettonWalletAddress(toString(senderAddress), toString(lfTokenAddress));
|
|
754
|
+
await senderJettonWallet.sendTransfer(sender, gas || (0, ton_1.toNano)(0.1), {
|
|
755
|
+
recipient: toAddress(target),
|
|
756
|
+
response: toAddress(senderAddress),
|
|
757
|
+
amount: amount,
|
|
758
|
+
forwardTonAmount: (0, ton_1.toNano)(0.02),
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
async withdrawTons(sender, senderAddress, wlpAddress) {
|
|
762
|
+
const senderWLPWalletAddress = await this.getJettonWalletAddress(toString(senderAddress), toString(wlpAddress));
|
|
763
|
+
const senderWLPWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(senderWLPWalletAddress));
|
|
764
|
+
const queryId = generateRandomQueryId(senderAddress);
|
|
765
|
+
await senderWLPWallet.sendWithdrawTons(sender, (0, ton_1.toNano)(0.1), {
|
|
766
|
+
queryId,
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
async withdrawTonAndWaitTx(sender, params, callbackFn) {
|
|
770
|
+
const senderWLPWalletAddress = await this.getJettonWalletAddress(toString(params.senderAddress), toString(params.wlpAddress));
|
|
771
|
+
const senderWLPWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(senderWLPWalletAddress));
|
|
772
|
+
const queryId = generateRandomQueryId(params.senderAddress);
|
|
773
|
+
await senderWLPWallet.sendWithdrawTons(sender, (0, ton_1.toNano)(0.1), {
|
|
774
|
+
queryId,
|
|
775
|
+
});
|
|
776
|
+
const steps = [];
|
|
777
|
+
steps.push(...[
|
|
778
|
+
{
|
|
779
|
+
queryId,
|
|
780
|
+
description: "tx send",
|
|
781
|
+
from: toAddress(params.senderAddress),
|
|
782
|
+
to: senderWLPWalletAddress,
|
|
783
|
+
opcode: LFStonfiJettonWallet_1.LFStonfiJettonWallet.Op.WithdrawTons,
|
|
784
|
+
},
|
|
785
|
+
{
|
|
786
|
+
queryId,
|
|
787
|
+
description: "withdraw tons",
|
|
788
|
+
from: senderWLPWalletAddress,
|
|
789
|
+
to: toAddress(params.senderAddress),
|
|
790
|
+
opcode: jetton_wallet_1.JettonWallet.Op.Excesses,
|
|
791
|
+
},
|
|
792
|
+
]);
|
|
793
|
+
(async () => {
|
|
794
|
+
const matchedTx0 = await this.findAndCallback(toAddress(params.senderAddress), steps[0], "0", callbackFn);
|
|
795
|
+
const matchedTx1 = await this.findAndCallback(toAddress(params.senderAddress), steps[1], matchedTx0.lt.toString(), callbackFn);
|
|
796
|
+
})();
|
|
797
|
+
return steps;
|
|
798
|
+
}
|
|
799
|
+
async withdrawJettons(sender, senderAddress, wlpAddress, assetAddress, amount) {
|
|
800
|
+
const senderWLPWalletAddress = await this.getJettonWalletAddress(toString(senderAddress), toString(wlpAddress));
|
|
801
|
+
const senderWLPWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(senderWLPWalletAddress));
|
|
802
|
+
const wlpAssetWalletAddress = await this.getJettonWalletAddress(toString(senderWLPWalletAddress), toString(assetAddress));
|
|
803
|
+
const queryId = generateRandomQueryId(senderAddress);
|
|
804
|
+
await senderWLPWallet.sendWithdrawJettons(sender, (0, ton_1.toNano)(0.1), {
|
|
805
|
+
queryId,
|
|
806
|
+
wallet: toAddress(wlpAssetWalletAddress),
|
|
807
|
+
amount: amount,
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
async withdrawJettonAndWaitTx(sender, params, callbackFn) {
|
|
811
|
+
const senderWLPWalletAddress = await this.getJettonWalletAddress(toString(params.senderAddress), toString(params.wlpAddress));
|
|
812
|
+
const senderWLPWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(senderWLPWalletAddress));
|
|
813
|
+
const wlpAssetWalletAddress = await this.getJettonWalletAddress(toString(senderWLPWalletAddress), toString(params.assetAddress));
|
|
814
|
+
const senderAssetWalletAddress = await this.getJettonWalletAddress(toString(params.senderAddress), toString(params.assetAddress));
|
|
815
|
+
const queryId = generateRandomQueryId(params.senderAddress);
|
|
816
|
+
await senderWLPWallet.sendWithdrawJettons(sender, (0, ton_1.toNano)(0.1), {
|
|
817
|
+
queryId,
|
|
818
|
+
wallet: toAddress(wlpAssetWalletAddress),
|
|
819
|
+
amount: params.amount,
|
|
820
|
+
});
|
|
821
|
+
const steps = [];
|
|
822
|
+
steps.push(...[
|
|
823
|
+
{
|
|
824
|
+
queryId,
|
|
825
|
+
description: "tx send",
|
|
826
|
+
from: toAddress(params.senderAddress),
|
|
827
|
+
to: senderWLPWalletAddress,
|
|
828
|
+
opcode: LFStonfiJettonWallet_1.LFStonfiJettonWallet.Op.WithdrawJettons,
|
|
829
|
+
},
|
|
830
|
+
{
|
|
831
|
+
queryId,
|
|
832
|
+
description: "transfer",
|
|
833
|
+
from: senderWLPWalletAddress,
|
|
834
|
+
to: wlpAssetWalletAddress,
|
|
835
|
+
opcode: jetton_wallet_1.JettonWallet.Op.Transfer,
|
|
836
|
+
},
|
|
837
|
+
{
|
|
838
|
+
queryId,
|
|
839
|
+
description: "internal_transfer",
|
|
840
|
+
from: wlpAssetWalletAddress,
|
|
841
|
+
to: senderAssetWalletAddress,
|
|
842
|
+
opcode: jetton_wallet_1.JettonWallet.Op.InternalTransfer,
|
|
843
|
+
},
|
|
844
|
+
]);
|
|
845
|
+
(async () => {
|
|
846
|
+
const matchedTx0 = await this.findAndCallback(toAddress(params.senderAddress), steps[0], "0", callbackFn);
|
|
847
|
+
const matchedTx1 = await this.findAndCallback(wlpAssetWalletAddress, steps[1], matchedTx0.lt.toString(), callbackFn);
|
|
848
|
+
const matchedTx2 = await this.findAndCallback(senderAssetWalletAddress, steps[2], matchedTx1.lt.toString(), callbackFn);
|
|
849
|
+
})();
|
|
850
|
+
return steps;
|
|
851
|
+
}
|
|
852
|
+
async getStonfiLFData(lfTokenAddress, targetAddress) {
|
|
853
|
+
const targetJettonWalletAddress = await this.getJettonWalletAddress(toString(targetAddress), toString(lfTokenAddress));
|
|
854
|
+
const targetJettonWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(targetJettonWalletAddress));
|
|
855
|
+
return targetJettonWallet.getLiquidFarmData();
|
|
856
|
+
}
|
|
857
|
+
async getDedustLFData(lfTokenAddress, targetAddress) {
|
|
858
|
+
const targetJettonWalletAddress = await this.getJettonWalletAddress(toString(targetAddress), toString(lfTokenAddress));
|
|
859
|
+
const targetJettonWallet = this.client.open(wallet_1.LFDedustJettonWallet.createFromAddress(targetJettonWalletAddress));
|
|
860
|
+
return targetJettonWallet.getLiquidFarmData();
|
|
861
|
+
}
|
|
862
|
+
async dedustUnlock(sender, senderAddress, lfTokenAddress, amount, gas) {
|
|
863
|
+
const senderJettonWalletAddress = await this.getJettonWalletAddress(toString(senderAddress), toString(lfTokenAddress));
|
|
864
|
+
const senderJettonWallet = this.client.open(wallet_1.LFDedustJettonWallet.createFromAddress(senderJettonWalletAddress));
|
|
865
|
+
await senderJettonWallet.sendBurn(sender, {
|
|
866
|
+
amount,
|
|
867
|
+
value: gas || (0, ton_1.toNano)(0.2),
|
|
868
|
+
recipientAddress: toAddress(senderAddress),
|
|
869
|
+
responseAddress: toAddress(senderAddress),
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
async stonfiUnlock(sender, senderAddress, lfTokenAddress, amount, gas) {
|
|
873
|
+
const senderJettonWalletAddress = await this.getJettonWalletAddress(toString(senderAddress), toString(lfTokenAddress));
|
|
874
|
+
const senderJettonWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(senderJettonWalletAddress));
|
|
875
|
+
await senderJettonWallet.sendBurn(sender, {
|
|
876
|
+
amount,
|
|
877
|
+
value: gas || (0, ton_1.toNano)(0.2),
|
|
878
|
+
recipientAddress: toAddress(senderAddress),
|
|
879
|
+
responseAddress: toAddress(senderAddress),
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
async claimDedustRewardAndWaitTx(sender, params, callbackFn) {
|
|
883
|
+
const senderWLPWalletAddress = await this.getJettonWalletAddress(toString(params.senderAddress), toString(params.wlpTokenAddress));
|
|
884
|
+
const senderWLPWallet = this.client.open(wallet_1.LFDedustJettonWallet.createFromAddress(senderWLPWalletAddress));
|
|
885
|
+
const queryId = generateRandomQueryId(params.senderAddress);
|
|
886
|
+
await senderWLPWallet.sendClaimRewards(sender, {
|
|
887
|
+
queryId,
|
|
888
|
+
value: params.gas || (0, ton_1.toNano)(0.3),
|
|
889
|
+
distributorAddress: toAddress(params.distributorAddress),
|
|
890
|
+
proof: params.proof,
|
|
891
|
+
});
|
|
892
|
+
const steps = [];
|
|
893
|
+
steps.push(...[
|
|
894
|
+
{
|
|
895
|
+
queryId,
|
|
896
|
+
description: "tx send",
|
|
897
|
+
from: toAddress(params.senderAddress),
|
|
898
|
+
to: toAddress(senderWLPWalletAddress),
|
|
899
|
+
opcode: wallet_1.LFDedustJettonWallet.Op.ClaimRewards,
|
|
900
|
+
},
|
|
901
|
+
{
|
|
902
|
+
queryId,
|
|
903
|
+
description: "request claim to distributor",
|
|
904
|
+
from: toAddress(senderWLPWalletAddress),
|
|
905
|
+
to: toAddress(params.distributorAddress),
|
|
906
|
+
opcode: wallet_1.LFDedustJettonWallet.Op.DedustClaim,
|
|
907
|
+
},
|
|
908
|
+
{
|
|
909
|
+
queryId,
|
|
910
|
+
description: "Check claim eligibility.",
|
|
911
|
+
to: toAddress(params.distributorAddress),
|
|
912
|
+
opcode: 0x951c5d6b,
|
|
913
|
+
},
|
|
914
|
+
]);
|
|
915
|
+
if (params.rewardAssetAddress === "NATIVE") {
|
|
916
|
+
steps.push({
|
|
917
|
+
queryId,
|
|
918
|
+
description: "withdraw",
|
|
919
|
+
from: toAddress(params.distributorAddress),
|
|
920
|
+
opcode: jetton_wallet_1.JettonWallet.Op.Transfer,
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
else {
|
|
924
|
+
const wlpRewardAssetWalletAddress = await this.getJettonWalletAddress(toString(senderWLPWalletAddress), toString(params.rewardAssetAddress));
|
|
925
|
+
steps.push({
|
|
926
|
+
queryId,
|
|
927
|
+
description: "withdraw",
|
|
928
|
+
to: toAddress(wlpRewardAssetWalletAddress),
|
|
929
|
+
opcode: jetton_wallet_1.JettonWallet.Op.InternalTransfer,
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
(async () => {
|
|
933
|
+
const matchedTx0 = await this.findAndCallback(toAddress(params.senderAddress), steps[0], "0", callbackFn);
|
|
934
|
+
const matchedTx1 = await this.findAndCallback(toAddress(params.distributorAddress), steps[1], matchedTx0.lt.toString(), callbackFn);
|
|
935
|
+
const matchedTx2 = await this.findAndCallback(toAddress(params.distributorAddress), steps[2], matchedTx1.lt.toString(), callbackFn);
|
|
936
|
+
if (params.rewardAssetAddress === "NATIVE") {
|
|
937
|
+
const dedustVaultAddress = matchedTx2.outMessages[0]?.dst;
|
|
938
|
+
steps[3].to = dedustVaultAddress;
|
|
939
|
+
const matchedTx3 = await this.findAndCallback(toAddress(dedustVaultAddress), steps[3], matchedTx2.lt.toString(), callbackFn);
|
|
940
|
+
}
|
|
941
|
+
else {
|
|
942
|
+
const wlpRewardAssetWalletAddress = await this.getJettonWalletAddress(toString(senderWLPWalletAddress), toString(params.rewardAssetAddress));
|
|
943
|
+
const matchedTx3 = await this.findAndCallback(toAddress(wlpRewardAssetWalletAddress), steps[3], matchedTx2.lt.toString(), callbackFn);
|
|
944
|
+
}
|
|
945
|
+
})();
|
|
946
|
+
return steps;
|
|
947
|
+
}
|
|
948
|
+
async dedustClaimReward(sender, senderAddress, lfTokenAddress, distributorAddress, proof, gas) {
|
|
949
|
+
const senderJettonWalletAddress = await this.getJettonWalletAddress(toString(senderAddress), toString(lfTokenAddress));
|
|
950
|
+
const senderJettonWallet = this.client.open(wallet_1.LFDedustJettonWallet.createFromAddress(senderJettonWalletAddress));
|
|
951
|
+
await senderJettonWallet.sendClaimRewards(sender, {
|
|
952
|
+
value: gas || (0, ton_1.toNano)(0.3),
|
|
953
|
+
distributorAddress: toAddress(distributorAddress),
|
|
954
|
+
proof: proof,
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
async claimStonfiRewardAndWaitTx(sender, params, callbackFn) {
|
|
958
|
+
const senderWLPWalletAddress = await this.getJettonWalletAddress(toString(params.senderAddress), toString(params.wlpTokenAddress));
|
|
959
|
+
const stonfiWLPMinter = this.client.open(LFStonfiJettonMinter_1.LFStonfiJettonMinter.createFromAddress(toAddress(params.wlpTokenAddress)));
|
|
960
|
+
const wlpData = await stonfiWLPMinter.getWLPJettonData();
|
|
961
|
+
const senderWLPWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(senderWLPWalletAddress));
|
|
962
|
+
const queryId = generateRandomQueryId(params.senderAddress);
|
|
963
|
+
await senderWLPWallet.sendClaimRewards(sender, {
|
|
964
|
+
queryId,
|
|
965
|
+
value: params.gas || (0, ton_1.toNano)(0.5),
|
|
966
|
+
nftAddress: toAddress(params.nftAddress),
|
|
967
|
+
claimAll: true,
|
|
968
|
+
poolIndex: 0,
|
|
969
|
+
});
|
|
970
|
+
const steps = [];
|
|
971
|
+
steps.push(...[
|
|
972
|
+
{
|
|
973
|
+
queryId,
|
|
974
|
+
description: "tx send",
|
|
975
|
+
from: toAddress(params.senderAddress),
|
|
976
|
+
to: senderWLPWalletAddress,
|
|
977
|
+
opcode: LFStonfiJettonWallet_1.LFStonfiJettonWallet.Op.ClaimRewards,
|
|
978
|
+
},
|
|
979
|
+
{
|
|
980
|
+
queryId,
|
|
981
|
+
description: "request claim to nft",
|
|
982
|
+
from: senderWLPWalletAddress,
|
|
983
|
+
to: toAddress(params.nftAddress),
|
|
984
|
+
opcode: LFStonfiJettonWallet_1.LFStonfiJettonWallet.Op.ClaimRewards,
|
|
985
|
+
},
|
|
986
|
+
{
|
|
987
|
+
queryId,
|
|
988
|
+
description: "request claim to farm",
|
|
989
|
+
from: toAddress(params.nftAddress),
|
|
990
|
+
to: toAddress(wlpData.farmAddress),
|
|
991
|
+
opcode: 0x39656584,
|
|
992
|
+
},
|
|
993
|
+
{
|
|
994
|
+
queryId,
|
|
995
|
+
description: "claim",
|
|
996
|
+
from: toAddress(senderWLPWalletAddress),
|
|
997
|
+
to: toAddress(params.senderAddress),
|
|
998
|
+
opcode: jetton_wallet_1.JettonWallet.Op.Excesses,
|
|
999
|
+
},
|
|
1000
|
+
]);
|
|
1001
|
+
(async () => {
|
|
1002
|
+
const matchedTx0 = await this.findAndCallback(toAddress(params.senderAddress), steps[0], "0", callbackFn);
|
|
1003
|
+
const matchedTx1 = await this.findAndCallback(toAddress(params.nftAddress), steps[1], matchedTx0.lt.toString(), callbackFn);
|
|
1004
|
+
const matchedTx2 = await this.findAndCallback(wlpData.farmAddress, steps[2], matchedTx1.lt.toString(), callbackFn);
|
|
1005
|
+
const matchedTx3 = await this.findAndCallback(toAddress(params.senderAddress), steps[3], matchedTx2.lt.toString(), callbackFn);
|
|
1006
|
+
})();
|
|
1007
|
+
return steps;
|
|
1008
|
+
}
|
|
1009
|
+
async stonfiClaimReward(sender, senderAddress, lfTokenAddress, nftAddress, gas) {
|
|
1010
|
+
const senderJettonWalletAddress = await this.getJettonWalletAddress(toString(senderAddress), toString(lfTokenAddress));
|
|
1011
|
+
const senderJettonWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(senderJettonWalletAddress));
|
|
1012
|
+
await senderJettonWallet.sendClaimRewards(sender, {
|
|
1013
|
+
value: gas || (0, ton_1.toNano)(0.2),
|
|
1014
|
+
nftAddress: toAddress(nftAddress),
|
|
1015
|
+
claimAll: true,
|
|
1016
|
+
poolIndex: 0,
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
async stonfiFarm(sender, senderAddress, lfTokenAddress, amount, gas) {
|
|
1020
|
+
const senderJettonWalletAddress = await this.getJettonWalletAddress(toString(senderAddress), toString(lfTokenAddress));
|
|
1021
|
+
const senderJettonWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(senderJettonWalletAddress));
|
|
1022
|
+
await senderJettonWallet.sendFarm(sender, gas || (0, ton_1.toNano)(0.5), {
|
|
1023
|
+
amount,
|
|
1024
|
+
response: toAddress(senderAddress),
|
|
1025
|
+
forwardTonAmount: (0, ton_1.toNano)(0.35),
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
async stonfiUnfarm(sender, targetAddress, lfTokenAddress, nftAddress, gas) {
|
|
1029
|
+
const senderJettonWalletAddress = await this.getJettonWalletAddress(toString(targetAddress), toString(lfTokenAddress));
|
|
1030
|
+
const senderJettonWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(senderJettonWalletAddress));
|
|
1031
|
+
await senderJettonWallet.sendUnfarm(sender, gas || (0, ton_1.toNano)(0.4), {
|
|
1032
|
+
nftAddress: toAddress(nftAddress),
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
async findAndCallback(target, step, createdLt, callbackFn) {
|
|
1036
|
+
const matchedTx = await (0, tracker_1.findTx)(this.client, toAddress(target), createdLt.toString(), step);
|
|
1037
|
+
step.matchedTx = matchedTx;
|
|
1038
|
+
if (matchedTx.inMessage?.body) {
|
|
1039
|
+
const parsed = (0, parser_1.parseActionNotification)(matchedTx.inMessage.body);
|
|
1040
|
+
if (parsed) {
|
|
1041
|
+
step.actionNotificationResult = parsed;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
if (callbackFn)
|
|
1045
|
+
callbackFn(step);
|
|
1046
|
+
return matchedTx;
|
|
1047
|
+
}
|
|
1048
|
+
async stonfiSync(sender, targetAddress, lfTokenAddress, gas) {
|
|
1049
|
+
const targetJettonWalletAddress = await this.getJettonWalletAddress(toString(targetAddress), toString(lfTokenAddress));
|
|
1050
|
+
const targetJettonWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(targetJettonWalletAddress));
|
|
1051
|
+
await targetJettonWallet.sendSyncLockedAssetCash(sender, gas || (0, ton_1.toNano)(0.16), {});
|
|
1052
|
+
}
|
|
1053
|
+
async connectToPoolAccount(sender, targetAddress, lfTokenAddress, gas) {
|
|
1054
|
+
const targetJettonWalletAddress = await this.getJettonWalletAddress(toString(targetAddress), toString(lfTokenAddress));
|
|
1055
|
+
const targetJettonWallet = this.client.open(LFStonfiJettonWallet_1.LFStonfiJettonWallet.createFromAddress(targetJettonWalletAddress));
|
|
1056
|
+
await targetJettonWallet.sendConnectPoolAccount(sender, gas || (0, ton_1.toNano)(0.03));
|
|
1057
|
+
}
|
|
1058
|
+
async getStonfiFarmingData(nftAddress) {
|
|
1059
|
+
const result = await this.client
|
|
1060
|
+
.provider(toAddress(nftAddress))
|
|
1061
|
+
.get("get_farming_data", []);
|
|
1062
|
+
const status = result.stack.readNumber();
|
|
1063
|
+
const itemIndex = result.stack.readBigNumber();
|
|
1064
|
+
const stakedTokens = result.stack.readBigNumber();
|
|
1065
|
+
const stakedDate = result.stack.readBigNumber();
|
|
1066
|
+
const claimedPerUnitDict = result.stack.readCell();
|
|
1067
|
+
const ownerAddress = result.stack.readAddress();
|
|
1068
|
+
const statusMap = {
|
|
1069
|
+
0: "nft::status::uninitialized",
|
|
1070
|
+
1: "nft::status::active",
|
|
1071
|
+
2: "nft::status::unstaked",
|
|
1072
|
+
3: "nft::status::claiming",
|
|
1073
|
+
4: "nft::status::unstaked_pending",
|
|
1074
|
+
};
|
|
1075
|
+
return {
|
|
1076
|
+
address: nftAddress,
|
|
1077
|
+
status,
|
|
1078
|
+
statusString: statusMap[status],
|
|
1079
|
+
itemIndex,
|
|
1080
|
+
stakedTokens,
|
|
1081
|
+
stakedDate,
|
|
1082
|
+
claimedPerUnitDict,
|
|
1083
|
+
ownerAddress,
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
exports.PeripheryV1 = PeripheryV1;
|