@affluent-org/sdk 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +11 -0
- package/Refactoring.md +548 -0
- package/dist/_compiled/Account.compiled.json +1 -0
- package/dist/_compiled/Receipt.compiled.json +1 -0
- package/dist/_compiled/WTONWallet.compiled.json +1 -0
- package/dist/_compiled/index.d.ts +4 -0
- package/dist/_compiled/index.js +12 -0
- package/dist/affluent.d.ts +14 -0
- package/dist/affluent.js +20 -0
- package/dist/constants/constants.d.ts +2 -0
- package/dist/constants/constants.js +5 -0
- package/dist/constants/contracts.d.ts +9 -0
- package/dist/constants/contracts.js +18 -0
- package/dist/context.d.ts +43 -0
- package/dist/context.js +90 -0
- package/dist/contracts/common/type.d.ts +16 -0
- package/dist/contracts/common/type.js +2 -0
- package/dist/contracts/common/utils.d.ts +3 -0
- package/dist/contracts/common/utils.js +16 -0
- package/dist/contracts/core/account/index.d.ts +38 -0
- package/dist/contracts/core/account/index.js +128 -0
- package/dist/contracts/core/account/type.d.ts +18 -0
- package/dist/contracts/core/account/type.js +2 -0
- package/dist/contracts/core/pool/index.d.ts +149 -0
- package/dist/contracts/core/pool/index.js +379 -0
- package/dist/contracts/core/pool/serializer.d.ts +15 -0
- package/dist/contracts/core/pool/serializer.js +307 -0
- package/dist/contracts/core/pool/type.d.ts +136 -0
- package/dist/contracts/core/pool/type.js +2 -0
- package/dist/contracts/dedust-farm/MockDedustFarm.d.ts +41 -0
- package/dist/contracts/dedust-farm/MockDedustFarm.js +79 -0
- package/dist/contracts/external/tonstaker.d.ts +18 -0
- package/dist/contracts/external/tonstaker.js +26 -0
- package/dist/contracts/factory/factory.d.ts +24 -0
- package/dist/contracts/factory/factory.js +58 -0
- package/dist/contracts/factory/type.d.ts +11 -0
- package/dist/contracts/factory/type.js +2 -0
- package/dist/contracts/farm/distributor.d.ts +43 -0
- package/dist/contracts/farm/distributor.js +83 -0
- package/dist/contracts/farm/receipt.d.ts +40 -0
- package/dist/contracts/farm/receipt.js +68 -0
- package/dist/contracts/irm/jump-irm/serializer.d.ts +4 -0
- package/dist/contracts/irm/jump-irm/serializer.js +26 -0
- package/dist/contracts/irm/jump-irm/type.d.ts +8 -0
- package/dist/contracts/irm/jump-irm/type.js +2 -0
- package/dist/contracts/jetton/jetton-minter.d.ts +23 -0
- package/dist/contracts/jetton/jetton-minter.js +46 -0
- package/dist/contracts/jetton/jetton-wallet.d.ts +67 -0
- package/dist/contracts/jetton/jetton-wallet.js +119 -0
- package/dist/contracts/jetton/type.d.ts +7 -0
- package/dist/contracts/jetton/type.js +2 -0
- package/dist/contracts/liquid_token/dedust/minter.d.ts +56 -0
- package/dist/contracts/liquid_token/dedust/minter.js +112 -0
- package/dist/contracts/liquid_token/dedust/wallet.d.ts +127 -0
- package/dist/contracts/liquid_token/dedust/wallet.js +213 -0
- package/dist/contracts/liquid_token/stonfi/LFStonfiJettonMinter.d.ts +53 -0
- package/dist/contracts/liquid_token/stonfi/LFStonfiJettonMinter.js +110 -0
- package/dist/contracts/liquid_token/stonfi/LFStonfiJettonWallet.d.ts +169 -0
- package/dist/contracts/liquid_token/stonfi/LFStonfiJettonWallet.js +288 -0
- package/dist/contracts/oracle/composite-onchain-oracle/index.d.ts +108 -0
- package/dist/contracts/oracle/composite-onchain-oracle/index.js +185 -0
- package/dist/contracts/oracle/parser.d.ts +7 -0
- package/dist/contracts/oracle/parser.js +77 -0
- package/dist/contracts/oracle/redstone-onchain-oracle/index.d.ts +56 -0
- package/dist/contracts/oracle/redstone-onchain-oracle/index.js +159 -0
- package/dist/contracts/oracle/redstone-onchain-oracle/serializer.d.ts +4 -0
- package/dist/contracts/oracle/redstone-onchain-oracle/serializer.js +137 -0
- package/dist/contracts/oracle/redstone-onchain-oracle/type.d.ts +57 -0
- package/dist/contracts/oracle/redstone-onchain-oracle/type.js +18 -0
- package/dist/contracts/oracle/redstone-oracle/serializer.d.ts +3 -0
- package/dist/contracts/oracle/redstone-oracle/serializer.js +30 -0
- package/dist/contracts/oracle/redstone-oracle/type.d.ts +9 -0
- package/dist/contracts/oracle/redstone-oracle/type.js +2 -0
- package/dist/contracts/oracle/redstone-parser.d.ts +9 -0
- package/dist/contracts/oracle/redstone-parser.js +58 -0
- package/dist/contracts/rfq/rfq_auction/index.d.ts +216 -0
- package/dist/contracts/rfq/rfq_auction/index.js +334 -0
- package/dist/contracts/rfq/rfq_batch/index.d.ts +346 -0
- package/dist/contracts/rfq/rfq_batch/index.js +448 -0
- package/dist/contracts/rfq/rfq_event_emitter/index.d.ts +132 -0
- package/dist/contracts/rfq/rfq_event_emitter/index.js +143 -0
- package/dist/contracts/stonfi-farm/MockStonfiFarmItem.d.ts +41 -0
- package/dist/contracts/stonfi-farm/MockStonfiFarmItem.js +83 -0
- package/dist/contracts/stonfi-farm/MockStonfiFarmMinter.d.ts +45 -0
- package/dist/contracts/stonfi-farm/MockStonfiFarmMinter.js +92 -0
- package/dist/contracts/unknown-contract/index.d.ts +14 -0
- package/dist/contracts/unknown-contract/index.js +18 -0
- package/dist/contracts/vault/share-vault/index.d.ts +206 -0
- package/dist/contracts/vault/share-vault/index.js +373 -0
- package/dist/contracts/vault/strategy-vault/codec.d.ts +710 -0
- package/dist/contracts/vault/strategy-vault/codec.js +1256 -0
- package/dist/contracts/vault/strategy-vault/computation.d.ts +11 -0
- package/dist/contracts/vault/strategy-vault/computation.js +56 -0
- package/dist/contracts/vault/strategy-vault/constants.d.ts +163 -0
- package/dist/contracts/vault/strategy-vault/constants.js +170 -0
- package/dist/contracts/vault/strategy-vault/index.d.ts +587 -0
- package/dist/contracts/vault/strategy-vault/index.js +406 -0
- package/dist/contracts/vault/strategy-vault/type.d.ts +115 -0
- package/dist/contracts/vault/strategy-vault/type.js +2 -0
- package/dist/contracts/wton/jetton-minter.d.ts +35 -0
- package/dist/contracts/wton/jetton-minter.js +71 -0
- package/dist/contracts/wton/jetton-wallet.d.ts +90 -0
- package/dist/contracts/wton/jetton-wallet.js +153 -0
- package/dist/contracts/wton/type.d.ts +7 -0
- package/dist/contracts/wton/type.js +2 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +65 -0
- package/dist/lib/assert.d.ts +1 -0
- package/dist/lib/assert.js +9 -0
- package/dist/lib/query-cache.d.ts +5 -0
- package/dist/lib/query-cache.js +57 -0
- package/dist/lib/send-msg.d.ts +11 -0
- package/dist/lib/send-msg.js +9 -0
- package/dist/services/composite-oracle/computation.d.ts +55 -0
- package/dist/services/composite-oracle/computation.js +295 -0
- package/dist/services/composite-oracle/index.d.ts +45 -0
- package/dist/services/composite-oracle/index.js +110 -0
- package/dist/services/composite-oracle/query.d.ts +36 -0
- package/dist/services/composite-oracle/query.js +251 -0
- package/dist/services/composite-oracle/types.d.ts +82 -0
- package/dist/services/composite-oracle/types.js +11 -0
- package/dist/services/pool/computation.d.ts +75 -0
- package/dist/services/pool/computation.js +219 -0
- package/dist/services/pool/index.d.ts +94 -0
- package/dist/services/pool/index.js +139 -0
- package/dist/services/pool/oracle.d.ts +20 -0
- package/dist/services/pool/oracle.js +61 -0
- package/dist/services/pool/owner/index.d.ts +37 -0
- package/dist/services/pool/owner/index.js +76 -0
- package/dist/services/pool/owner/types.d.ts +18 -0
- package/dist/services/pool/owner/types.js +2 -0
- package/dist/services/pool/query.d.ts +64 -0
- package/dist/services/pool/query.js +282 -0
- package/dist/services/pool/user/index.d.ts +86 -0
- package/dist/services/pool/user/index.js +285 -0
- package/dist/services/pool/user/types.d.ts +44 -0
- package/dist/services/pool/user/types.js +2 -0
- package/dist/services/rfq-auction/index.d.ts +81 -0
- package/dist/services/rfq-auction/index.js +93 -0
- package/dist/services/rfq-auction/oracle.d.ts +19 -0
- package/dist/services/rfq-auction/oracle.js +60 -0
- package/dist/services/rfq-auction/query.d.ts +50 -0
- package/dist/services/rfq-auction/query.js +19 -0
- package/dist/services/rfq-auction/user/index.d.ts +63 -0
- package/dist/services/rfq-auction/user/index.js +218 -0
- package/dist/services/rfq-auction/user/types.d.ts +29 -0
- package/dist/services/rfq-auction/user/types.js +2 -0
- package/dist/services/rfq-batch/index.d.ts +78 -0
- package/dist/services/rfq-batch/index.js +132 -0
- package/dist/services/rfq-batch/oracle.d.ts +22 -0
- package/dist/services/rfq-batch/oracle.js +54 -0
- package/dist/services/rfq-batch/query.d.ts +46 -0
- package/dist/services/rfq-batch/query.js +34 -0
- package/dist/services/rfq-batch/user/index.d.ts +79 -0
- package/dist/services/rfq-batch/user/index.js +171 -0
- package/dist/services/rfq-batch/user/types.d.ts +37 -0
- package/dist/services/rfq-batch/user/types.js +2 -0
- package/dist/services/share-vault/computation.d.ts +24 -0
- package/dist/services/share-vault/computation.js +42 -0
- package/dist/services/share-vault/index.d.ts +90 -0
- package/dist/services/share-vault/index.js +128 -0
- package/dist/services/share-vault/manager/index.d.ts +40 -0
- package/dist/services/share-vault/manager/index.js +111 -0
- package/dist/services/share-vault/manager/types.d.ts +23 -0
- package/dist/services/share-vault/manager/types.js +2 -0
- package/dist/services/share-vault/owner/index.d.ts +64 -0
- package/dist/services/share-vault/owner/index.js +122 -0
- package/dist/services/share-vault/owner/types.d.ts +33 -0
- package/dist/services/share-vault/owner/types.js +2 -0
- package/dist/services/share-vault/query.d.ts +34 -0
- package/dist/services/share-vault/query.js +138 -0
- package/dist/services/share-vault/user/index.d.ts +33 -0
- package/dist/services/share-vault/user/index.js +106 -0
- package/dist/services/share-vault/user/types.d.ts +13 -0
- package/dist/services/share-vault/user/types.js +2 -0
- package/dist/services/strategy-vault/index.d.ts +2124 -0
- package/dist/services/strategy-vault/index.js +268 -0
- package/dist/services/strategy-vault/manager/index.d.ts +1968 -0
- package/dist/services/strategy-vault/manager/index.js +475 -0
- package/dist/services/strategy-vault/manager/types.d.ts +144 -0
- package/dist/services/strategy-vault/manager/types.js +2 -0
- package/dist/services/strategy-vault/oracle.d.ts +66 -0
- package/dist/services/strategy-vault/oracle.js +162 -0
- package/dist/services/strategy-vault/owner/index.d.ts +277 -0
- package/dist/services/strategy-vault/owner/index.js +333 -0
- package/dist/services/strategy-vault/owner/types.d.ts +146 -0
- package/dist/services/strategy-vault/owner/types.js +2 -0
- package/dist/services/strategy-vault/query.d.ts +138 -0
- package/dist/services/strategy-vault/query.js +59 -0
- package/dist/services/strategy-vault/user/index.d.ts +89 -0
- package/dist/services/strategy-vault/user/index.js +219 -0
- package/dist/services/strategy-vault/user/types.d.ts +46 -0
- package/dist/services/strategy-vault/user/types.js +2 -0
- package/dist/types/sender.d.ts +7 -0
- package/dist/types/sender.js +2 -0
- package/dist/utils/action-parser.d.ts +7 -0
- package/dist/utils/action-parser.js +20 -0
- package/dist/utils/external-message-hash.d.ts +45 -0
- package/dist/utils/external-message-hash.js +65 -0
- package/dist/utils/oracle/redstone/readonlyCachedRedstone.d.ts +3 -0
- package/dist/utils/oracle/redstone/readonlyCachedRedstone.js +25 -0
- package/dist/utils/oracle/redstone/redstoneHelper.d.ts +21 -0
- package/dist/utils/oracle/redstone/redstoneHelper.js +228 -0
- package/dist/utils/parser.d.ts +40 -0
- package/dist/utils/parser.js +580 -0
- package/dist/utils/pending-tracker/index.d.ts +14 -0
- package/dist/utils/pending-tracker/index.js +34 -0
- package/dist/utils/pending-tracker/trackable-sender.d.ts +16 -0
- package/dist/utils/pending-tracker/trackable-sender.js +87 -0
- package/dist/utils/pending-tracker/type.d.ts +78 -0
- package/dist/utils/pending-tracker/type.js +2 -0
- package/dist/utils/pending-tracker/v3-client.d.ts +31 -0
- package/dist/utils/pending-tracker/v3-client.js +104 -0
- package/dist/utils/risk_calculator/risk_calculator.d.ts +45 -0
- package/dist/utils/risk_calculator/risk_calculator.js +332 -0
- package/dist/utils/utils.d.ts +5 -0
- package/dist/utils/utils.js +12 -0
- package/package.json +46 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Address, Cell, Contract, ContractProvider, Sender, Slice } from "@ton/core";
|
|
2
|
+
import { RedstoneOnchainOracleConfig } from "./type";
|
|
3
|
+
export type InitRedstoneOnchainOracleConfig = {
|
|
4
|
+
owner: Address;
|
|
5
|
+
reserveAggregatorCode: Cell;
|
|
6
|
+
};
|
|
7
|
+
export declare function redstonOnchainOracleConfigToCell(config: InitRedstoneOnchainOracleConfig): Cell;
|
|
8
|
+
export declare class RedstoneOnchainOracle implements Contract {
|
|
9
|
+
readonly address: Address;
|
|
10
|
+
readonly init?: {
|
|
11
|
+
code: Cell;
|
|
12
|
+
data: Cell;
|
|
13
|
+
} | undefined;
|
|
14
|
+
constructor(address: Address, init?: {
|
|
15
|
+
code: Cell;
|
|
16
|
+
data: Cell;
|
|
17
|
+
} | undefined);
|
|
18
|
+
static AssetType: {
|
|
19
|
+
currency: number;
|
|
20
|
+
synthetic1: number;
|
|
21
|
+
synthetic2: number;
|
|
22
|
+
};
|
|
23
|
+
static SourceType: {
|
|
24
|
+
internal: number;
|
|
25
|
+
tonstakers: number;
|
|
26
|
+
stonfi: number;
|
|
27
|
+
dedust: number;
|
|
28
|
+
storm: number;
|
|
29
|
+
tradoor: number;
|
|
30
|
+
};
|
|
31
|
+
static Op: {
|
|
32
|
+
ProvideOraclePrice: number;
|
|
33
|
+
TakeOraclePrice: number;
|
|
34
|
+
};
|
|
35
|
+
static createFromAddress(address: Address): RedstoneOnchainOracle;
|
|
36
|
+
static createFromConfig(config: InitRedstoneOnchainOracleConfig, code: Cell, workchain?: number): RedstoneOnchainOracle;
|
|
37
|
+
sendDeploy(provider: ContractProvider, via: Sender, value: bigint): Promise<void>;
|
|
38
|
+
static createAddressToTupleCell(whitelists: Address[]): Cell;
|
|
39
|
+
sendProvideOraclePrice(provider: ContractProvider, via: Sender, opts: {
|
|
40
|
+
value: bigint;
|
|
41
|
+
oracleConfig: Cell;
|
|
42
|
+
oracleParams: Cell;
|
|
43
|
+
forwardPayload?: Slice;
|
|
44
|
+
queryID?: bigint;
|
|
45
|
+
}): Promise<void>;
|
|
46
|
+
getState(provider: ContractProvider): Promise<import("@ton/core").ContractState>;
|
|
47
|
+
getOwner(provider: ContractProvider): Promise<{
|
|
48
|
+
owner: Address | null;
|
|
49
|
+
}>;
|
|
50
|
+
static getOracleRequestParams(assets: string[] | Address[], config: RedstoneOnchainOracleConfig): {
|
|
51
|
+
feedIds: bigint[];
|
|
52
|
+
redstoneAssetNames: any[];
|
|
53
|
+
requestAssets: Address[];
|
|
54
|
+
redstoneAssets: Address[];
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RedstoneOnchainOracle = void 0;
|
|
4
|
+
exports.redstonOnchainOracleConfigToCell = redstonOnchainOracleConfigToCell;
|
|
5
|
+
const core_1 = require("@ton/core");
|
|
6
|
+
const NAME_MAP = {
|
|
7
|
+
"5525326": "TON",
|
|
8
|
+
"1431520340": "USDT",
|
|
9
|
+
"39287100404874731933245616043935197839692": "stTON_FUNDAMENTAL",
|
|
10
|
+
"39626053543799885480836086844306685706572": "tsTON_FUNDAMENTAL",
|
|
11
|
+
"1431520357": "USDe",
|
|
12
|
+
"10144271057007612894112390016889590732046668": "tsUSDe_FUNDAMENTAL",
|
|
13
|
+
"5783893": "XAU",
|
|
14
|
+
"4346947": "BTC",
|
|
15
|
+
"495352759397": "sUSDe",
|
|
16
|
+
};
|
|
17
|
+
function redstonOnchainOracleConfigToCell(config) {
|
|
18
|
+
return (0, core_1.beginCell)().storeCoins(0).storeAddress(config.owner).storeRef(config.reserveAggregatorCode).endCell();
|
|
19
|
+
}
|
|
20
|
+
class RedstoneOnchainOracle {
|
|
21
|
+
address;
|
|
22
|
+
init;
|
|
23
|
+
constructor(address, init) {
|
|
24
|
+
this.address = address;
|
|
25
|
+
this.init = init;
|
|
26
|
+
}
|
|
27
|
+
static AssetType = {
|
|
28
|
+
currency: 0,
|
|
29
|
+
synthetic1: 1,
|
|
30
|
+
synthetic2: 2,
|
|
31
|
+
};
|
|
32
|
+
static SourceType = {
|
|
33
|
+
internal: 0,
|
|
34
|
+
tonstakers: 1,
|
|
35
|
+
stonfi: 2,
|
|
36
|
+
dedust: 3,
|
|
37
|
+
storm: 4,
|
|
38
|
+
tradoor: 5,
|
|
39
|
+
};
|
|
40
|
+
static Op = {
|
|
41
|
+
ProvideOraclePrice: 0x262964ae,
|
|
42
|
+
TakeOraclePrice: 0xba2968fa,
|
|
43
|
+
};
|
|
44
|
+
static createFromAddress(address) {
|
|
45
|
+
return new RedstoneOnchainOracle(address);
|
|
46
|
+
}
|
|
47
|
+
static createFromConfig(config, code, workchain = 0) {
|
|
48
|
+
const data = redstonOnchainOracleConfigToCell(config);
|
|
49
|
+
const init = { code, data };
|
|
50
|
+
return new RedstoneOnchainOracle((0, core_1.contractAddress)(workchain, init), init);
|
|
51
|
+
}
|
|
52
|
+
async sendDeploy(provider, via, value) {
|
|
53
|
+
await provider.internal(via, {
|
|
54
|
+
value,
|
|
55
|
+
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY,
|
|
56
|
+
body: (0, core_1.beginCell)().endCell(),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
static createAddressToTupleCell(whitelists) {
|
|
60
|
+
if (whitelists.length === 0) {
|
|
61
|
+
return (0, core_1.beginCell)().storeUint(0, 2).endCell();
|
|
62
|
+
}
|
|
63
|
+
const chunkedWhitelists = [];
|
|
64
|
+
for (let i = 0; i < whitelists.length; i += 3) {
|
|
65
|
+
chunkedWhitelists.push(whitelists.slice(i, i + 3));
|
|
66
|
+
}
|
|
67
|
+
const cells = chunkedWhitelists.map((chunk) => {
|
|
68
|
+
let cell = (0, core_1.beginCell)();
|
|
69
|
+
cell = cell.storeUint(chunk.length, 2);
|
|
70
|
+
chunk.forEach((address) => {
|
|
71
|
+
cell = cell.storeAddress(address);
|
|
72
|
+
});
|
|
73
|
+
return cell;
|
|
74
|
+
});
|
|
75
|
+
const finalCell = cells.reduce((acc, cur) => {
|
|
76
|
+
return acc ? cur.storeRef(acc) : cur;
|
|
77
|
+
}, null);
|
|
78
|
+
return finalCell?.endCell() || (0, core_1.beginCell)().storeUint(0, 2).endCell();
|
|
79
|
+
}
|
|
80
|
+
async sendProvideOraclePrice(provider, via, opts) {
|
|
81
|
+
let body = (0, core_1.beginCell)()
|
|
82
|
+
.storeUint(RedstoneOnchainOracle.Op.ProvideOraclePrice, 32)
|
|
83
|
+
.storeUint(opts.queryID ?? 0, 64)
|
|
84
|
+
.storeRef((0, core_1.beginCell)().storeRef(opts.oracleConfig).storeRef(opts.oracleParams).endCell());
|
|
85
|
+
if (opts.forwardPayload) {
|
|
86
|
+
body = body.storeSlice(opts.forwardPayload);
|
|
87
|
+
}
|
|
88
|
+
await provider.internal(via, {
|
|
89
|
+
value: opts.value,
|
|
90
|
+
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY,
|
|
91
|
+
body: body.endCell(),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async getState(provider) {
|
|
95
|
+
return await provider.getState();
|
|
96
|
+
}
|
|
97
|
+
async getOwner(provider) {
|
|
98
|
+
const result = await provider.get("get_owner", []);
|
|
99
|
+
const owner = result.stack.readAddressOpt();
|
|
100
|
+
return {
|
|
101
|
+
owner,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
static getOracleRequestParams(assets, config) {
|
|
105
|
+
const redstoneFeedIds = [];
|
|
106
|
+
const _redstoneAssets = new Set();
|
|
107
|
+
const _requestAssets = [];
|
|
108
|
+
const redstoneAssetsMap = Object.entries(config.redstoneAssetInfo).reduce((acc, [feedId, info]) => {
|
|
109
|
+
return { ...acc, [info.address.toString()]: feedId };
|
|
110
|
+
}, {});
|
|
111
|
+
while (assets.length != 0) {
|
|
112
|
+
const newAssets = [];
|
|
113
|
+
for (let asset of assets) {
|
|
114
|
+
asset = asset.toString();
|
|
115
|
+
if (!config.assetOnchainDataInfo[asset] && !redstoneAssetsMap[asset]) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (redstoneAssetsMap[asset]) {
|
|
119
|
+
redstoneFeedIds.push(redstoneAssetsMap[asset]);
|
|
120
|
+
_redstoneAssets.add(asset);
|
|
121
|
+
const assetInfo = Object.values(config.redstoneAssetInfo).find((item) => item.address.equals(core_1.Address.parse(asset)));
|
|
122
|
+
if (assetInfo.assetType === RedstoneOnchainOracle.AssetType.currency) {
|
|
123
|
+
}
|
|
124
|
+
else if (assetInfo.assetType === RedstoneOnchainOracle.AssetType.synthetic1 &&
|
|
125
|
+
"underlyingAddress" in assetInfo) {
|
|
126
|
+
newAssets.push(assetInfo.underlyingAddress);
|
|
127
|
+
}
|
|
128
|
+
else if (assetInfo.assetType === RedstoneOnchainOracle.AssetType.synthetic2 &&
|
|
129
|
+
"underlying0Address" in assetInfo) {
|
|
130
|
+
newAssets.push(assetInfo.underlying0Address);
|
|
131
|
+
newAssets.push(assetInfo.underlying1Address);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
_requestAssets.push(asset);
|
|
136
|
+
const assetInfo = config.assetOnchainDataInfo[asset];
|
|
137
|
+
if (assetInfo.assetType === RedstoneOnchainOracle.AssetType.currency) {
|
|
138
|
+
}
|
|
139
|
+
else if (assetInfo.assetType === RedstoneOnchainOracle.AssetType.synthetic1 &&
|
|
140
|
+
"underlyingAddress" in assetInfo) {
|
|
141
|
+
newAssets.push(assetInfo.underlyingAddress);
|
|
142
|
+
}
|
|
143
|
+
else if (assetInfo.assetType === RedstoneOnchainOracle.AssetType.synthetic2 &&
|
|
144
|
+
"underlying0Address" in assetInfo) {
|
|
145
|
+
newAssets.push(assetInfo.underlying0Address);
|
|
146
|
+
newAssets.push(assetInfo.underlying1Address);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
assets = newAssets;
|
|
151
|
+
}
|
|
152
|
+
const feedIds = [...new Set(redstoneFeedIds)].map((item) => BigInt(item));
|
|
153
|
+
const redstoneAssetNames = [...new Set(redstoneFeedIds)].map((item) => NAME_MAP[item]);
|
|
154
|
+
const requestAssets = [...new Set(_requestAssets)].map((item) => core_1.Address.parse(item));
|
|
155
|
+
const redstoneAssets = [...new Set(_redstoneAssets)].map((item) => core_1.Address.parse(item));
|
|
156
|
+
return { feedIds, redstoneAssetNames, requestAssets, redstoneAssets };
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.RedstoneOnchainOracle = RedstoneOnchainOracle;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Cell } from "@ton/core";
|
|
2
|
+
import { RedstoneOnchainOracleConfig } from "./type";
|
|
3
|
+
export declare function parseRedstoneOnchainOracleConfig(cell: Cell): RedstoneOnchainOracleConfig;
|
|
4
|
+
export declare function serializeRedstoneOnchainOracleConfig(config: RedstoneOnchainOracleConfig): Cell;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseRedstoneOnchainOracleConfig = parseRedstoneOnchainOracleConfig;
|
|
4
|
+
exports.serializeRedstoneOnchainOracleConfig = serializeRedstoneOnchainOracleConfig;
|
|
5
|
+
const core_1 = require("@ton/core");
|
|
6
|
+
const _1 = require(".");
|
|
7
|
+
function parseRedstoneOnchainOracleConfig(cell) {
|
|
8
|
+
const ds = cell.beginParse();
|
|
9
|
+
const redstoneAssetInfoDict = ds.loadDict(core_1.Dictionary.Keys.BigUint(256), core_1.Dictionary.Values.Cell());
|
|
10
|
+
const threshold = ds.loadCoins();
|
|
11
|
+
const signerCell = ds.loadRef();
|
|
12
|
+
const signersTuple = threshold ? (0, core_1.parseTuple)(signerCell) : [];
|
|
13
|
+
const signers = signersTuple
|
|
14
|
+
.filter((item) => item.type === "int")
|
|
15
|
+
.map((item) => {
|
|
16
|
+
return item.value.toString(16);
|
|
17
|
+
});
|
|
18
|
+
const redstoneAssetInfo = {};
|
|
19
|
+
redstoneAssetInfoDict.keys().forEach((key) => {
|
|
20
|
+
const ds2 = redstoneAssetInfoDict.get(key)?.beginParse();
|
|
21
|
+
if (ds2) {
|
|
22
|
+
const assetType = ds2.loadUint(8);
|
|
23
|
+
if (assetType === 0) {
|
|
24
|
+
const address = ds2.loadAddress();
|
|
25
|
+
const precision = ds2.loadCoins();
|
|
26
|
+
redstoneAssetInfo[key.toString()] = { assetType, address, precision };
|
|
27
|
+
}
|
|
28
|
+
else if (assetType === 1) {
|
|
29
|
+
const address = ds2.loadAddress();
|
|
30
|
+
const underlyingAddress = ds2.loadAddress();
|
|
31
|
+
const precision = ds2.loadCoins();
|
|
32
|
+
redstoneAssetInfo[key.toString()] = { assetType, address, underlyingAddress, precision };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const onchainDataInfoDict = ds.loadDict(core_1.Dictionary.Keys.Address(), core_1.Dictionary.Values.Cell());
|
|
37
|
+
const assetOnchainDataInfo = {};
|
|
38
|
+
onchainDataInfoDict.keys().forEach((key) => {
|
|
39
|
+
const ds2 = onchainDataInfoDict.get(key)?.beginParse();
|
|
40
|
+
if (ds2) {
|
|
41
|
+
const data = {};
|
|
42
|
+
data.sourceType = ds2.loadUint(8);
|
|
43
|
+
data.sourceAddress = ds2.loadMaybeAddress();
|
|
44
|
+
data.assetType = ds2.loadUint(8);
|
|
45
|
+
if (data.assetType === _1.RedstoneOnchainOracle.AssetType.currency) {
|
|
46
|
+
try {
|
|
47
|
+
data.price = ds2.loadCoins();
|
|
48
|
+
}
|
|
49
|
+
catch (e) { }
|
|
50
|
+
}
|
|
51
|
+
else if (data.assetType === _1.RedstoneOnchainOracle.AssetType.synthetic1) {
|
|
52
|
+
data.underlyingAddress = ds2.loadAddress();
|
|
53
|
+
try {
|
|
54
|
+
data.underlyingReserve = ds2.loadCoins();
|
|
55
|
+
}
|
|
56
|
+
catch (e) { }
|
|
57
|
+
try {
|
|
58
|
+
data.totalSupply = ds2.loadCoins();
|
|
59
|
+
}
|
|
60
|
+
catch (e) { }
|
|
61
|
+
}
|
|
62
|
+
else if (data.assetType === _1.RedstoneOnchainOracle.AssetType.synthetic2) {
|
|
63
|
+
data.underlying0Address = ds2.loadAddress();
|
|
64
|
+
data.underlying1Address = ds2.loadAddress();
|
|
65
|
+
try {
|
|
66
|
+
data.underlying0Reserve = ds2.loadCoins();
|
|
67
|
+
}
|
|
68
|
+
catch (e) { }
|
|
69
|
+
try {
|
|
70
|
+
data.underlying1Reserve = ds2.loadCoins();
|
|
71
|
+
}
|
|
72
|
+
catch (e) { }
|
|
73
|
+
try {
|
|
74
|
+
data.totalSupply = ds2.loadCoins();
|
|
75
|
+
}
|
|
76
|
+
catch (e) { }
|
|
77
|
+
}
|
|
78
|
+
assetOnchainDataInfo[key.toString()] = data;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
signers: signers,
|
|
83
|
+
threshold,
|
|
84
|
+
redstoneAssetInfo,
|
|
85
|
+
assetOnchainDataInfo,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function serializeRedstoneOnchainOracleConfig(config) {
|
|
89
|
+
const redstoneAssetInfoDict = core_1.Dictionary.empty(core_1.Dictionary.Keys.BigUint(256), core_1.Dictionary.Values.Cell());
|
|
90
|
+
Object.entries(config.redstoneAssetInfo).forEach(([a, b]) => {
|
|
91
|
+
const key = BigInt(a);
|
|
92
|
+
if (b.assetType === 0) {
|
|
93
|
+
const value = (0, core_1.beginCell)().storeUint(b.assetType, 8).storeAddress(b.address).storeCoins(b.precision);
|
|
94
|
+
redstoneAssetInfoDict.set(key, value.endCell());
|
|
95
|
+
}
|
|
96
|
+
else if (b.assetType === 1) {
|
|
97
|
+
const value = (0, core_1.beginCell)()
|
|
98
|
+
.storeUint(b.assetType, 8)
|
|
99
|
+
.storeAddress(b.address)
|
|
100
|
+
.storeAddress(b.underlyingAddress)
|
|
101
|
+
.storeCoins(b.precision);
|
|
102
|
+
redstoneAssetInfoDict.set(key, value.endCell());
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const assetOnchainDataInfoDict = core_1.Dictionary.empty(core_1.Dictionary.Keys.Address(), core_1.Dictionary.Values.Cell());
|
|
106
|
+
Object.entries(config.assetOnchainDataInfo).forEach(([a, b]) => {
|
|
107
|
+
const key = BigInt(a);
|
|
108
|
+
let value = (0, core_1.beginCell)().storeUint(b.sourceType, 8).storeAddress(b.sourceAddress).storeCoins(b.assetType);
|
|
109
|
+
if (b.assetType === _1.RedstoneOnchainOracle.AssetType.currency) {
|
|
110
|
+
}
|
|
111
|
+
else if (b.assetType === _1.RedstoneOnchainOracle.AssetType.synthetic1) {
|
|
112
|
+
value = value.storeAddress(b.underlyingAddress);
|
|
113
|
+
value = value.storeCoins(b.underlyingReserve);
|
|
114
|
+
value = value.storeCoins(b.totalSupply);
|
|
115
|
+
}
|
|
116
|
+
else if (b.assetType === _1.RedstoneOnchainOracle.AssetType.synthetic2) {
|
|
117
|
+
value = value
|
|
118
|
+
.storeAddress(b.underlying0Address)
|
|
119
|
+
.storeAddress(b.underlying1Address)
|
|
120
|
+
.storeCoins(b.underlying0Reserve)
|
|
121
|
+
.storeCoins(b.underlying1Reserve)
|
|
122
|
+
.storeCoins(b.totalSupply);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
const tuple = new core_1.TupleBuilder();
|
|
126
|
+
for (let signer of config.signers) {
|
|
127
|
+
tuple.writeNumber(BigInt("0x" + signer));
|
|
128
|
+
}
|
|
129
|
+
const signers = (0, core_1.serializeTuple)(tuple.build());
|
|
130
|
+
const oracleConfig = (0, core_1.beginCell)()
|
|
131
|
+
.storeDict(redstoneAssetInfoDict)
|
|
132
|
+
.storeCoins(config.threshold)
|
|
133
|
+
.storeRef(signers)
|
|
134
|
+
.storeDict(assetOnchainDataInfoDict)
|
|
135
|
+
.endCell();
|
|
136
|
+
return oracleConfig;
|
|
137
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Address } from "@ton/core";
|
|
2
|
+
export type RedstoneOnchainOracleConfig = {
|
|
3
|
+
signers: string[];
|
|
4
|
+
threshold: bigint;
|
|
5
|
+
redstoneAssetInfo: Record<string, {
|
|
6
|
+
assetType: number;
|
|
7
|
+
address: Address;
|
|
8
|
+
precision: bigint;
|
|
9
|
+
}>;
|
|
10
|
+
assetOnchainDataInfo: OnchainDataInfo;
|
|
11
|
+
};
|
|
12
|
+
export declare enum OnchainDataSourceType {
|
|
13
|
+
Internal = 0,
|
|
14
|
+
Tonstakers = 1,
|
|
15
|
+
Stonfi = 2,
|
|
16
|
+
Dedust = 3,
|
|
17
|
+
Bemo = 4
|
|
18
|
+
}
|
|
19
|
+
export declare enum AssetType {
|
|
20
|
+
Native = 0,
|
|
21
|
+
SingleAsset = 1,
|
|
22
|
+
MultiAsset = 2,
|
|
23
|
+
VaultAsset = 10
|
|
24
|
+
}
|
|
25
|
+
export type OnchainDataInfoBase = {
|
|
26
|
+
sourceType: OnchainDataSourceType;
|
|
27
|
+
sourceAddress: Address;
|
|
28
|
+
assetType: AssetType;
|
|
29
|
+
};
|
|
30
|
+
export type OnchainDataInfoNative = OnchainDataInfoBase & {
|
|
31
|
+
assetType: AssetType.Native;
|
|
32
|
+
};
|
|
33
|
+
export type OnchainDataInfoSingleAsset = OnchainDataInfoBase & {
|
|
34
|
+
assetType: AssetType.SingleAsset;
|
|
35
|
+
underlyingAddress: Address;
|
|
36
|
+
underlyingReserve?: bigint;
|
|
37
|
+
totalSupply?: bigint;
|
|
38
|
+
};
|
|
39
|
+
export type OnchainDataInfoMultiAsset = OnchainDataInfoBase & {
|
|
40
|
+
assetType: AssetType.MultiAsset;
|
|
41
|
+
underlying0Address: Address;
|
|
42
|
+
underlying1Address: Address;
|
|
43
|
+
underlying0Reserve?: bigint;
|
|
44
|
+
underlying1Reserve?: bigint;
|
|
45
|
+
totalSupply?: bigint;
|
|
46
|
+
};
|
|
47
|
+
export type OnchainDataInfoInternal = OnchainDataInfoBase & {
|
|
48
|
+
price: bigint;
|
|
49
|
+
};
|
|
50
|
+
export type OnchainData = OnchainDataInfoNative | OnchainDataInfoSingleAsset | OnchainDataInfoMultiAsset;
|
|
51
|
+
export type OnchainDataInfo = Record<string, OnchainData>;
|
|
52
|
+
export type AssetPriceInfo = Record<string, AssetPrice>;
|
|
53
|
+
export type AssetPrice = {
|
|
54
|
+
type: AssetType;
|
|
55
|
+
price: bigint;
|
|
56
|
+
timestamp?: number;
|
|
57
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AssetType = exports.OnchainDataSourceType = void 0;
|
|
4
|
+
var OnchainDataSourceType;
|
|
5
|
+
(function (OnchainDataSourceType) {
|
|
6
|
+
OnchainDataSourceType[OnchainDataSourceType["Internal"] = 0] = "Internal";
|
|
7
|
+
OnchainDataSourceType[OnchainDataSourceType["Tonstakers"] = 1] = "Tonstakers";
|
|
8
|
+
OnchainDataSourceType[OnchainDataSourceType["Stonfi"] = 2] = "Stonfi";
|
|
9
|
+
OnchainDataSourceType[OnchainDataSourceType["Dedust"] = 3] = "Dedust";
|
|
10
|
+
OnchainDataSourceType[OnchainDataSourceType["Bemo"] = 4] = "Bemo";
|
|
11
|
+
})(OnchainDataSourceType || (exports.OnchainDataSourceType = OnchainDataSourceType = {}));
|
|
12
|
+
var AssetType;
|
|
13
|
+
(function (AssetType) {
|
|
14
|
+
AssetType[AssetType["Native"] = 0] = "Native";
|
|
15
|
+
AssetType[AssetType["SingleAsset"] = 1] = "SingleAsset";
|
|
16
|
+
AssetType[AssetType["MultiAsset"] = 2] = "MultiAsset";
|
|
17
|
+
AssetType[AssetType["VaultAsset"] = 10] = "VaultAsset";
|
|
18
|
+
})(AssetType || (exports.AssetType = AssetType = {}));
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseRedstoneOracleConfig = parseRedstoneOracleConfig;
|
|
4
|
+
const core_1 = require("@ton/core");
|
|
5
|
+
function parseRedstoneOracleConfig(cell) {
|
|
6
|
+
const ds = cell.beginParse();
|
|
7
|
+
const assetInfoDict = ds.loadDict(core_1.Dictionary.Keys.Uint(64), core_1.Dictionary.Values.Cell());
|
|
8
|
+
const threshold = ds.loadCoins();
|
|
9
|
+
const signerCell = ds.loadRef();
|
|
10
|
+
const signersTuple = threshold ? (0, core_1.parseTuple)(signerCell) : [];
|
|
11
|
+
const signers = signersTuple
|
|
12
|
+
.filter((item) => item.type === "int")
|
|
13
|
+
.map((item) => {
|
|
14
|
+
return item.value.toString(16);
|
|
15
|
+
});
|
|
16
|
+
const assetInfo = {};
|
|
17
|
+
assetInfoDict.keys().forEach((key) => {
|
|
18
|
+
const ds2 = assetInfoDict.get(key)?.beginParse();
|
|
19
|
+
if (ds2) {
|
|
20
|
+
const address = ds2.loadAddress();
|
|
21
|
+
const precision = ds2.loadCoins();
|
|
22
|
+
assetInfo[key] = { address, precision };
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
signers: signers,
|
|
27
|
+
threshold,
|
|
28
|
+
assetInfo,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a Redstone data package from hex string
|
|
3
|
+
* Pure parsing function - no external dependencies beyond @ton/core and @redstone-finance/protocol
|
|
4
|
+
*/
|
|
5
|
+
export declare function parseDataPackageHex(dataPackageHex: string): {
|
|
6
|
+
timestamp: bigint;
|
|
7
|
+
price: bigint;
|
|
8
|
+
feedId: bigint;
|
|
9
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseDataPackageHex = parseDataPackageHex;
|
|
4
|
+
const core_1 = require("@ton/core");
|
|
5
|
+
const protocol_1 = require("@redstone-finance/protocol");
|
|
6
|
+
const assert_1 = require("../../lib/assert");
|
|
7
|
+
/**
|
|
8
|
+
* Parse a Redstone data package from hex string
|
|
9
|
+
* Pure parsing function - no external dependencies beyond @ton/core and @redstone-finance/protocol
|
|
10
|
+
*/
|
|
11
|
+
function parseDataPackageHex(dataPackageHex) {
|
|
12
|
+
const data = dataPackageHex.substring(0, dataPackageHex.length - 2 * protocol_1.consts.SIGNATURE_BS);
|
|
13
|
+
const signature = dataPackageHex.substring(dataPackageHex.length - 2 * protocol_1.consts.SIGNATURE_BS, dataPackageHex.length);
|
|
14
|
+
const v = BigInt("0x" + signature.substring(128, 130));
|
|
15
|
+
(0, assert_1.assert)([27, 28].map(BigInt).includes(v), `Wrong signature 'v' value (${v})`);
|
|
16
|
+
const dataCell = (0, core_1.beginCell)()
|
|
17
|
+
.storeBuffer(Buffer.from(stringToBytes("0x" + data)))
|
|
18
|
+
.endCell();
|
|
19
|
+
let skipLastBit = protocol_1.consts.DATA_POINTS_COUNT_BS * 8;
|
|
20
|
+
const dataPointsCount = dataCell
|
|
21
|
+
.asSlice()
|
|
22
|
+
.skip(dataCell.bits.length - skipLastBit)
|
|
23
|
+
.loadUintBig(protocol_1.consts.DATA_POINTS_COUNT_BS * 8);
|
|
24
|
+
skipLastBit += protocol_1.consts.DATA_POINT_VALUE_BYTE_SIZE_BS * 8;
|
|
25
|
+
const dataPointValueByteSize = dataCell
|
|
26
|
+
.asSlice()
|
|
27
|
+
.skip(dataCell.bits.length - skipLastBit)
|
|
28
|
+
.loadUintBig(protocol_1.consts.DATA_POINT_VALUE_BYTE_SIZE_BS * 8);
|
|
29
|
+
skipLastBit += protocol_1.consts.TIMESTAMP_BS * 8;
|
|
30
|
+
const timestamp = dataCell
|
|
31
|
+
.asSlice()
|
|
32
|
+
.skip(dataCell.bits.length - skipLastBit)
|
|
33
|
+
.loadUintBig(protocol_1.consts.TIMESTAMP_BS * 8);
|
|
34
|
+
skipLastBit += Number(dataPointValueByteSize) * 8;
|
|
35
|
+
const value = dataCell
|
|
36
|
+
.asSlice()
|
|
37
|
+
.skip(dataCell.bits.length - skipLastBit)
|
|
38
|
+
.loadUintBig(Number(dataPointValueByteSize) * 8);
|
|
39
|
+
let feedId = dataCell.asSlice().loadUintBig(protocol_1.consts.DATA_FEED_ID_BS * 8);
|
|
40
|
+
if (feedId != 0n) {
|
|
41
|
+
while (feedId == (feedId / 256n) * 256n) {
|
|
42
|
+
feedId = feedId / 256n;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
timestamp,
|
|
47
|
+
price: value,
|
|
48
|
+
feedId,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function stringToBytes(value) {
|
|
52
|
+
const hexArray = value
|
|
53
|
+
.slice(2)
|
|
54
|
+
.match(/.{1,2}/g)
|
|
55
|
+
?.map((byte) => parseInt(byte, 16));
|
|
56
|
+
const buffer = Buffer.from(hexArray);
|
|
57
|
+
return buffer;
|
|
58
|
+
}
|