@floorlaunchpad/sdk 0.4.1 → 0.7.0
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/CHANGELOG.md +219 -18
- package/README.md +0 -2
- package/dist/abi/evm-event-names.js +7 -0
- package/dist/abi/evm.gen.js +6 -0
- package/dist/abi/functions.gen.js +49 -1
- package/dist/abi/solana.gen.js +5 -0
- package/dist/config/generated.js +77 -0
- package/dist/errors.js +2 -2
- package/dist/events/types.gen.js +1 -1
- package/dist/evm/chains.js +32 -24
- package/dist/evm/floor/calls.js +5 -0
- package/dist/evm/router.js +1 -25
- package/dist/evm/squid.js +3 -3
- package/dist/generated/interface.gen.js +48 -43
- package/dist/index.js +1 -0
- package/dist/indexer/bodies.js +137 -2
- package/dist/indexer/client.js +10 -1
- package/dist/indexer/contract.js +65 -6
- package/dist/indexer/paths.js +34 -7
- package/dist/indexer/read.js +12 -3
- package/dist/indexer/stream.js +2 -2
- package/dist/math/v2/book.js +40 -7
- package/dist/math/v2/create.js +1 -1
- package/dist/math/v2/fees.js +30 -4
- package/dist/math/v2/milestones.js +1 -1
- package/dist/math/v2/receipt.js +3 -3
- package/dist/math/v2/relay.js +201 -1
- package/dist/math/v2/rows.js +17 -0
- package/dist/math/v2/split.js +60 -15
- package/dist/math/v2/team.js +14 -1
- package/dist/math/v2/trade.js +16 -8
- package/dist/solana/floor/accounts.js +30 -3
- package/dist/solana/floor/events.js +6 -0
- package/dist/solana/floor/instructions.js +23 -1
- package/dist/solana/floor/program.js +3 -0
- package/dist/ton/addresses.js +36 -0
- package/dist/ton/book-check.js +23 -0
- package/dist/ton/book.js +119 -0
- package/dist/ton/cell.js +542 -0
- package/dist/ton/consts.generated.js +17 -0
- package/dist/ton/content.js +83 -0
- package/dist/ton/gas.js +198 -0
- package/dist/ton/governance.js +401 -0
- package/dist/ton/index.js +18 -0
- package/dist/ton/messages.js +340 -0
- package/dist/ton/ops.js +37 -0
- package/dist/ton/price.js +51 -0
- package/dist/ton/quote-entry.js +116 -0
- package/dist/ton/quote.js +25 -0
- package/dist/ton/reader.js +378 -0
- package/dist/ton/types.js +43 -0
- package/dist/ton/wallet.js +26 -0
- package/dist/v2/events.js +2 -0
- package/dist/v2/evm.js +8 -1
- package/dist/v2/layouts.js +7 -1
- package/dist/v2/router.js +2 -2
- package/dist/v2/solana.js +1 -1
- package/dist/v2/solanaSettle.js +2 -0
- package/dist/v2/tx/evm.js +15 -1
- package/docs/aggregator.md +0 -22
- package/docs/bot.md +0 -8
- package/docs/cursor-pages.md +9 -5
- package/docs/frontend.md +0 -2
- package/docs/ton.md +107 -0
- package/docs/wallet.md +0 -2
- package/examples/floor-line.html +1 -1
- package/package.json +6 -1
- package/src/abi/evm-event-names.ts +7 -0
- package/src/abi/evm.gen.ts +6 -0
- package/src/abi/functions.gen.ts +49 -1
- package/src/abi/solana.gen.ts +5 -0
- package/src/config/generated.ts +77 -0
- package/src/errors.ts +2 -2
- package/src/events/types.gen.ts +57 -1
- package/src/evm/chains.ts +34 -28
- package/src/evm/floor/calls.ts +5 -0
- package/src/evm/router.ts +1 -26
- package/src/evm/squid.ts +3 -3
- package/src/generated/interface.gen.ts +48 -43
- package/src/index.ts +1 -0
- package/src/indexer/bodies.ts +144 -2
- package/src/indexer/client.ts +17 -4
- package/src/indexer/contract.ts +66 -7
- package/src/indexer/paths.ts +62 -7
- package/src/indexer/read.ts +14 -5
- package/src/indexer/stream.ts +4 -4
- package/src/math/v2/book.ts +42 -7
- package/src/math/v2/create.ts +1 -1
- package/src/math/v2/fees.ts +30 -4
- package/src/math/v2/milestones.ts +1 -1
- package/src/math/v2/receipt.ts +7 -3
- package/src/math/v2/relay.ts +208 -1
- package/src/math/v2/rows.ts +17 -0
- package/src/math/v2/split.ts +70 -16
- package/src/math/v2/team.ts +14 -1
- package/src/math/v2/trade.ts +16 -8
- package/src/solana/floor/accounts.ts +30 -3
- package/src/solana/floor/events.ts +6 -0
- package/src/solana/floor/instructions.ts +23 -1
- package/src/solana/floor/program.ts +3 -0
- package/src/ton/addresses.ts +38 -0
- package/src/ton/book-check.ts +24 -0
- package/src/ton/book.ts +136 -0
- package/src/ton/cell.ts +547 -0
- package/src/ton/consts.generated.ts +17 -0
- package/src/ton/content.ts +97 -0
- package/src/ton/gas.ts +209 -0
- package/src/ton/governance.ts +452 -0
- package/src/ton/index.ts +18 -0
- package/src/ton/messages.ts +343 -0
- package/src/ton/ops.ts +37 -0
- package/src/ton/price.ts +54 -0
- package/src/ton/quote-entry.ts +138 -0
- package/src/ton/quote.ts +67 -0
- package/src/ton/reader.ts +420 -0
- package/src/ton/types.ts +201 -0
- package/src/ton/wallet.ts +30 -0
- package/src/v2/events.ts +3 -1
- package/src/v2/evm.ts +10 -1
- package/src/v2/layouts.ts +7 -1
- package/src/v2/router.ts +2 -2
- package/src/v2/solana.ts +1 -1
- package/src/v2/solanaSettle.ts +2 -0
- package/src/v2/tx/evm.ts +15 -1
- package/src/v2/types.ts +14 -1
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { Address, beginCell, bytesOfBase64, fromBoc } from "./cell.ts";
|
|
4
|
+
import type { Cell } from "./cell.ts";
|
|
5
|
+
import { addr, accountAddress as deriveAccount } from "./addresses.ts";
|
|
6
|
+
import type { AddressLike, TonChain, TonGasParams } from "./types.ts";
|
|
7
|
+
|
|
8
|
+
export type StackItem =
|
|
9
|
+
| { type: "int"; value: bigint }
|
|
10
|
+
| { type: "cell"; cell: Cell }
|
|
11
|
+
| { type: "slice"; cell: Cell }
|
|
12
|
+
| { type: "null" }
|
|
13
|
+
| { type: "tuple"; items: StackItem[] };
|
|
14
|
+
|
|
15
|
+
export interface TonRpc {
|
|
16
|
+
|
|
17
|
+
runGetMethod(address: Address, method: string, stack: StackItem[]): Promise<StackItem[]>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const intItem = (value: bigint | number | boolean): StackItem => ({ type: "int", value: BigInt(value) });
|
|
21
|
+
|
|
22
|
+
export const addressItem = (a: AddressLike | null): StackItem => ({ type: "slice", cell: beginCell().storeAddress(a === null ? null : addr(a)).endCell() });
|
|
23
|
+
|
|
24
|
+
export class StackError extends Error {}
|
|
25
|
+
|
|
26
|
+
const int = (s: StackItem[], i: number, name: string): bigint => {
|
|
27
|
+
const x = s[i];
|
|
28
|
+
if (!x || x.type !== "int") throw new StackError(`${name}: expected an int at ${i}`);
|
|
29
|
+
return x.value;
|
|
30
|
+
};
|
|
31
|
+
const bool = (s: StackItem[], i: number, name: string): boolean => int(s, i, name) !== 0n;
|
|
32
|
+
const cell = (s: StackItem[], i: number, name: string): Cell => {
|
|
33
|
+
const x = s[i];
|
|
34
|
+
if (!x || (x.type !== "cell" && x.type !== "slice")) throw new StackError(`${name}: expected a cell at ${i}`);
|
|
35
|
+
return x.cell;
|
|
36
|
+
};
|
|
37
|
+
const address = (s: StackItem[], i: number, name: string): Address | null => {
|
|
38
|
+
const x = s[i];
|
|
39
|
+
if (!x) throw new StackError(`${name}: missing item ${i}`);
|
|
40
|
+
if (x.type === "null") return null;
|
|
41
|
+
if (x.type !== "slice" && x.type !== "cell") throw new StackError(`${name}: expected an address at ${i}`);
|
|
42
|
+
return x.cell.beginParse().loadAddress();
|
|
43
|
+
};
|
|
44
|
+
const need = (s: StackItem[], n: number, name: string): void => {
|
|
45
|
+
if (s.length < n) throw new StackError(`${name}: ${s.length} stack items, expected ${n}`);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const parseNum = (v: unknown): bigint => {
|
|
49
|
+
const t = String(v);
|
|
50
|
+
return t.startsWith("-") ? -BigInt(t.slice(1)) : BigInt(t);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export function parseToncenterStack(raw: readonly unknown[]): StackItem[] {
|
|
54
|
+
return raw.map((e): StackItem => {
|
|
55
|
+
let type: string;
|
|
56
|
+
let v: any;
|
|
57
|
+
if (Array.isArray(e)) [type, v] = e as [string, any];
|
|
58
|
+
else if (e && typeof e === "object" && typeof (e as any)["@type"] === "string") {
|
|
59
|
+
|
|
60
|
+
const t = (e as any)["@type"] as string;
|
|
61
|
+
if (t === "tvm.stackEntryNumber") { type = "num"; v = (e as any).number?.number ?? (e as any).number; }
|
|
62
|
+
else if (t === "tvm.stackEntryCell") { type = "cell"; v = (e as any).cell; }
|
|
63
|
+
else if (t === "tvm.stackEntrySlice") { type = "slice"; v = (e as any).slice; }
|
|
64
|
+
else if (t === "tvm.stackEntryTuple") { type = "tuple"; v = (e as any).tuple; }
|
|
65
|
+
else if (t === "tvm.stackEntryList") { type = "list"; v = (e as any).list; }
|
|
66
|
+
else if (t === "tvm.stackEntryUnsupported") { type = "null"; v = null; }
|
|
67
|
+
else throw new StackError(`unknown stack item type ${t}`);
|
|
68
|
+
} else {
|
|
69
|
+
type = (e as any).type;
|
|
70
|
+
v = (e as any).value;
|
|
71
|
+
}
|
|
72
|
+
switch (type) {
|
|
73
|
+
case "num":
|
|
74
|
+
case "int":
|
|
75
|
+
return { type: "int", value: parseNum(v) };
|
|
76
|
+
case "cell":
|
|
77
|
+
return { type: "cell", cell: fromBoc(bytesOfBase64(typeof v === "string" ? v : v.bytes)) };
|
|
78
|
+
case "slice":
|
|
79
|
+
case "cell_slice":
|
|
80
|
+
return { type: "slice", cell: fromBoc(bytesOfBase64(typeof v === "string" ? v : v.bytes)) };
|
|
81
|
+
case "null":
|
|
82
|
+
return { type: "null" };
|
|
83
|
+
case "tuple":
|
|
84
|
+
case "list": {
|
|
85
|
+
const els: readonly unknown[] = v?.elements ?? v ?? [];
|
|
86
|
+
|
|
87
|
+
if (els.length === 0) return { type: "null" };
|
|
88
|
+
return { type: "tuple", items: parseToncenterStack(els) };
|
|
89
|
+
}
|
|
90
|
+
default:
|
|
91
|
+
throw new StackError(`unknown stack item type ${type}`);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function parseCoinsMap(root: Cell | null, keyBits: number): Map<bigint, bigint> {
|
|
97
|
+
const out = new Map<bigint, bigint>();
|
|
98
|
+
if (!root) return out;
|
|
99
|
+
const walk = (c: Cell, prefix: bigint, prefixLen: number): void => {
|
|
100
|
+
const s = c.beginParse();
|
|
101
|
+
const m = keyBits - prefixLen;
|
|
102
|
+
|
|
103
|
+
let lbl = 0n;
|
|
104
|
+
let len = 0;
|
|
105
|
+
const lenBits = (n: number): number => Math.ceil(Math.log2(n + 1));
|
|
106
|
+
if (!s.loadBit()) {
|
|
107
|
+
|
|
108
|
+
while (s.loadBit()) len++;
|
|
109
|
+
lbl = len > 0 ? s.loadUint(len) : 0n;
|
|
110
|
+
} else if (!s.loadBit()) {
|
|
111
|
+
len = Number(s.loadUint(lenBits(m)));
|
|
112
|
+
lbl = len > 0 ? s.loadUint(len) : 0n;
|
|
113
|
+
} else {
|
|
114
|
+
const bit = s.loadBit();
|
|
115
|
+
len = Number(s.loadUint(lenBits(m)));
|
|
116
|
+
lbl = bit ? (1n << BigInt(len)) - 1n : 0n;
|
|
117
|
+
}
|
|
118
|
+
const pfx = (prefix << BigInt(len)) | lbl;
|
|
119
|
+
const plen = prefixLen + len;
|
|
120
|
+
if (plen === keyBits) {
|
|
121
|
+
out.set(pfx, s.loadCoins());
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const l = s.loadRef();
|
|
126
|
+
const r = s.loadRef();
|
|
127
|
+
walk(l, pfx << 1n, plen + 1);
|
|
128
|
+
walk(r, (pfx << 1n) | 1n, plen + 1);
|
|
129
|
+
};
|
|
130
|
+
walk(root, 0n, 0);
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface TonLaunchState {
|
|
135
|
+
id: bigint; factory: Address | null; creator: Address | null; quote: Address | null; presetId: bigint; graduated: boolean;
|
|
136
|
+
supply: bigint; circulating: bigint; dead: bigint; f: bigint; c: bigint; k: bigint; moneyInPlace: bigint; reserve: bigint;
|
|
137
|
+
}
|
|
138
|
+
export interface TonFees { backing: bigint; team: bigint; platform: bigint; floor: bigint; holder: bigint }
|
|
139
|
+
export interface TonSimBuy { tokens: bigint; refund: bigint; fees: TonFees; steps: number; budgetHit: boolean; errorClass: number }
|
|
140
|
+
export interface TonSimSell { out: bigint; fees: TonFees; errorClass: number }
|
|
141
|
+
export interface AccountOwed { owed: Map<bigint, bigint>; teamBuyLockUntil: bigint; teamBuyTokens: bigint }
|
|
142
|
+
export interface InFlight { quote: Address | null; amount: bigint; bit: number; sentAt: bigint }
|
|
143
|
+
export interface TonPosition { amount: bigint; owed: bigint; indexSnapX64: bigint; optedIn: boolean; dead: boolean }
|
|
144
|
+
|
|
145
|
+
function feesOf(s: StackItem[], i: number, name: string): TonFees {
|
|
146
|
+
const x = s[i];
|
|
147
|
+
if (!x || x.type !== "tuple" || x.items.length < 5) throw new StackError(`${name}: expected a 5-int tuple at ${i}`);
|
|
148
|
+
const [backing, team, platform, floor, holder] = [0, 1, 2, 3, 4].map((k) => int(x.items, k, `${name}[${k}]`));
|
|
149
|
+
return { backing: backing!, team: team!, platform: platform!, floor: floor!, holder: holder! };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function run(rpc: TonRpc, a: AddressLike, method: string, stack: StackItem[] = []): Promise<StackItem[]> {
|
|
153
|
+
return rpc.runGetMethod(addr(a), method, stack);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export async function getLaunchState(rpc: TonRpc, launch: AddressLike): Promise<TonLaunchState> {
|
|
157
|
+
const s = await run(rpc, launch, "get_launch_state");
|
|
158
|
+
need(s, 14, "get_launch_state");
|
|
159
|
+
return {
|
|
160
|
+
id: int(s, 0, "id"), factory: address(s, 1, "factory"), creator: address(s, 2, "creator"), quote: address(s, 3, "quote"),
|
|
161
|
+
presetId: int(s, 4, "preset_id"), graduated: bool(s, 5, "phase"), supply: int(s, 6, "supply"), circulating: int(s, 7, "circulating"),
|
|
162
|
+
dead: int(s, 8, "dead"), f: int(s, 9, "f"), c: int(s, 10, "c"), k: int(s, 11, "k"), moneyInPlace: int(s, 12, "money_in_place"),
|
|
163
|
+
reserve: int(s, 13, "reserve"),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export async function getLaunchBook(rpc: TonRpc, launch: AddressLike): Promise<Cell> {
|
|
168
|
+
const s = await run(rpc, launch, "get_launch_book");
|
|
169
|
+
need(s, 1, "get_launch_book");
|
|
170
|
+
return cell(s, 0, "book");
|
|
171
|
+
}
|
|
172
|
+
export async function getLaunchMilestones(rpc: TonRpc, launch: AddressLike): Promise<Cell> {
|
|
173
|
+
return cell(await run(rpc, launch, "get_launch_milestones"), 0, "milestones");
|
|
174
|
+
}
|
|
175
|
+
export async function getFeeCurve(rpc: TonRpc, launch: AddressLike): Promise<Cell> {
|
|
176
|
+
return cell(await run(rpc, launch, "get_fee_curve"), 0, "curve");
|
|
177
|
+
}
|
|
178
|
+
export async function getCirculating(rpc: TonRpc, launch: AddressLike): Promise<bigint> {
|
|
179
|
+
return int(await run(rpc, launch, "get_circulating"), 0, "s_circ");
|
|
180
|
+
}
|
|
181
|
+
export async function getBidMoney(rpc: TonRpc, launch: AddressLike): Promise<{ f: bigint; c: bigint; k: bigint; moneyInPlace: bigint }> {
|
|
182
|
+
const s = await run(rpc, launch, "get_bid_money");
|
|
183
|
+
need(s, 4, "get_bid_money");
|
|
184
|
+
return { f: int(s, 0, "f"), c: int(s, 1, "c"), k: int(s, 2, "k"), moneyInPlace: int(s, 3, "money_in_place") };
|
|
185
|
+
}
|
|
186
|
+
export async function getHolderBook(rpc: TonRpc, launch: AddressLike): Promise<{ indexX64: bigint; w: bigint; bucket: bigint }> {
|
|
187
|
+
const s = await run(rpc, launch, "get_holder_book");
|
|
188
|
+
need(s, 3, "get_holder_book");
|
|
189
|
+
return { indexX64: int(s, 0, "index_x64"), w: int(s, 1, "w"), bucket: int(s, 2, "bucket") };
|
|
190
|
+
}
|
|
191
|
+
export async function getTeamShare(rpc: TonRpc, launch: AddressLike, place: number): Promise<{ owed: bigint; bought: bigint }> {
|
|
192
|
+
const s = await run(rpc, launch, "get_team_share", [intItem(place)]);
|
|
193
|
+
need(s, 2, "get_team_share");
|
|
194
|
+
return { owed: int(s, 0, "owed"), bought: int(s, 1, "bought") };
|
|
195
|
+
}
|
|
196
|
+
export async function getGasParams(rpc: TonRpc, launch: AddressLike): Promise<TonGasParams> {
|
|
197
|
+
const s = await run(rpc, launch, "get_gas_params");
|
|
198
|
+
need(s, 4, "get_gas_params");
|
|
199
|
+
return { buyFwdMin: int(s, 0, "buy_fwd_min"), sellFwdMin: int(s, 1, "sell_fwd_min"), refundFwdMin: int(s, 2, "refund_fwd_min"), reclaimAfter: int(s, 3, "reclaim_after") };
|
|
200
|
+
}
|
|
201
|
+
export async function getQuoteWallet(rpc: TonRpc, launch: AddressLike): Promise<Address | null> {
|
|
202
|
+
return address(await run(rpc, launch, "get_quote_wallet"), 0, "wallet");
|
|
203
|
+
}
|
|
204
|
+
export async function getQuoteBooks(rpc: TonRpc, launch: AddressLike): Promise<{ entry: Cell; booked: bigint; syncedBalance: bigint; syncedAt: bigint; surplus: bigint }> {
|
|
205
|
+
const s = await run(rpc, launch, "get_quote_books");
|
|
206
|
+
need(s, 5, "get_quote_books");
|
|
207
|
+
return { entry: cell(s, 0, "entry"), booked: int(s, 1, "booked"), syncedBalance: int(s, 2, "synced_balance"), syncedAt: int(s, 3, "synced_at"), surplus: int(s, 4, "surplus") };
|
|
208
|
+
}
|
|
209
|
+
export async function getWalletAddress(rpc: TonRpc, master: AddressLike, owner: AddressLike): Promise<Address | null> {
|
|
210
|
+
return address(await run(rpc, master, "get_wallet_address", [addressItem(owner)]), 0, "wallet");
|
|
211
|
+
}
|
|
212
|
+
export async function getLaunchAddress(rpc: TonRpc, factory: AddressLike, id: bigint): Promise<Address | null> {
|
|
213
|
+
return address(await run(rpc, factory, "get_launch_address", [intItem(id)]), 0, "launch");
|
|
214
|
+
}
|
|
215
|
+
export async function getAccountAddress(rpc: TonRpc, launch: AddressLike, owner: AddressLike): Promise<Address | null> {
|
|
216
|
+
return address(await run(rpc, launch, "get_account_address", [addressItem(owner)]), 0, "account");
|
|
217
|
+
}
|
|
218
|
+
export async function getPosition(rpc: TonRpc, wallet: AddressLike): Promise<TonPosition> {
|
|
219
|
+
const s = await run(rpc, wallet, "get_position");
|
|
220
|
+
need(s, 5, "get_position");
|
|
221
|
+
return { amount: int(s, 0, "amount"), owed: int(s, 1, "owed"), indexSnapX64: int(s, 2, "index_snap_x64"), optedIn: bool(s, 3, "opted_in"), dead: bool(s, 4, "dead") };
|
|
222
|
+
}
|
|
223
|
+
export async function getWalletData(rpc: TonRpc, wallet: AddressLike): Promise<{ balance: bigint; owner: Address | null; master: Address | null }> {
|
|
224
|
+
const s = await run(rpc, wallet, "get_wallet_data");
|
|
225
|
+
need(s, 3, "get_wallet_data");
|
|
226
|
+
return { balance: int(s, 0, "balance"), owner: address(s, 1, "owner"), master: address(s, 2, "master") };
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export async function simBuy(rpc: TonRpc, launch: AddressLike, money: bigint, now: bigint): Promise<TonSimBuy> {
|
|
230
|
+
const s = await run(rpc, launch, "sim_buy", [intItem(money), intItem(now)]);
|
|
231
|
+
need(s, 6, "sim_buy");
|
|
232
|
+
return { tokens: int(s, 0, "tokens"), refund: int(s, 1, "refund"), fees: feesOf(s, 2, "fees"), steps: Number(int(s, 3, "steps")), budgetHit: bool(s, 4, "budget_hit"), errorClass: Number(int(s, 5, "class")) };
|
|
233
|
+
}
|
|
234
|
+
export async function simSell(rpc: TonRpc, launch: AddressLike, tokens: bigint, now: bigint): Promise<TonSimSell> {
|
|
235
|
+
const s = await run(rpc, launch, "sim_sell", [intItem(tokens), intItem(now)]);
|
|
236
|
+
need(s, 3, "sim_sell");
|
|
237
|
+
return { out: int(s, 0, "out"), fees: feesOf(s, 1, "fees"), errorClass: Number(int(s, 2, "class")) };
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export async function quoteBuyMoney(rpc: TonRpc, launch: AddressLike, tokens: bigint): Promise<bigint> {
|
|
241
|
+
return int(await run(rpc, launch, "quote_buy", [intItem(tokens)]), 0, "money");
|
|
242
|
+
}
|
|
243
|
+
export async function quoteSellTokens(rpc: TonRpc, launch: AddressLike, out: bigint): Promise<bigint> {
|
|
244
|
+
return int(await run(rpc, launch, "quote_sell", [intItem(out)]), 0, "tokens");
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export async function getOwed(rpc: TonRpc, account: AddressLike): Promise<AccountOwed> {
|
|
248
|
+
const s = await run(rpc, account, "get_owed");
|
|
249
|
+
need(s, 3, "get_owed");
|
|
250
|
+
const m = s[0];
|
|
251
|
+
return {
|
|
252
|
+
owed: parseCoinsMap(m && m.type !== "null" && m.type !== "int" ? (m as { cell: Cell }).cell : null, 16),
|
|
253
|
+
teamBuyLockUntil: int(s, 1, "team_buy_lock_until"), teamBuyTokens: int(s, 2, "team_buy_tokens"),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export async function getOwedOf(rpc: TonRpc, chain: Pick<TonChain, "codes">, launch: AddressLike, owner: AddressLike): Promise<AccountOwed> {
|
|
258
|
+
return getOwed(rpc, deriveAccount(chain, launch, owner));
|
|
259
|
+
}
|
|
260
|
+
export async function getInFlight(rpc: TonRpc, account: AddressLike, payoutId: bigint): Promise<InFlight> {
|
|
261
|
+
const s = await run(rpc, account, "get_in_flight", [intItem(payoutId)]);
|
|
262
|
+
need(s, 4, "get_in_flight");
|
|
263
|
+
return { quote: address(s, 0, "quote"), amount: int(s, 1, "amount"), bit: Number(int(s, 2, "bit")), sentAt: int(s, 3, "sent_at") };
|
|
264
|
+
}
|
|
265
|
+
export async function getConfig(rpc: TonRpc, factory: AddressLike): Promise<{
|
|
266
|
+
authority: Address | null; pendingAuthority: Address | null; timelock: Address | null; treasury: Address | null; createPaused: boolean;
|
|
267
|
+
nativeCreateFee: bigint; referralAuthority: bigint; priceUpdater: bigint; holderDest: Address | null; metadataBase: Cell | null;
|
|
268
|
+
launchCount: bigint; nextPresetId: bigint; codeVersion: bigint;
|
|
269
|
+
}> {
|
|
270
|
+
const s = await run(rpc, factory, "get_config");
|
|
271
|
+
need(s, 13, "get_config");
|
|
272
|
+
return {
|
|
273
|
+
authority: address(s, 0, "authority"), pendingAuthority: address(s, 1, "pending_authority"), timelock: address(s, 2, "timelock"), treasury: address(s, 3, "treasury"),
|
|
274
|
+
createPaused: bool(s, 4, "create_paused"), nativeCreateFee: int(s, 5, "native_create_fee"), referralAuthority: int(s, 6, "referral_authority"),
|
|
275
|
+
priceUpdater: int(s, 7, "price_updater"), holderDest: address(s, 8, "holder_dest"), metadataBase: s[9]?.type === "null" ? null : cell(s, 9, "metadata_base"),
|
|
276
|
+
launchCount: int(s, 10, "launch_count"), nextPresetId: int(s, 11, "next_preset_id"), codeVersion: int(s, 12, "code_version"),
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
export async function getQuote(rpc: TonRpc, factory: AddressLike, master: AddressLike | null): Promise<{ entry: Cell; usdCentsX64: bigint; validUntil: bigint }> {
|
|
280
|
+
const s = await run(rpc, factory, "get_quote", [addressItem(master)]);
|
|
281
|
+
need(s, 3, "get_quote");
|
|
282
|
+
return { entry: cell(s, 0, "entry"), usdCentsX64: int(s, 1, "usd_cents_x64"), validUntil: int(s, 2, "valid_until") };
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export interface TonQuotePrice { listed: boolean; entry: QuoteEntry | null; usdCentsX64: bigint; validUntil: bigint }
|
|
286
|
+
|
|
287
|
+
export async function getTonQuotePrice(rpc: TonRpc, factory: AddressLike, quote: AddressLike | null): Promise<TonQuotePrice> {
|
|
288
|
+
const s = await run(rpc, factory, "get_quote", [addressItem(quote)]);
|
|
289
|
+
need(s, 3, "get_quote");
|
|
290
|
+
const usdCentsX64 = int(s, 1, "usd_cents_x64");
|
|
291
|
+
const validUntil = int(s, 2, "valid_until");
|
|
292
|
+
if (s[0]!.type === "null") return { listed: false, entry: null, usdCentsX64, validUntil };
|
|
293
|
+
return { listed: true, entry: decodeTonQuoteEntry(cell(s, 0, "entry")), usdCentsX64, validUntil };
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export interface QuoteEntry {
|
|
297
|
+
kind: 0 | 1; master: Address | null; decimals: number; walletKind: number; walletCodeHash: bigint; walletCode: Cell | null;
|
|
298
|
+
createFee: bigint; issuerCanFreeze: boolean; createsEnabled: boolean; cap: bigint;
|
|
299
|
+
}
|
|
300
|
+
export function decodeTonQuoteEntry(c: Cell): QuoteEntry {
|
|
301
|
+
const s = c.beginParse();
|
|
302
|
+
const kind = Number(s.loadUint(1)) as 0 | 1;
|
|
303
|
+
const master = s.loadAddress();
|
|
304
|
+
const decimals = Number(s.loadUint(8));
|
|
305
|
+
const walletKind = Number(s.loadUint(8));
|
|
306
|
+
const walletCodeHash = s.loadUint(256);
|
|
307
|
+
const walletCode = s.loadMaybeRef();
|
|
308
|
+
const createFee = s.loadCoins();
|
|
309
|
+
const issuerCanFreeze = s.loadBit();
|
|
310
|
+
const createsEnabled = s.loadBit();
|
|
311
|
+
const cap = s.loadCoins();
|
|
312
|
+
s.endParse();
|
|
313
|
+
return { kind, master, decimals, walletKind, walletCodeHash, walletCode, createFee, issuerCanFreeze, createsEnabled, cap };
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export interface TonSlotPlace {
|
|
317
|
+
place: number; member: Address | null; handle: bigint | null; shares: bigint; weightPpb: bigint;
|
|
318
|
+
slotOwed: bigint; boughtOwed: bigint; teamBuyPart: bigint;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export interface TonTeamSlot { slotBps: bigint; count: number; shareTotal: bigint; shareBuyDay: bigint; places: TonSlotPlace[] }
|
|
322
|
+
|
|
323
|
+
export function parseRefMap(root: Cell | null, keyBits: number): Map<bigint, Cell> {
|
|
324
|
+
const out = new Map<bigint, Cell>();
|
|
325
|
+
if (!root) return out;
|
|
326
|
+
const lenBits = (n: number): number => Math.ceil(Math.log2(n + 1));
|
|
327
|
+
const walk = (c: Cell, prefix: bigint, prefixLen: number): void => {
|
|
328
|
+
const s = c.beginParse();
|
|
329
|
+
const m = keyBits - prefixLen;
|
|
330
|
+
let lbl = 0n;
|
|
331
|
+
let len = 0;
|
|
332
|
+
if (!s.loadBit()) {
|
|
333
|
+
while (s.loadBit()) len++;
|
|
334
|
+
lbl = len > 0 ? s.loadUint(len) : 0n;
|
|
335
|
+
} else if (!s.loadBit()) {
|
|
336
|
+
len = Number(s.loadUint(lenBits(m)));
|
|
337
|
+
lbl = len > 0 ? s.loadUint(len) : 0n;
|
|
338
|
+
} else {
|
|
339
|
+
const bit = s.loadBit();
|
|
340
|
+
len = Number(s.loadUint(lenBits(m)));
|
|
341
|
+
lbl = bit ? (1n << BigInt(len)) - 1n : 0n;
|
|
342
|
+
}
|
|
343
|
+
const pfx = (prefix << BigInt(len)) | lbl;
|
|
344
|
+
const plen = prefixLen + len;
|
|
345
|
+
if (plen === keyBits) {
|
|
346
|
+
out.set(pfx, s.loadRef());
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
const l = s.loadRef();
|
|
350
|
+
const r = s.loadRef();
|
|
351
|
+
walk(l, pfx << 1n, plen + 1);
|
|
352
|
+
walk(r, (pfx << 1n) | 1n, plen + 1);
|
|
353
|
+
};
|
|
354
|
+
walk(root, 0n, 0);
|
|
355
|
+
return out;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export function decodeTonSlotPlace(c: Cell, place: number): TonSlotPlace {
|
|
359
|
+
const s = c.beginParse();
|
|
360
|
+
const member = s.loadAddress();
|
|
361
|
+
const handle = s.loadBit() ? s.loadUint(256) : null;
|
|
362
|
+
const shares = s.loadUint(64);
|
|
363
|
+
const weightPpb = s.loadUint(32);
|
|
364
|
+
const slotOwed = s.loadCoins();
|
|
365
|
+
const boughtOwed = s.loadCoins();
|
|
366
|
+
const teamBuyPart = s.loadCoins();
|
|
367
|
+
s.endParse();
|
|
368
|
+
return { place, member, handle, shares, weightPpb, slotOwed, boughtOwed, teamBuyPart };
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export async function getTeamSlot(rpc: TonRpc, launch: AddressLike): Promise<TonTeamSlot> {
|
|
372
|
+
const s = await run(rpc, launch, "get_team_slot");
|
|
373
|
+
need(s, 5, "get_team_slot");
|
|
374
|
+
const d = s[4];
|
|
375
|
+
const dict = d && d.type !== "null" && d.type !== "int" ? (d as { cell: Cell }).cell : null;
|
|
376
|
+
const places = [...parseRefMap(dict, 4)].sort((a, b) => (a[0] < b[0] ? -1 : 1)).map(([k, c]) => decodeTonSlotPlace(c, Number(k)));
|
|
377
|
+
return { slotBps: int(s, 0, "slot_bps"), count: Number(int(s, 1, "count")), shareTotal: int(s, 2, "share_total"), shareBuyDay: int(s, 3, "share_buy_day"), places };
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export interface TonPresetRowInfo {
|
|
381
|
+
found: boolean; row: Cell | null; rowBytes: Uint8Array | null; enabled: boolean; deleted: boolean; checked: boolean; version: bigint; hash: bigint;
|
|
382
|
+
}
|
|
383
|
+
export async function getPresetRow(rpc: TonRpc, factory: AddressLike, id: bigint | number): Promise<TonPresetRowInfo> {
|
|
384
|
+
const s = await run(rpc, factory, "get_preset_row", [intItem(id)]);
|
|
385
|
+
need(s, 6, "get_preset_row");
|
|
386
|
+
const r = s[0];
|
|
387
|
+
const row = r && r.type !== "null" && r.type !== "int" ? (r as { cell: Cell }).cell : null;
|
|
388
|
+
let rowBytes: Uint8Array | null = null;
|
|
389
|
+
if (row) {
|
|
390
|
+
const parts: Uint8Array[] = [];
|
|
391
|
+
for (let cur: Cell | null = row; cur; ) {
|
|
392
|
+
const sl = cur.beginParse();
|
|
393
|
+
parts.push(sl.loadBytes(sl.remainingBits / 8));
|
|
394
|
+
cur = sl.remainingRefs ? sl.loadRef() : null;
|
|
395
|
+
}
|
|
396
|
+
rowBytes = new Uint8Array(parts.reduce((a, p) => a + p.length, 0));
|
|
397
|
+
let o = 0;
|
|
398
|
+
for (const p of parts) (rowBytes.set(p, o), (o += p.length));
|
|
399
|
+
}
|
|
400
|
+
return {
|
|
401
|
+
found: row !== null, row, rowBytes, enabled: bool(s, 1, "enabled"), deleted: bool(s, 2, "deleted"), checked: bool(s, 3, "checked"),
|
|
402
|
+
version: int(s, 4, "version"), hash: int(s, 5, "hash"),
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export async function getTraderAddress(rpc: TonRpc, factory: AddressLike, trader: AddressLike): Promise<Address | null> {
|
|
407
|
+
return address(await run(rpc, factory, "get_trader_address", [addressItem(trader)]), 0, "trader");
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export async function getFamily(rpc: TonRpc, factory: AddressLike, family: number): Promise<{ version: bigint; initHash: bigint; codeHash: bigint }> {
|
|
411
|
+
if (!Number.isInteger(family) || family < 0 || family > 4) throw new RangeError("family must be 0 to 4");
|
|
412
|
+
const s = await run(rpc, factory, "get_family", [intItem(family)]);
|
|
413
|
+
need(s, 3, "get_family");
|
|
414
|
+
return { version: int(s, 0, "version"), initHash: int(s, 1, "init_hash"), codeHash: int(s, 2, "code_hash") };
|
|
415
|
+
}
|
|
416
|
+
export async function getTimelockInfo(rpc: TonRpc, timelock: AddressLike): Promise<{ admin: Address | null; factory: Address | null; delay: bigint }> {
|
|
417
|
+
const s = await run(rpc, timelock, "get_timelock");
|
|
418
|
+
need(s, 3, "get_timelock");
|
|
419
|
+
return { admin: address(s, 0, "admin"), factory: address(s, 1, "factory"), delay: int(s, 2, "delay") };
|
|
420
|
+
}
|
package/src/ton/types.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import type { Address, Cell } from "./cell.ts";
|
|
4
|
+
|
|
5
|
+
export interface TonMessage {
|
|
6
|
+
to: Address;
|
|
7
|
+
|
|
8
|
+
value: bigint;
|
|
9
|
+
bounce: boolean;
|
|
10
|
+
body: Cell;
|
|
11
|
+
|
|
12
|
+
stateInit?: { code: Cell; data: Cell };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface TonTx {
|
|
16
|
+
family: "ton";
|
|
17
|
+
messages: TonMessage[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type AddressLike = Address | string;
|
|
21
|
+
|
|
22
|
+
export type TonQuote = { kind: "native" } | { kind: "jetton"; master: AddressLike };
|
|
23
|
+
|
|
24
|
+
export interface TonCodes {
|
|
25
|
+
|
|
26
|
+
launch?: Cell;
|
|
27
|
+
|
|
28
|
+
wallet: Cell;
|
|
29
|
+
account: Cell;
|
|
30
|
+
trader: Cell;
|
|
31
|
+
|
|
32
|
+
factory?: Cell;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface TonChain {
|
|
36
|
+
family: "ton";
|
|
37
|
+
factory: AddressLike;
|
|
38
|
+
codes: TonCodes;
|
|
39
|
+
|
|
40
|
+
workchain?: 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface TonGasParams {
|
|
44
|
+
buyFwdMin: bigint;
|
|
45
|
+
sellFwdMin: bigint;
|
|
46
|
+
refundFwdMin: bigint;
|
|
47
|
+
|
|
48
|
+
reclaimAfter: bigint;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const DEFAULT_GAS: TonGasParams = {
|
|
52
|
+
buyFwdMin: 300_000_000n,
|
|
53
|
+
sellFwdMin: 300_000_000n,
|
|
54
|
+
refundFwdMin: 60_000_000n,
|
|
55
|
+
reclaimAfter: 3600n,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const TON_CLAIM = {
|
|
59
|
+
CREATOR: 1,
|
|
60
|
+
CREATOR_REF: 2,
|
|
61
|
+
TEAM_SLOT: 4,
|
|
62
|
+
TRADER_REF: 8,
|
|
63
|
+
EXTRA_RESERVED: 32,
|
|
64
|
+
PAYOUT: 64,
|
|
65
|
+
TEAM_BUY: 128,
|
|
66
|
+
SHARE_BOUGHT: 256,
|
|
67
|
+
HOLDER: 512,
|
|
68
|
+
} as const;
|
|
69
|
+
export const TON_CLAIM_KNOWN = 975;
|
|
70
|
+
|
|
71
|
+
export const TON_WALK_STEPS = 16;
|
|
72
|
+
|
|
73
|
+
interface Common {
|
|
74
|
+
|
|
75
|
+
queryId?: bigint;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface TonBuyArgs extends Common {
|
|
79
|
+
launch: AddressLike;
|
|
80
|
+
|
|
81
|
+
money: bigint;
|
|
82
|
+
minTokens: bigint;
|
|
83
|
+
|
|
84
|
+
deadline: number;
|
|
85
|
+
|
|
86
|
+
recipient: AddressLike;
|
|
87
|
+
|
|
88
|
+
referrer?: AddressLike;
|
|
89
|
+
|
|
90
|
+
gas?: bigint;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface TonBuyJettonArgs extends Omit<TonBuyArgs, "gas"> {
|
|
94
|
+
|
|
95
|
+
buyerQuoteWallet: AddressLike;
|
|
96
|
+
|
|
97
|
+
buyer: AddressLike;
|
|
98
|
+
|
|
99
|
+
forwardTon?: bigint;
|
|
100
|
+
|
|
101
|
+
walletGas?: bigint;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export const REFERRED_HOP = 60_000_000n;
|
|
105
|
+
|
|
106
|
+
export const REFERRED_FWD_MIN = 240_000_000n;
|
|
107
|
+
|
|
108
|
+
export const REFERRED_SELL_FWD_MIN = 240_000_000n;
|
|
109
|
+
|
|
110
|
+
export const REFERRED_GIFT_FWD_MIN = REFERRED_FWD_MIN + REFERRED_HOP;
|
|
111
|
+
|
|
112
|
+
export const REFERRED_FWD_DEFAULT = DEFAULT_GAS.buyFwdMin + REFERRED_HOP;
|
|
113
|
+
export const REFERRED_SELL_FWD_DEFAULT = DEFAULT_GAS.sellFwdMin + REFERRED_HOP;
|
|
114
|
+
export const REFERRED_GIFT_FWD_DEFAULT = REFERRED_FWD_DEFAULT + REFERRED_HOP;
|
|
115
|
+
export const REFERRED_SELL_GIFT_FWD_DEFAULT = REFERRED_SELL_FWD_DEFAULT + REFERRED_HOP;
|
|
116
|
+
|
|
117
|
+
export interface TonBuyReferredJettonArgs extends Omit<TonBuyJettonArgs, "buyer"> {
|
|
118
|
+
|
|
119
|
+
trader: AddressLike;
|
|
120
|
+
|
|
121
|
+
deployTrader?: boolean;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface TonBuyReferredArgs extends TonBuyArgs {
|
|
125
|
+
|
|
126
|
+
trader: AddressLike;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface TonSellReferredArgs extends Omit<TonSellArgs, "gasParams"> {
|
|
130
|
+
|
|
131
|
+
deployTrader?: boolean;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface TonSellArgs extends Common {
|
|
135
|
+
launch: AddressLike;
|
|
136
|
+
|
|
137
|
+
seller: AddressLike;
|
|
138
|
+
tokens: bigint;
|
|
139
|
+
|
|
140
|
+
minOut: bigint;
|
|
141
|
+
deadline: number;
|
|
142
|
+
recipient: AddressLike;
|
|
143
|
+
|
|
144
|
+
forwardTon?: bigint;
|
|
145
|
+
walletGas?: bigint;
|
|
146
|
+
|
|
147
|
+
sellerWallet?: AddressLike;
|
|
148
|
+
|
|
149
|
+
gasParams?: TonGasParams;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface TonClaimArgs extends Common {
|
|
153
|
+
launch: AddressLike;
|
|
154
|
+
owner: AddressLike;
|
|
155
|
+
|
|
156
|
+
types: number;
|
|
157
|
+
|
|
158
|
+
to?: AddressLike;
|
|
159
|
+
|
|
160
|
+
gas?: bigint;
|
|
161
|
+
|
|
162
|
+
deploy?: boolean;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export interface TonTeamSpecArg {
|
|
166
|
+
|
|
167
|
+
slotBps: number;
|
|
168
|
+
creatorHandle?: bigint;
|
|
169
|
+
|
|
170
|
+
creatorRefs?: readonly [AddressLike | null, AddressLike | null, AddressLike | null];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface TonCreateArgs extends Common {
|
|
174
|
+
|
|
175
|
+
creator: AddressLike;
|
|
176
|
+
presetId: number;
|
|
177
|
+
|
|
178
|
+
quote: AddressLike | null;
|
|
179
|
+
listed: boolean;
|
|
180
|
+
name: string;
|
|
181
|
+
symbol: string;
|
|
182
|
+
uri: string;
|
|
183
|
+
team: TonTeamSpecArg;
|
|
184
|
+
|
|
185
|
+
teamBuyMoney: bigint;
|
|
186
|
+
teamBuyMinTokens: bigint;
|
|
187
|
+
creatorRef?: AddressLike;
|
|
188
|
+
deadline: number;
|
|
189
|
+
|
|
190
|
+
createFee: bigint;
|
|
191
|
+
|
|
192
|
+
deployGas?: bigint;
|
|
193
|
+
|
|
194
|
+
creatorQuoteWallet?: AddressLike;
|
|
195
|
+
forwardTon?: bigint;
|
|
196
|
+
walletGas?: bigint;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface TonTeamShareBuyArgs {
|
|
200
|
+
launch: AddressLike; place: number; money: bigint; minTokens: bigint; deadline: number; thenClaim?: boolean; queryId?: bigint; gas?: bigint;
|
|
201
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { base64Of, stateInitCell, toBoc } from "./cell.ts";
|
|
4
|
+
import type { TonTx } from "./types.ts";
|
|
5
|
+
|
|
6
|
+
export interface TonConnectMessage { address: string; amount: string; payload: string; stateInit?: string }
|
|
7
|
+
export interface TonConnectRequest { validUntil: number; messages: TonConnectMessage[] }
|
|
8
|
+
|
|
9
|
+
const VALID_FOR_DEFAULT = 300;
|
|
10
|
+
const VALID_FOR_MAX = 600;
|
|
11
|
+
const MAX_MESSAGES_DEFAULT = 4;
|
|
12
|
+
|
|
13
|
+
export function tonConnectRequest(tx: TonTx, o: { nowS: number; validForS?: number; maxMessages?: number }): TonConnectRequest {
|
|
14
|
+
const max = o.maxMessages ?? MAX_MESSAGES_DEFAULT;
|
|
15
|
+
const n = tx.messages.length;
|
|
16
|
+
if (n < 1 || n > max) throw new RangeError(`a request carries 1 to ${max} messages, got ${n}`);
|
|
17
|
+
const validFor = o.validForS ?? VALID_FOR_DEFAULT;
|
|
18
|
+
if (!Number.isInteger(validFor) || validFor < 1 || validFor > VALID_FOR_MAX) throw new RangeError("validForS must be 1 to 600");
|
|
19
|
+
if (!Number.isInteger(o.nowS) || o.nowS < 0) throw new RangeError("nowS must be a non-negative integer (seconds)");
|
|
20
|
+
const messages = tx.messages.map((m): TonConnectMessage => {
|
|
21
|
+
const out: TonConnectMessage = {
|
|
22
|
+
address: m.to.toString({ bounceable: m.bounce, urlSafe: true }),
|
|
23
|
+
amount: m.value.toString(),
|
|
24
|
+
payload: base64Of(toBoc(m.body)),
|
|
25
|
+
};
|
|
26
|
+
if (m.stateInit) out.stateInit = base64Of(toBoc(stateInitCell(m.stateInit.code, m.stateInit.data)));
|
|
27
|
+
return out;
|
|
28
|
+
});
|
|
29
|
+
return { validUntil: o.nowS + validFor, messages };
|
|
30
|
+
}
|
package/src/v2/events.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { hex } from "../codec.ts";
|
|
|
4
4
|
import { EVENT_IX_TAG_LE, eventDiscriminator } from "../solana/instruction.ts";
|
|
5
5
|
import { Reader, Writer } from "../solana/floor/borsh.ts";
|
|
6
6
|
|
|
7
|
-
type F = "pubkey" | "bool" | "u8" | "u32" | "u64" | "i64" | "u128" | "u64[4]" | "u64[5]" | "bytes:10" | "bytes:32";
|
|
7
|
+
type F = "pubkey" | "bool" | "u8" | "u32" | "u64" | "i64" | "u128" | "u64[3]" | "u64[4]" | "u64[5]" | "bytes:10" | "bytes:32";
|
|
8
8
|
const S = (...f: [string, F][]): [string, F][] => f;
|
|
9
9
|
|
|
10
10
|
export const EVENTS_V2: Record<string, [string, F][]> = {
|
|
@@ -25,6 +25,8 @@ export const EVENTS_V2: Record<string, [string, F][]> = {
|
|
|
25
25
|
HolderPositionClosed: S(["launch", "pubkey"], ["owner", "pubkey"], ["amount", "u64"], ["paid", "u64"]),
|
|
26
26
|
HolderIndexRolled: S(["launch", "pubkey"], ["index", "u128"], ["wMatured", "u64"], ["wPending", "u64"], ["carry", "u64"]),
|
|
27
27
|
DeadSynced: S(["launch", "pubkey"], ["added", "u64"], ["deadTokens", "u64"], ["sCirc", "u64"]),
|
|
28
|
+
|
|
29
|
+
RefSlices: S(["launch", "pubkey"], ["trader", "pubkey"], ["traderParts", "u64[3]"], ["creatorParts", "u64[3]"], ["og", "u8"]),
|
|
28
30
|
};
|
|
29
31
|
|
|
30
32
|
EVENTS_V2.GenesisRaiseBought = EVENTS_V2.Trade;
|