@evaafi/sdk 0.6.2 → 0.6.3-a
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/README.md +2 -1
- package/dist/api/math.d.ts +12 -2
- package/dist/api/math.js +56 -4
- package/dist/api/parser.js +48 -20
- package/dist/constants/assets.d.ts +5 -1
- package/dist/constants/assets.js +24 -9
- package/dist/constants/general.d.ts +16 -0
- package/dist/constants/general.js +18 -2
- package/dist/constants/pools.d.ts +6 -1
- package/dist/constants/pools.js +46 -26
- package/dist/index.d.ts +10 -3
- package/dist/index.js +25 -2
- package/dist/prices/PricesCollector.d.ts +2 -2
- package/dist/prices/PricesCollector.js +8 -6
- package/dist/rewards/EvaaRewards.d.ts +10 -0
- package/dist/rewards/EvaaRewards.js +21 -0
- package/dist/rewards/JettonMinter.d.ts +30 -0
- package/dist/rewards/JettonMinter.js +83 -0
- package/dist/rewards/JettonWallet.d.ts +23 -0
- package/dist/rewards/JettonWallet.js +60 -0
- package/dist/rewards/RewardMaster.d.ts +26 -0
- package/dist/rewards/RewardMaster.js +83 -0
- package/dist/rewards/RewardUser.d.ts +23 -0
- package/dist/rewards/RewardUser.js +70 -0
- package/dist/types/MasterRewards.d.ts +13 -0
- package/dist/types/User.d.ts +11 -1
- package/dist/types/UserRewards.d.ts +10 -0
- package/dist/types/UserRewards.js +2 -0
- package/dist/utils/sha256BigInt.d.ts +2 -0
- package/dist/utils/sha256BigInt.js +9 -1
- package/dist/utils/userJettonWallet.js +7 -0
- package/package.json +42 -42
- package/src/api/math.ts +78 -3
- package/src/api/parser.ts +57 -22
- package/src/constants/assets.ts +91 -65
- package/src/constants/general.ts +30 -2
- package/src/constants/pools.ts +91 -28
- package/src/index.ts +23 -2
- package/src/prices/PricesCollector.ts +9 -5
- package/src/rewards/EvaaRewards.ts +23 -0
- package/src/rewards/JettonMinter.ts +113 -0
- package/src/rewards/JettonWallet.ts +77 -0
- package/src/rewards/RewardMaster.ts +110 -0
- package/src/rewards/RewardUser.ts +90 -0
- package/src/types/Master.ts +1 -1
- package/src/types/MasterRewards.ts +13 -0
- package/src/types/User.ts +13 -3
- package/src/types/UserRewards.ts +10 -0
- package/src/utils/sha256BigInt.ts +8 -0
- package/src/utils/userJettonWallet.ts +39 -33
- package/CHANGELOG.md +0 -240
- package/dist/config.d.ts +0 -1
- package/dist/config.js +0 -4
- package/dist/constants.d.ts +0 -69
- package/dist/constants.js +0 -83
- package/dist/types/Common.d.ts +0 -14
- package/dist/utils/priceUtils.d.ts +0 -55
- package/dist/utils/priceUtils.js +0 -117
- /package/dist/types/{Common.js → MasterRewards.js} +0 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Address, beginCell, Cell, Contract, contractAddress, ContractProvider, Sender, SendMode } from '@ton/ton';
|
|
2
|
+
import { OPCODES } from '../constants/general';
|
|
3
|
+
|
|
4
|
+
export type JettonMinterConfig = {
|
|
5
|
+
address: Address;
|
|
6
|
+
content: Cell;
|
|
7
|
+
walletCode: Cell;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type MintMessage = {
|
|
11
|
+
address: Address;
|
|
12
|
+
forwardValue: bigint;
|
|
13
|
+
amount: bigint;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export class JettonMinter implements Contract {
|
|
17
|
+
constructor(
|
|
18
|
+
readonly address: Address,
|
|
19
|
+
readonly init?: { code: Cell; data: Cell },
|
|
20
|
+
) {}
|
|
21
|
+
|
|
22
|
+
static createFromAddress(address: Address) {
|
|
23
|
+
return new JettonMinter(address);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static jettonMinterConfigToCell(config: JettonMinterConfig): Cell {
|
|
27
|
+
return beginCell()
|
|
28
|
+
.storeCoins(0)
|
|
29
|
+
.storeAddress(config.address)
|
|
30
|
+
.storeRef(config.content)
|
|
31
|
+
.storeRef(config.walletCode)
|
|
32
|
+
.endCell();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static createFromConfig(config: JettonMinterConfig, code: Cell, workchain = 0) {
|
|
36
|
+
const data = this.jettonMinterConfigToCell(config);
|
|
37
|
+
const init = { code, data };
|
|
38
|
+
return new JettonMinter(contractAddress(workchain, init), init);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async sendDeploy(provider: ContractProvider, via: Sender, value: bigint) {
|
|
42
|
+
await provider.internal(via, {
|
|
43
|
+
value,
|
|
44
|
+
sendMode: SendMode.PAY_GAS_SEPARATELY,
|
|
45
|
+
body: beginCell().endCell(),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
sendMintMessage(payload: MintMessage) {
|
|
50
|
+
return beginCell()
|
|
51
|
+
.storeUint(21, 32)
|
|
52
|
+
.storeUint(0, 64)
|
|
53
|
+
.storeAddress(payload.address)
|
|
54
|
+
.storeCoins(payload.forwardValue)
|
|
55
|
+
.storeRef(
|
|
56
|
+
beginCell()
|
|
57
|
+
.storeUint(OPCODES.REWARD_JETTON_MINT, 32)
|
|
58
|
+
.storeUint(0, 64)
|
|
59
|
+
.storeCoins(payload.amount)
|
|
60
|
+
.storeAddress(this.address)
|
|
61
|
+
.storeAddress(this.address)
|
|
62
|
+
.storeCoins(0)
|
|
63
|
+
.storeUint(0, 1)
|
|
64
|
+
.endCell(),
|
|
65
|
+
)
|
|
66
|
+
.endCell();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async sendMint(
|
|
70
|
+
provider: ContractProvider,
|
|
71
|
+
via: Sender,
|
|
72
|
+
value: bigint,
|
|
73
|
+
forwardValue: bigint,
|
|
74
|
+
recipient: Address,
|
|
75
|
+
amount: bigint,
|
|
76
|
+
) {
|
|
77
|
+
await provider.internal(via, {
|
|
78
|
+
sendMode: SendMode.PAY_GAS_SEPARATELY,
|
|
79
|
+
body: beginCell()
|
|
80
|
+
.storeUint(21, 32)
|
|
81
|
+
.storeUint(0, 64)
|
|
82
|
+
.storeAddress(recipient)
|
|
83
|
+
.storeCoins(forwardValue)
|
|
84
|
+
.storeRef(
|
|
85
|
+
beginCell()
|
|
86
|
+
.storeUint(OPCODES.REWARD_JETTON_MINT, 32)
|
|
87
|
+
.storeUint(0, 64)
|
|
88
|
+
.storeCoins(amount)
|
|
89
|
+
.storeAddress(this.address)
|
|
90
|
+
.storeAddress(this.address)
|
|
91
|
+
.storeCoins(0)
|
|
92
|
+
.storeUint(0, 1)
|
|
93
|
+
.endCell(),
|
|
94
|
+
)
|
|
95
|
+
.endCell(),
|
|
96
|
+
value: value + forwardValue,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async getWalletAddressOf(provider: ContractProvider, address: Address) {
|
|
101
|
+
return (
|
|
102
|
+
await provider.get('get_wallet_address', [
|
|
103
|
+
{ type: 'slice', cell: beginCell().storeAddress(address).endCell() },
|
|
104
|
+
])
|
|
105
|
+
).stack.readAddress();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async getWalletCode(provider: ContractProvider) {
|
|
109
|
+
let stack = (await provider.get('get_jetton_data', [])).stack;
|
|
110
|
+
stack.skip(4);
|
|
111
|
+
return stack.readCell();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Address, beginCell, Cell, Contract, contractAddress, ContractProvider, Sender, SendMode } from '@ton/ton';
|
|
2
|
+
import { OPCODES } from '../constants/general';
|
|
3
|
+
|
|
4
|
+
export type JettonWalletConfig = {
|
|
5
|
+
owner: Address;
|
|
6
|
+
minter: Address;
|
|
7
|
+
walletCode: Cell;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export class JettonWallet implements Contract {
|
|
11
|
+
constructor(
|
|
12
|
+
readonly address: Address,
|
|
13
|
+
readonly init?: { code: Cell; data: Cell },
|
|
14
|
+
) {}
|
|
15
|
+
|
|
16
|
+
static createFromAddress(address: Address) {
|
|
17
|
+
return new JettonWallet(address);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static jettonWalletConfigToCell(config: JettonWalletConfig): Cell {
|
|
21
|
+
return beginCell()
|
|
22
|
+
.storeCoins(0) // baseTrackingAccured always is 0, check smartcontract
|
|
23
|
+
.storeAddress(config.owner)
|
|
24
|
+
.storeAddress(config.minter)
|
|
25
|
+
.storeRef(config.walletCode)
|
|
26
|
+
.endCell();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static createFromConfig(config: JettonWalletConfig, code: Cell, workchain = 0) {
|
|
30
|
+
const data = this.jettonWalletConfigToCell(config);
|
|
31
|
+
const init = { code, data };
|
|
32
|
+
return new JettonWallet(contractAddress(workchain, init), init);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async sendDeploy(provider: ContractProvider, via: Sender, value: bigint) {
|
|
36
|
+
await provider.internal(via, {
|
|
37
|
+
value,
|
|
38
|
+
sendMode: SendMode.PAY_GAS_SEPARATELY,
|
|
39
|
+
body: beginCell().endCell(),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async sendTransfer(
|
|
44
|
+
provider: ContractProvider,
|
|
45
|
+
via: Sender,
|
|
46
|
+
value: bigint,
|
|
47
|
+
forwardValue: bigint,
|
|
48
|
+
recipient: Address,
|
|
49
|
+
amount: bigint,
|
|
50
|
+
forwardPayload: Cell,
|
|
51
|
+
) {
|
|
52
|
+
await provider.internal(via, {
|
|
53
|
+
sendMode: SendMode.PAY_GAS_SEPARATELY,
|
|
54
|
+
body: beginCell()
|
|
55
|
+
.storeUint(OPCODES.REWARD_JETTON_TRANSFER, 32)
|
|
56
|
+
.storeUint(0, 64)
|
|
57
|
+
.storeCoins(amount)
|
|
58
|
+
.storeAddress(recipient)
|
|
59
|
+
.storeAddress(via.address)
|
|
60
|
+
.storeUint(0, 1)
|
|
61
|
+
.storeCoins(forwardValue)
|
|
62
|
+
.storeUint(1, 1)
|
|
63
|
+
.storeRef(forwardPayload)
|
|
64
|
+
.endCell(),
|
|
65
|
+
value: value + forwardValue,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async getJettonBalance(provider: ContractProvider) {
|
|
70
|
+
let state = await provider.getState();
|
|
71
|
+
if (state.state.type !== 'active') {
|
|
72
|
+
return 0n;
|
|
73
|
+
}
|
|
74
|
+
let res = await provider.get('get_wallet_data', []);
|
|
75
|
+
return res.stack.readBigNumber();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Address,
|
|
3
|
+
beginCell,
|
|
4
|
+
Cell,
|
|
5
|
+
Contract,
|
|
6
|
+
contractAddress,
|
|
7
|
+
ContractProvider,
|
|
8
|
+
fromNano,
|
|
9
|
+
Sender,
|
|
10
|
+
SendMode,
|
|
11
|
+
StateInit,
|
|
12
|
+
toNano,
|
|
13
|
+
} from '@ton/ton';
|
|
14
|
+
import { Maybe } from '@ton/ton/dist/utils/maybe';
|
|
15
|
+
import { FEES, OPCODES } from '../constants/general';
|
|
16
|
+
import { EvaaRewardsConfig } from '../types/MasterRewards';
|
|
17
|
+
import { bigIntToBuffer } from '../utils/sha256BigInt';
|
|
18
|
+
|
|
19
|
+
export class RewardMaster implements Contract {
|
|
20
|
+
constructor(
|
|
21
|
+
readonly address: Address,
|
|
22
|
+
readonly init?: Maybe<StateInit>,
|
|
23
|
+
) {}
|
|
24
|
+
|
|
25
|
+
static createFromAddress(address: Address) {
|
|
26
|
+
return new RewardMaster(address);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static rewardMasterConfigToCell(config: EvaaRewardsConfig): Cell {
|
|
30
|
+
return beginCell()
|
|
31
|
+
.storeAddress(config.adminAddress)
|
|
32
|
+
.storeCoins(config.availableReward)
|
|
33
|
+
.storeAddress(null) // The addres null for TON
|
|
34
|
+
.storeRef(config.rewardUserCode)
|
|
35
|
+
.storeRef(
|
|
36
|
+
beginCell()
|
|
37
|
+
.storeAddress(config.evaaMasterAddress)
|
|
38
|
+
.storeBuffer(bigIntToBuffer(config.asset.assetId), 256 / 8)
|
|
39
|
+
.storeBuffer(config.publicKey, 256 / 8)
|
|
40
|
+
.endCell(),
|
|
41
|
+
)
|
|
42
|
+
.endCell();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static createFromConfig(config: EvaaRewardsConfig, workchain = 0) {
|
|
46
|
+
const data = this.rewardMasterConfigToCell(config);
|
|
47
|
+
const init = { code: config.rewardMasterCode, data };
|
|
48
|
+
return new RewardMaster(contractAddress(workchain, init), init);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async sendDeploy(provider: ContractProvider, via: Sender, rewardTokenJettonWalletAddress: Address | null) {
|
|
52
|
+
await provider.internal(via, {
|
|
53
|
+
value: FEES.REWARD_MASTER_DEPLOY,
|
|
54
|
+
sendMode: SendMode.PAY_GAS_SEPARATELY,
|
|
55
|
+
body: beginCell().storeUint(1, 32).storeUint(0, 64).storeAddress(rewardTokenJettonWalletAddress).endCell(),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async sendTonTopUp(provider: ContractProvider, via: Sender, topUpRewardAmount: number) {
|
|
60
|
+
await provider.internal(via, {
|
|
61
|
+
value: toNano(topUpRewardAmount) + FEES.REWARD_MASTER_TON_TOP_UP,
|
|
62
|
+
sendMode: SendMode.PAY_GAS_SEPARATELY,
|
|
63
|
+
body: beginCell().storeUint(OPCODES.REWARD_TON_TOP_UP, 32).storeUint(0, 64).endCell(),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private adminWithdrawMessage(destinationAddress: Address, jettonAmount: number) {
|
|
68
|
+
return beginCell()
|
|
69
|
+
.storeUint(4, 32)
|
|
70
|
+
.storeUint(0, 64)
|
|
71
|
+
.storeAddress(destinationAddress)
|
|
72
|
+
.storeCoins(toNano(jettonAmount))
|
|
73
|
+
.endCell();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async sendAdminWithdraw(
|
|
77
|
+
provider: ContractProvider,
|
|
78
|
+
via: Sender,
|
|
79
|
+
destinationAddress: Address,
|
|
80
|
+
jettonAmount: number,
|
|
81
|
+
) {
|
|
82
|
+
await provider.internal(via, {
|
|
83
|
+
value: FEES.REWARD_MASTER_WITHDRAW,
|
|
84
|
+
sendMode: SendMode.PAY_GAS_SEPARATELY,
|
|
85
|
+
body: this.adminWithdrawMessage(destinationAddress, jettonAmount),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async getData(provider: ContractProvider) {
|
|
90
|
+
const result = await provider.get('load_data', []);
|
|
91
|
+
const data = {
|
|
92
|
+
// TODO: maybe it will be typed
|
|
93
|
+
adminAddress: result.stack.readAddress(),
|
|
94
|
+
availableReward: Number(fromNano(result.stack.readBigNumber())),
|
|
95
|
+
rewardUserCode: result.stack.readCell(),
|
|
96
|
+
evaaMasterAddress: result.stack.readAddress(),
|
|
97
|
+
rewardTokenJettonWalletAddress: result.stack.readAddressOpt(),
|
|
98
|
+
assetId: Buffer.from(result.stack.readBigNumber().toString(16), 'hex'),
|
|
99
|
+
publicKey: Buffer.from(result.stack.readBigNumber().toString(16), 'hex'),
|
|
100
|
+
};
|
|
101
|
+
return data;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async getRewardUserAddress(provider: ContractProvider, userAddress: Address): Promise<Address> {
|
|
105
|
+
const result = await provider.get('calculate_reward_user_address', [
|
|
106
|
+
{ type: 'slice', cell: beginCell().storeAddress(userAddress).endCell() },
|
|
107
|
+
]);
|
|
108
|
+
return result.stack.readAddress();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { sign } from '@ton/crypto';
|
|
2
|
+
import {
|
|
3
|
+
Address,
|
|
4
|
+
beginCell,
|
|
5
|
+
Cell,
|
|
6
|
+
Contract,
|
|
7
|
+
contractAddress,
|
|
8
|
+
ContractProvider,
|
|
9
|
+
fromNano,
|
|
10
|
+
Sender,
|
|
11
|
+
SendMode,
|
|
12
|
+
StateInit,
|
|
13
|
+
} from '@ton/ton';
|
|
14
|
+
import { Maybe } from '@ton/ton/dist/utils/maybe';
|
|
15
|
+
import { FEES, OPCODES } from '../constants/general';
|
|
16
|
+
import { EvaaUserRewardsConfig } from '../types/UserRewards';
|
|
17
|
+
import { bigIntToBuffer } from '../utils/sha256BigInt';
|
|
18
|
+
|
|
19
|
+
export class RewardUser implements Contract {
|
|
20
|
+
constructor(
|
|
21
|
+
readonly address: Address,
|
|
22
|
+
readonly init?: Maybe<StateInit>,
|
|
23
|
+
) {}
|
|
24
|
+
|
|
25
|
+
static createFromAddress(address: Address) {
|
|
26
|
+
return new RewardUser(address);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static rewardUserConfigToCell(config: EvaaUserRewardsConfig): Cell {
|
|
30
|
+
return beginCell()
|
|
31
|
+
.storeAddress(config.userAddress)
|
|
32
|
+
.storeCoins(0)
|
|
33
|
+
.storeRef(
|
|
34
|
+
beginCell()
|
|
35
|
+
.storeAddress(config.rewardMasterAddress)
|
|
36
|
+
.storeBuffer(bigIntToBuffer(config.asset.assetId), 256 / 8)
|
|
37
|
+
.storeBuffer(config.publicKey, 256 / 8)
|
|
38
|
+
.endCell(),
|
|
39
|
+
)
|
|
40
|
+
.endCell();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static createFromConfig(config: EvaaUserRewardsConfig, workchain = 0) {
|
|
44
|
+
const data = this.rewardUserConfigToCell(config);
|
|
45
|
+
const init = { code: config.rewardUserCode, data };
|
|
46
|
+
return new RewardUser(contractAddress(workchain, init), init);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async sendDeploy(provider: ContractProvider, via: Sender) {
|
|
50
|
+
await provider.internal(via, {
|
|
51
|
+
value: FEES.REWARD_MASTER_DEPLOY,
|
|
52
|
+
sendMode: SendMode.PAY_GAS_SEPARATELY,
|
|
53
|
+
body: beginCell().endCell(),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
claimMessageToCell(claimAmount: bigint): Cell {
|
|
58
|
+
return beginCell().storeAddress(this.address).storeCoins(claimAmount).endCell();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
signClaimMessage(claimBody: Cell, privateKey: Buffer): Cell {
|
|
62
|
+
return beginCell()
|
|
63
|
+
.storeUint(OPCODES.REWARD_CLAIM, 32)
|
|
64
|
+
.storeUint(0, 64)
|
|
65
|
+
.storeBuffer(sign(claimBody.hash(), privateKey))
|
|
66
|
+
.storeRef(claimBody)
|
|
67
|
+
.endCell();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async sendClaim(provider: ContractProvider, via: Sender, signedClaimMessage: Cell) {
|
|
71
|
+
await provider.internal(via, {
|
|
72
|
+
value: FEES.REWARD_USER_CLAIM,
|
|
73
|
+
sendMode: SendMode.PAY_GAS_SEPARATELY,
|
|
74
|
+
body: signedClaimMessage,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async getData(provider: ContractProvider) {
|
|
79
|
+
const result = await provider.get('load_data', []);
|
|
80
|
+
// TODO: maybe it will be typed
|
|
81
|
+
const data = {
|
|
82
|
+
userAddress: result.stack.readAddress(),
|
|
83
|
+
baseTrackingAccrued: Number(fromNano(result.stack.readBigNumber())),
|
|
84
|
+
rewardMasterAddress: result.stack.readAddress(),
|
|
85
|
+
assetId: Buffer.from(result.stack.readBigNumber().toString(16), 'hex'),
|
|
86
|
+
publicKey: Buffer.from(result.stack.readBigNumber().toString(16), 'hex'),
|
|
87
|
+
};
|
|
88
|
+
return data;
|
|
89
|
+
}
|
|
90
|
+
}
|
package/src/types/Master.ts
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Address, Cell } from '@ton/ton';
|
|
2
|
+
import { PoolAssetConfig } from './Master';
|
|
3
|
+
|
|
4
|
+
export type EvaaRewardsConfig = {
|
|
5
|
+
workchain?: number;
|
|
6
|
+
adminAddress: Address;
|
|
7
|
+
evaaMasterAddress: Address;
|
|
8
|
+
availableReward: number;
|
|
9
|
+
asset: PoolAssetConfig;
|
|
10
|
+
rewardMasterCode: Cell;
|
|
11
|
+
rewardUserCode: Cell;
|
|
12
|
+
publicKey: Buffer;
|
|
13
|
+
};
|
package/src/types/User.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Address, Cell, Dictionary } from '@ton/core';
|
|
2
|
-
import { AssetConfig, ExtendedAssetData, ExtendedAssetsConfig, ExtendedAssetsData, MasterConfig, MasterConstants, PoolAssetConfig, PoolConfig } from './Master';
|
|
1
|
+
import { Address, BitBuilder, Cell, Dictionary } from '@ton/core';
|
|
2
|
+
import { AssetConfig, AssetData, ExtendedAssetData, ExtendedAssetsConfig, ExtendedAssetsData, MasterConfig, MasterConstants, PoolAssetConfig, PoolConfig } from './Master';
|
|
3
3
|
|
|
4
4
|
export enum BalanceType {
|
|
5
5
|
supply = 'supply',
|
|
@@ -38,6 +38,7 @@ export type UserLiteData = {
|
|
|
38
38
|
masterAddress: Address;
|
|
39
39
|
ownerAddress: Address;
|
|
40
40
|
principals: Dictionary<bigint, bigint>;
|
|
41
|
+
realPrincipals: Dictionary<bigint, bigint>; // principals before applying dusts
|
|
41
42
|
state: number;
|
|
42
43
|
balances: Dictionary<bigint, UserBalance>;
|
|
43
44
|
trackingSupplyIndex: bigint;
|
|
@@ -47,6 +48,7 @@ export type UserLiteData = {
|
|
|
47
48
|
rewards: Dictionary<bigint, UserRewards>;
|
|
48
49
|
backupCell1: Cell | null;
|
|
49
50
|
backupCell2: Cell | null;
|
|
51
|
+
fullyParsed: boolean;
|
|
50
52
|
};
|
|
51
53
|
|
|
52
54
|
export type UserDataActive = UserLiteData & {
|
|
@@ -59,8 +61,8 @@ export type UserDataActive = UserLiteData & {
|
|
|
59
61
|
limitUsedPercent: number;
|
|
60
62
|
limitUsed: bigint;
|
|
61
63
|
healthFactor: number;
|
|
62
|
-
|
|
63
64
|
liquidationData: LiquidationData;
|
|
65
|
+
havePrincipalWithoutPrice: boolean;
|
|
64
66
|
};
|
|
65
67
|
|
|
66
68
|
export type UserDataInactive = {
|
|
@@ -99,3 +101,11 @@ export type PredictHealthFactorArgs = {
|
|
|
99
101
|
assetsConfig: ExtendedAssetsConfig;
|
|
100
102
|
poolConfig: PoolConfig;
|
|
101
103
|
};
|
|
104
|
+
|
|
105
|
+
export type PredictAPYArgs = {
|
|
106
|
+
balanceChangeType: BalanceChangeType;
|
|
107
|
+
amount: bigint; // always positive
|
|
108
|
+
assetData: AssetData;
|
|
109
|
+
assetConfig: AssetConfig;
|
|
110
|
+
masterConstants: MasterConstants;
|
|
111
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Address, Cell } from '@ton/ton';
|
|
2
|
+
import { PoolAssetConfig } from './Master';
|
|
3
|
+
|
|
4
|
+
export type EvaaUserRewardsConfig = {
|
|
5
|
+
userAddress: Address;
|
|
6
|
+
rewardUserCode: Cell;
|
|
7
|
+
rewardMasterAddress: Address;
|
|
8
|
+
asset: PoolAssetConfig;
|
|
9
|
+
publicKey: Buffer;
|
|
10
|
+
};
|
|
@@ -5,3 +5,11 @@ export function sha256Hash(input: string): bigint {
|
|
|
5
5
|
const hashHex = hash.toString();
|
|
6
6
|
return BigInt('0x' + hashHex);
|
|
7
7
|
}
|
|
8
|
+
|
|
9
|
+
export function bigIntToBuffer(value: bigint): Buffer {
|
|
10
|
+
let hex = value.toString(16);
|
|
11
|
+
if (hex.length % 2) {
|
|
12
|
+
hex = '0' + hex;
|
|
13
|
+
}
|
|
14
|
+
return Buffer.from(hex, 'hex');
|
|
15
|
+
}
|
|
@@ -4,39 +4,45 @@ import { UNDEFINED_ASSET } from '../constants/assets';
|
|
|
4
4
|
|
|
5
5
|
function getUserJettonData(ownerAddress: Address, assetName: string, jettonWalletCode: Cell, jettonMasterAddress: Address) {
|
|
6
6
|
switch (assetName) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
7
|
+
case 'uTON':
|
|
8
|
+
return beginCell()
|
|
9
|
+
.storeCoins(0)
|
|
10
|
+
.storeUint(0, 64)
|
|
11
|
+
.storeAddress(ownerAddress)
|
|
12
|
+
.storeAddress(jettonMasterAddress)
|
|
13
|
+
.storeRef(jettonWalletCode)
|
|
14
|
+
.endCell();
|
|
15
|
+
case 'DOGS':
|
|
16
|
+
case 'NOT':
|
|
17
|
+
case 'USDT':
|
|
18
|
+
return beginCell()
|
|
19
|
+
.storeUint(0, 4)
|
|
20
|
+
.storeCoins(0)
|
|
21
|
+
.storeAddress(ownerAddress)
|
|
22
|
+
.storeAddress(jettonMasterAddress)
|
|
23
|
+
.endCell();
|
|
24
|
+
case 'tsTON':
|
|
25
|
+
return beginCell()
|
|
26
|
+
.storeCoins(0)
|
|
27
|
+
.storeAddress(ownerAddress)
|
|
28
|
+
.storeAddress(jettonMasterAddress)
|
|
29
|
+
.storeRef(jettonWalletCode)
|
|
30
|
+
.storeCoins(0)
|
|
31
|
+
.storeUint(0, 48)
|
|
32
|
+
.endCell();
|
|
33
|
+
case 'tgBTC':
|
|
34
|
+
return beginCell()
|
|
35
|
+
.storeUint(0, 4)
|
|
36
|
+
.storeCoins(0)
|
|
37
|
+
.storeAddress(ownerAddress)
|
|
38
|
+
.storeAddress(jettonMasterAddress)
|
|
39
|
+
.endCell();
|
|
40
|
+
default:
|
|
41
|
+
return beginCell().storeCoins(0)
|
|
42
|
+
.storeAddress(ownerAddress)
|
|
43
|
+
.storeAddress(jettonMasterAddress)
|
|
44
|
+
.storeRef(jettonWalletCode)
|
|
45
|
+
.endCell();
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
48
|
export function getUserJettonWallet(ownerAddress: Address, poolAssetConfig: PoolAssetConfig) {
|