@floorlaunchpad/sdk 0.4.1 → 0.6.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 +83 -18
- package/README.md +0 -2
- package/dist/abi/functions.gen.js +1 -1
- package/dist/config/generated.js +77 -0
- package/dist/evm/chains.js +1 -24
- package/dist/evm/router.js +1 -25
- package/dist/evm/squid.js +3 -3
- package/dist/index.js +1 -0
- package/dist/indexer/bodies.js +4 -0
- package/dist/math/v2/book.js +40 -7
- package/dist/math/v2/create.js +1 -1
- package/dist/math/v2/relay.js +201 -1
- package/dist/math/v2/split.js +60 -15
- package/dist/math/v2/trade.js +16 -8
- 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/evm.js +3 -1
- package/dist/v2/layouts.js +5 -1
- package/dist/v2/router.js +2 -2
- package/dist/v2/solanaSettle.js +2 -0
- package/docs/aggregator.md +0 -22
- package/docs/bot.md +0 -8
- package/docs/cursor-pages.md +0 -2
- 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/functions.gen.ts +1 -1
- package/src/config/generated.ts +77 -0
- package/src/evm/chains.ts +3 -28
- package/src/evm/router.ts +1 -26
- package/src/evm/squid.ts +3 -3
- package/src/index.ts +1 -0
- package/src/indexer/bodies.ts +4 -0
- package/src/math/v2/book.ts +42 -7
- package/src/math/v2/create.ts +1 -1
- package/src/math/v2/relay.ts +208 -1
- package/src/math/v2/split.ts +70 -16
- package/src/math/v2/trade.ts +16 -8
- 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/evm.ts +5 -1
- package/src/v2/layouts.ts +5 -1
- package/src/v2/router.ts +2 -2
- package/src/v2/solanaSettle.ts +2 -0
- package/src/v2/types.ts +4 -1
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { Address, beginCell, bytesOfBase64, fromBoc } from "./cell.js";
|
|
4
|
+
|
|
5
|
+
import { addr, accountAddress as deriveAccount } from "./addresses.js";
|
|
6
|
+
|
|
7
|
+
export const intItem = (value ) => ({ type: "int", value: BigInt(value) });
|
|
8
|
+
|
|
9
|
+
export const addressItem = (a ) => ({ type: "slice", cell: beginCell().storeAddress(a === null ? null : addr(a)).endCell() });
|
|
10
|
+
|
|
11
|
+
export class StackError extends Error {}
|
|
12
|
+
|
|
13
|
+
const int = (s , i , name ) => {
|
|
14
|
+
const x = s[i];
|
|
15
|
+
if (!x || x.type !== "int") throw new StackError(`${name}: expected an int at ${i}`);
|
|
16
|
+
return x.value;
|
|
17
|
+
};
|
|
18
|
+
const bool = (s , i , name ) => int(s, i, name) !== 0n;
|
|
19
|
+
const cell = (s , i , name ) => {
|
|
20
|
+
const x = s[i];
|
|
21
|
+
if (!x || (x.type !== "cell" && x.type !== "slice")) throw new StackError(`${name}: expected a cell at ${i}`);
|
|
22
|
+
return x.cell;
|
|
23
|
+
};
|
|
24
|
+
const address = (s , i , name ) => {
|
|
25
|
+
const x = s[i];
|
|
26
|
+
if (!x) throw new StackError(`${name}: missing item ${i}`);
|
|
27
|
+
if (x.type === "null") return null;
|
|
28
|
+
if (x.type !== "slice" && x.type !== "cell") throw new StackError(`${name}: expected an address at ${i}`);
|
|
29
|
+
return x.cell.beginParse().loadAddress();
|
|
30
|
+
};
|
|
31
|
+
const need = (s , n , name ) => {
|
|
32
|
+
if (s.length < n) throw new StackError(`${name}: ${s.length} stack items, expected ${n}`);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const parseNum = (v ) => {
|
|
36
|
+
const t = String(v);
|
|
37
|
+
return t.startsWith("-") ? -BigInt(t.slice(1)) : BigInt(t);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export function parseToncenterStack(raw ) {
|
|
41
|
+
return raw.map((e) => {
|
|
42
|
+
let type ;
|
|
43
|
+
let v ;
|
|
44
|
+
if (Array.isArray(e)) [type, v] = e ;
|
|
45
|
+
else if (e && typeof e === "object" && typeof (e )["@type"] === "string") {
|
|
46
|
+
|
|
47
|
+
const t = (e )["@type"] ;
|
|
48
|
+
if (t === "tvm.stackEntryNumber") { type = "num"; v = (e ).number?.number ?? (e ).number; }
|
|
49
|
+
else if (t === "tvm.stackEntryCell") { type = "cell"; v = (e ).cell; }
|
|
50
|
+
else if (t === "tvm.stackEntrySlice") { type = "slice"; v = (e ).slice; }
|
|
51
|
+
else if (t === "tvm.stackEntryTuple") { type = "tuple"; v = (e ).tuple; }
|
|
52
|
+
else if (t === "tvm.stackEntryList") { type = "list"; v = (e ).list; }
|
|
53
|
+
else if (t === "tvm.stackEntryUnsupported") { type = "null"; v = null; }
|
|
54
|
+
else throw new StackError(`unknown stack item type ${t}`);
|
|
55
|
+
} else {
|
|
56
|
+
type = (e ).type;
|
|
57
|
+
v = (e ).value;
|
|
58
|
+
}
|
|
59
|
+
switch (type) {
|
|
60
|
+
case "num":
|
|
61
|
+
case "int":
|
|
62
|
+
return { type: "int", value: parseNum(v) };
|
|
63
|
+
case "cell":
|
|
64
|
+
return { type: "cell", cell: fromBoc(bytesOfBase64(typeof v === "string" ? v : v.bytes)) };
|
|
65
|
+
case "slice":
|
|
66
|
+
case "cell_slice":
|
|
67
|
+
return { type: "slice", cell: fromBoc(bytesOfBase64(typeof v === "string" ? v : v.bytes)) };
|
|
68
|
+
case "null":
|
|
69
|
+
return { type: "null" };
|
|
70
|
+
case "tuple":
|
|
71
|
+
case "list": {
|
|
72
|
+
const els = v?.elements ?? v ?? [];
|
|
73
|
+
|
|
74
|
+
if (els.length === 0) return { type: "null" };
|
|
75
|
+
return { type: "tuple", items: parseToncenterStack(els) };
|
|
76
|
+
}
|
|
77
|
+
default:
|
|
78
|
+
throw new StackError(`unknown stack item type ${type}`);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function parseCoinsMap(root , keyBits ) {
|
|
84
|
+
const out = new Map ();
|
|
85
|
+
if (!root) return out;
|
|
86
|
+
const walk = (c , prefix , prefixLen ) => {
|
|
87
|
+
const s = c.beginParse();
|
|
88
|
+
const m = keyBits - prefixLen;
|
|
89
|
+
|
|
90
|
+
let lbl = 0n;
|
|
91
|
+
let len = 0;
|
|
92
|
+
const lenBits = (n ) => Math.ceil(Math.log2(n + 1));
|
|
93
|
+
if (!s.loadBit()) {
|
|
94
|
+
|
|
95
|
+
while (s.loadBit()) len++;
|
|
96
|
+
lbl = len > 0 ? s.loadUint(len) : 0n;
|
|
97
|
+
} else if (!s.loadBit()) {
|
|
98
|
+
len = Number(s.loadUint(lenBits(m)));
|
|
99
|
+
lbl = len > 0 ? s.loadUint(len) : 0n;
|
|
100
|
+
} else {
|
|
101
|
+
const bit = s.loadBit();
|
|
102
|
+
len = Number(s.loadUint(lenBits(m)));
|
|
103
|
+
lbl = bit ? (1n << BigInt(len)) - 1n : 0n;
|
|
104
|
+
}
|
|
105
|
+
const pfx = (prefix << BigInt(len)) | lbl;
|
|
106
|
+
const plen = prefixLen + len;
|
|
107
|
+
if (plen === keyBits) {
|
|
108
|
+
out.set(pfx, s.loadCoins());
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const l = s.loadRef();
|
|
113
|
+
const r = s.loadRef();
|
|
114
|
+
walk(l, pfx << 1n, plen + 1);
|
|
115
|
+
walk(r, (pfx << 1n) | 1n, plen + 1);
|
|
116
|
+
};
|
|
117
|
+
walk(root, 0n, 0);
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function feesOf(s , i , name ) {
|
|
122
|
+
const x = s[i];
|
|
123
|
+
if (!x || x.type !== "tuple" || x.items.length < 5) throw new StackError(`${name}: expected a 5-int tuple at ${i}`);
|
|
124
|
+
const [backing, team, platform, floor, holder] = [0, 1, 2, 3, 4].map((k) => int(x.items, k, `${name}[${k}]`));
|
|
125
|
+
return { backing: backing , team: team , platform: platform , floor: floor , holder: holder };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function run(rpc , a , method , stack = []) {
|
|
129
|
+
return rpc.runGetMethod(addr(a), method, stack);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export async function getLaunchState(rpc , launch ) {
|
|
133
|
+
const s = await run(rpc, launch, "get_launch_state");
|
|
134
|
+
need(s, 14, "get_launch_state");
|
|
135
|
+
return {
|
|
136
|
+
id: int(s, 0, "id"), factory: address(s, 1, "factory"), creator: address(s, 2, "creator"), quote: address(s, 3, "quote"),
|
|
137
|
+
presetId: int(s, 4, "preset_id"), graduated: bool(s, 5, "phase"), supply: int(s, 6, "supply"), circulating: int(s, 7, "circulating"),
|
|
138
|
+
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"),
|
|
139
|
+
reserve: int(s, 13, "reserve"),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export async function getLaunchBook(rpc , launch ) {
|
|
144
|
+
const s = await run(rpc, launch, "get_launch_book");
|
|
145
|
+
need(s, 1, "get_launch_book");
|
|
146
|
+
return cell(s, 0, "book");
|
|
147
|
+
}
|
|
148
|
+
export async function getLaunchMilestones(rpc , launch ) {
|
|
149
|
+
return cell(await run(rpc, launch, "get_launch_milestones"), 0, "milestones");
|
|
150
|
+
}
|
|
151
|
+
export async function getFeeCurve(rpc , launch ) {
|
|
152
|
+
return cell(await run(rpc, launch, "get_fee_curve"), 0, "curve");
|
|
153
|
+
}
|
|
154
|
+
export async function getCirculating(rpc , launch ) {
|
|
155
|
+
return int(await run(rpc, launch, "get_circulating"), 0, "s_circ");
|
|
156
|
+
}
|
|
157
|
+
export async function getBidMoney(rpc , launch ) {
|
|
158
|
+
const s = await run(rpc, launch, "get_bid_money");
|
|
159
|
+
need(s, 4, "get_bid_money");
|
|
160
|
+
return { f: int(s, 0, "f"), c: int(s, 1, "c"), k: int(s, 2, "k"), moneyInPlace: int(s, 3, "money_in_place") };
|
|
161
|
+
}
|
|
162
|
+
export async function getHolderBook(rpc , launch ) {
|
|
163
|
+
const s = await run(rpc, launch, "get_holder_book");
|
|
164
|
+
need(s, 3, "get_holder_book");
|
|
165
|
+
return { indexX64: int(s, 0, "index_x64"), w: int(s, 1, "w"), bucket: int(s, 2, "bucket") };
|
|
166
|
+
}
|
|
167
|
+
export async function getTeamShare(rpc , launch , place ) {
|
|
168
|
+
const s = await run(rpc, launch, "get_team_share", [intItem(place)]);
|
|
169
|
+
need(s, 2, "get_team_share");
|
|
170
|
+
return { owed: int(s, 0, "owed"), bought: int(s, 1, "bought") };
|
|
171
|
+
}
|
|
172
|
+
export async function getGasParams(rpc , launch ) {
|
|
173
|
+
const s = await run(rpc, launch, "get_gas_params");
|
|
174
|
+
need(s, 4, "get_gas_params");
|
|
175
|
+
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") };
|
|
176
|
+
}
|
|
177
|
+
export async function getQuoteWallet(rpc , launch ) {
|
|
178
|
+
return address(await run(rpc, launch, "get_quote_wallet"), 0, "wallet");
|
|
179
|
+
}
|
|
180
|
+
export async function getQuoteBooks(rpc , launch ) {
|
|
181
|
+
const s = await run(rpc, launch, "get_quote_books");
|
|
182
|
+
need(s, 5, "get_quote_books");
|
|
183
|
+
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") };
|
|
184
|
+
}
|
|
185
|
+
export async function getWalletAddress(rpc , master , owner ) {
|
|
186
|
+
return address(await run(rpc, master, "get_wallet_address", [addressItem(owner)]), 0, "wallet");
|
|
187
|
+
}
|
|
188
|
+
export async function getLaunchAddress(rpc , factory , id ) {
|
|
189
|
+
return address(await run(rpc, factory, "get_launch_address", [intItem(id)]), 0, "launch");
|
|
190
|
+
}
|
|
191
|
+
export async function getAccountAddress(rpc , launch , owner ) {
|
|
192
|
+
return address(await run(rpc, launch, "get_account_address", [addressItem(owner)]), 0, "account");
|
|
193
|
+
}
|
|
194
|
+
export async function getPosition(rpc , wallet ) {
|
|
195
|
+
const s = await run(rpc, wallet, "get_position");
|
|
196
|
+
need(s, 5, "get_position");
|
|
197
|
+
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") };
|
|
198
|
+
}
|
|
199
|
+
export async function getWalletData(rpc , wallet ) {
|
|
200
|
+
const s = await run(rpc, wallet, "get_wallet_data");
|
|
201
|
+
need(s, 3, "get_wallet_data");
|
|
202
|
+
return { balance: int(s, 0, "balance"), owner: address(s, 1, "owner"), master: address(s, 2, "master") };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export async function simBuy(rpc , launch , money , now ) {
|
|
206
|
+
const s = await run(rpc, launch, "sim_buy", [intItem(money), intItem(now)]);
|
|
207
|
+
need(s, 6, "sim_buy");
|
|
208
|
+
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")) };
|
|
209
|
+
}
|
|
210
|
+
export async function simSell(rpc , launch , tokens , now ) {
|
|
211
|
+
const s = await run(rpc, launch, "sim_sell", [intItem(tokens), intItem(now)]);
|
|
212
|
+
need(s, 3, "sim_sell");
|
|
213
|
+
return { out: int(s, 0, "out"), fees: feesOf(s, 1, "fees"), errorClass: Number(int(s, 2, "class")) };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export async function quoteBuyMoney(rpc , launch , tokens ) {
|
|
217
|
+
return int(await run(rpc, launch, "quote_buy", [intItem(tokens)]), 0, "money");
|
|
218
|
+
}
|
|
219
|
+
export async function quoteSellTokens(rpc , launch , out ) {
|
|
220
|
+
return int(await run(rpc, launch, "quote_sell", [intItem(out)]), 0, "tokens");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export async function getOwed(rpc , account ) {
|
|
224
|
+
const s = await run(rpc, account, "get_owed");
|
|
225
|
+
need(s, 3, "get_owed");
|
|
226
|
+
const m = s[0];
|
|
227
|
+
return {
|
|
228
|
+
owed: parseCoinsMap(m && m.type !== "null" && m.type !== "int" ? (m ).cell : null, 16),
|
|
229
|
+
teamBuyLockUntil: int(s, 1, "team_buy_lock_until"), teamBuyTokens: int(s, 2, "team_buy_tokens"),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export async function getOwedOf(rpc , chain , launch , owner ) {
|
|
234
|
+
return getOwed(rpc, deriveAccount(chain, launch, owner));
|
|
235
|
+
}
|
|
236
|
+
export async function getInFlight(rpc , account , payoutId ) {
|
|
237
|
+
const s = await run(rpc, account, "get_in_flight", [intItem(payoutId)]);
|
|
238
|
+
need(s, 4, "get_in_flight");
|
|
239
|
+
return { quote: address(s, 0, "quote"), amount: int(s, 1, "amount"), bit: Number(int(s, 2, "bit")), sentAt: int(s, 3, "sent_at") };
|
|
240
|
+
}
|
|
241
|
+
export async function getConfig(rpc , factory )
|
|
242
|
+
|
|
243
|
+
{
|
|
244
|
+
const s = await run(rpc, factory, "get_config");
|
|
245
|
+
need(s, 13, "get_config");
|
|
246
|
+
return {
|
|
247
|
+
authority: address(s, 0, "authority"), pendingAuthority: address(s, 1, "pending_authority"), timelock: address(s, 2, "timelock"), treasury: address(s, 3, "treasury"),
|
|
248
|
+
createPaused: bool(s, 4, "create_paused"), nativeCreateFee: int(s, 5, "native_create_fee"), referralAuthority: int(s, 6, "referral_authority"),
|
|
249
|
+
priceUpdater: int(s, 7, "price_updater"), holderDest: address(s, 8, "holder_dest"), metadataBase: s[9]?.type === "null" ? null : cell(s, 9, "metadata_base"),
|
|
250
|
+
launchCount: int(s, 10, "launch_count"), nextPresetId: int(s, 11, "next_preset_id"), codeVersion: int(s, 12, "code_version"),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
export async function getQuote(rpc , factory , master ) {
|
|
254
|
+
const s = await run(rpc, factory, "get_quote", [addressItem(master)]);
|
|
255
|
+
need(s, 3, "get_quote");
|
|
256
|
+
return { entry: cell(s, 0, "entry"), usdCentsX64: int(s, 1, "usd_cents_x64"), validUntil: int(s, 2, "valid_until") };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export async function getTonQuotePrice(rpc , factory , quote ) {
|
|
260
|
+
const s = await run(rpc, factory, "get_quote", [addressItem(quote)]);
|
|
261
|
+
need(s, 3, "get_quote");
|
|
262
|
+
const usdCentsX64 = int(s, 1, "usd_cents_x64");
|
|
263
|
+
const validUntil = int(s, 2, "valid_until");
|
|
264
|
+
if (s[0] .type === "null") return { listed: false, entry: null, usdCentsX64, validUntil };
|
|
265
|
+
return { listed: true, entry: decodeTonQuoteEntry(cell(s, 0, "entry")), usdCentsX64, validUntil };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export function decodeTonQuoteEntry(c ) {
|
|
269
|
+
const s = c.beginParse();
|
|
270
|
+
const kind = Number(s.loadUint(1)) ;
|
|
271
|
+
const master = s.loadAddress();
|
|
272
|
+
const decimals = Number(s.loadUint(8));
|
|
273
|
+
const walletKind = Number(s.loadUint(8));
|
|
274
|
+
const walletCodeHash = s.loadUint(256);
|
|
275
|
+
const walletCode = s.loadMaybeRef();
|
|
276
|
+
const createFee = s.loadCoins();
|
|
277
|
+
const issuerCanFreeze = s.loadBit();
|
|
278
|
+
const createsEnabled = s.loadBit();
|
|
279
|
+
const cap = s.loadCoins();
|
|
280
|
+
s.endParse();
|
|
281
|
+
return { kind, master, decimals, walletKind, walletCodeHash, walletCode, createFee, issuerCanFreeze, createsEnabled, cap };
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export function parseRefMap(root , keyBits ) {
|
|
285
|
+
const out = new Map ();
|
|
286
|
+
if (!root) return out;
|
|
287
|
+
const lenBits = (n ) => Math.ceil(Math.log2(n + 1));
|
|
288
|
+
const walk = (c , prefix , prefixLen ) => {
|
|
289
|
+
const s = c.beginParse();
|
|
290
|
+
const m = keyBits - prefixLen;
|
|
291
|
+
let lbl = 0n;
|
|
292
|
+
let len = 0;
|
|
293
|
+
if (!s.loadBit()) {
|
|
294
|
+
while (s.loadBit()) len++;
|
|
295
|
+
lbl = len > 0 ? s.loadUint(len) : 0n;
|
|
296
|
+
} else if (!s.loadBit()) {
|
|
297
|
+
len = Number(s.loadUint(lenBits(m)));
|
|
298
|
+
lbl = len > 0 ? s.loadUint(len) : 0n;
|
|
299
|
+
} else {
|
|
300
|
+
const bit = s.loadBit();
|
|
301
|
+
len = Number(s.loadUint(lenBits(m)));
|
|
302
|
+
lbl = bit ? (1n << BigInt(len)) - 1n : 0n;
|
|
303
|
+
}
|
|
304
|
+
const pfx = (prefix << BigInt(len)) | lbl;
|
|
305
|
+
const plen = prefixLen + len;
|
|
306
|
+
if (plen === keyBits) {
|
|
307
|
+
out.set(pfx, s.loadRef());
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
const l = s.loadRef();
|
|
311
|
+
const r = s.loadRef();
|
|
312
|
+
walk(l, pfx << 1n, plen + 1);
|
|
313
|
+
walk(r, (pfx << 1n) | 1n, plen + 1);
|
|
314
|
+
};
|
|
315
|
+
walk(root, 0n, 0);
|
|
316
|
+
return out;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export function decodeTonSlotPlace(c , place ) {
|
|
320
|
+
const s = c.beginParse();
|
|
321
|
+
const member = s.loadAddress();
|
|
322
|
+
const handle = s.loadBit() ? s.loadUint(256) : null;
|
|
323
|
+
const shares = s.loadUint(64);
|
|
324
|
+
const weightPpb = s.loadUint(32);
|
|
325
|
+
const slotOwed = s.loadCoins();
|
|
326
|
+
const boughtOwed = s.loadCoins();
|
|
327
|
+
const teamBuyPart = s.loadCoins();
|
|
328
|
+
s.endParse();
|
|
329
|
+
return { place, member, handle, shares, weightPpb, slotOwed, boughtOwed, teamBuyPart };
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export async function getTeamSlot(rpc , launch ) {
|
|
333
|
+
const s = await run(rpc, launch, "get_team_slot");
|
|
334
|
+
need(s, 5, "get_team_slot");
|
|
335
|
+
const d = s[4];
|
|
336
|
+
const dict = d && d.type !== "null" && d.type !== "int" ? (d ).cell : null;
|
|
337
|
+
const places = [...parseRefMap(dict, 4)].sort((a, b) => (a[0] < b[0] ? -1 : 1)).map(([k, c]) => decodeTonSlotPlace(c, Number(k)));
|
|
338
|
+
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 };
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export async function getPresetRow(rpc , factory , id ) {
|
|
342
|
+
const s = await run(rpc, factory, "get_preset_row", [intItem(id)]);
|
|
343
|
+
need(s, 6, "get_preset_row");
|
|
344
|
+
const r = s[0];
|
|
345
|
+
const row = r && r.type !== "null" && r.type !== "int" ? (r ).cell : null;
|
|
346
|
+
let rowBytes = null;
|
|
347
|
+
if (row) {
|
|
348
|
+
const parts = [];
|
|
349
|
+
for (let cur = row; cur; ) {
|
|
350
|
+
const sl = cur.beginParse();
|
|
351
|
+
parts.push(sl.loadBytes(sl.remainingBits / 8));
|
|
352
|
+
cur = sl.remainingRefs ? sl.loadRef() : null;
|
|
353
|
+
}
|
|
354
|
+
rowBytes = new Uint8Array(parts.reduce((a, p) => a + p.length, 0));
|
|
355
|
+
let o = 0;
|
|
356
|
+
for (const p of parts) (rowBytes.set(p, o), (o += p.length));
|
|
357
|
+
}
|
|
358
|
+
return {
|
|
359
|
+
found: row !== null, row, rowBytes, enabled: bool(s, 1, "enabled"), deleted: bool(s, 2, "deleted"), checked: bool(s, 3, "checked"),
|
|
360
|
+
version: int(s, 4, "version"), hash: int(s, 5, "hash"),
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export async function getTraderAddress(rpc , factory , trader ) {
|
|
365
|
+
return address(await run(rpc, factory, "get_trader_address", [addressItem(trader)]), 0, "trader");
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export async function getFamily(rpc , factory , family ) {
|
|
369
|
+
if (!Number.isInteger(family) || family < 0 || family > 4) throw new RangeError("family must be 0 to 4");
|
|
370
|
+
const s = await run(rpc, factory, "get_family", [intItem(family)]);
|
|
371
|
+
need(s, 3, "get_family");
|
|
372
|
+
return { version: int(s, 0, "version"), initHash: int(s, 1, "init_hash"), codeHash: int(s, 2, "code_hash") };
|
|
373
|
+
}
|
|
374
|
+
export async function getTimelockInfo(rpc , timelock ) {
|
|
375
|
+
const s = await run(rpc, timelock, "get_timelock");
|
|
376
|
+
need(s, 3, "get_timelock");
|
|
377
|
+
return { admin: address(s, 0, "admin"), factory: address(s, 1, "factory"), delay: int(s, 2, "delay") };
|
|
378
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_GAS = {
|
|
4
|
+
buyFwdMin: 300_000_000n,
|
|
5
|
+
sellFwdMin: 300_000_000n,
|
|
6
|
+
refundFwdMin: 60_000_000n,
|
|
7
|
+
reclaimAfter: 3600n,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const TON_CLAIM = {
|
|
11
|
+
CREATOR: 1,
|
|
12
|
+
CREATOR_REF: 2,
|
|
13
|
+
TEAM_SLOT: 4,
|
|
14
|
+
TRADER_REF: 8,
|
|
15
|
+
EXTRA_RESERVED: 32,
|
|
16
|
+
PAYOUT: 64,
|
|
17
|
+
TEAM_BUY: 128,
|
|
18
|
+
SHARE_BOUGHT: 256,
|
|
19
|
+
HOLDER: 512,
|
|
20
|
+
} ;
|
|
21
|
+
export const TON_CLAIM_KNOWN = 975;
|
|
22
|
+
|
|
23
|
+
export const TON_WALK_STEPS = 16;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
export const REFERRED_HOP = 60_000_000n;
|
|
28
|
+
|
|
29
|
+
export const REFERRED_FWD_MIN = 240_000_000n;
|
|
30
|
+
|
|
31
|
+
export const REFERRED_SELL_FWD_MIN = 240_000_000n;
|
|
32
|
+
|
|
33
|
+
export const REFERRED_GIFT_FWD_MIN = REFERRED_FWD_MIN + REFERRED_HOP;
|
|
34
|
+
|
|
35
|
+
export const REFERRED_FWD_DEFAULT = DEFAULT_GAS.buyFwdMin + REFERRED_HOP;
|
|
36
|
+
export const REFERRED_SELL_FWD_DEFAULT = DEFAULT_GAS.sellFwdMin + REFERRED_HOP;
|
|
37
|
+
export const REFERRED_GIFT_FWD_DEFAULT = REFERRED_FWD_DEFAULT + REFERRED_HOP;
|
|
38
|
+
export const REFERRED_SELL_GIFT_FWD_DEFAULT = REFERRED_SELL_FWD_DEFAULT + REFERRED_HOP;
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { base64Of, stateInitCell, toBoc } from "./cell.js";
|
|
4
|
+
|
|
5
|
+
const VALID_FOR_DEFAULT = 300;
|
|
6
|
+
const VALID_FOR_MAX = 600;
|
|
7
|
+
const MAX_MESSAGES_DEFAULT = 4;
|
|
8
|
+
|
|
9
|
+
export function tonConnectRequest(tx , o ) {
|
|
10
|
+
const max = o.maxMessages ?? MAX_MESSAGES_DEFAULT;
|
|
11
|
+
const n = tx.messages.length;
|
|
12
|
+
if (n < 1 || n > max) throw new RangeError(`a request carries 1 to ${max} messages, got ${n}`);
|
|
13
|
+
const validFor = o.validForS ?? VALID_FOR_DEFAULT;
|
|
14
|
+
if (!Number.isInteger(validFor) || validFor < 1 || validFor > VALID_FOR_MAX) throw new RangeError("validForS must be 1 to 600");
|
|
15
|
+
if (!Number.isInteger(o.nowS) || o.nowS < 0) throw new RangeError("nowS must be a non-negative integer (seconds)");
|
|
16
|
+
const messages = tx.messages.map((m) => {
|
|
17
|
+
const out = {
|
|
18
|
+
address: m.to.toString({ bounceable: m.bounce, urlSafe: true }),
|
|
19
|
+
amount: m.value.toString(),
|
|
20
|
+
payload: base64Of(toBoc(m.body)),
|
|
21
|
+
};
|
|
22
|
+
if (m.stateInit) out.stateInit = base64Of(toBoc(stateInitCell(m.stateInit.code, m.stateInit.data)));
|
|
23
|
+
return out;
|
|
24
|
+
});
|
|
25
|
+
return { validUntil: o.nowS + validFor, messages };
|
|
26
|
+
}
|
package/dist/v2/evm.js
CHANGED
|
@@ -20,7 +20,7 @@ export const CLAIM_KNOWN_V2_EVM = CLAIM_KNOWN_MASKS.evm.v2;
|
|
|
20
20
|
|
|
21
21
|
const BOOK_RANGE = "(uint128,uint128,uint64,uint64,uint64,uint128,uint16,uint16,uint8,uint8)";
|
|
22
22
|
|
|
23
|
-
const LAUNCH_BOOK = `(uint128,uint128,uint128,uint128[],uint8,${BOOK_RANGE}[48],uint128,uint64,uint64[],uint128[],uint8,uint8,uint128[],uint128[],uint128,uint64,bool,uint32[5])`;
|
|
23
|
+
const LAUNCH_BOOK = `(uint128,uint128,uint128,uint128[],uint8,${BOOK_RANGE}[48],uint128,uint64,uint64[],uint128[],uint8,uint8,uint128[],uint128[],uint128,uint64,bool,uint32[5],uint128,uint64,bool)`;
|
|
24
24
|
|
|
25
25
|
const BUY_OUT = "(uint256,uint256,uint256,uint128,uint8,bool,bool)";
|
|
26
26
|
|
|
@@ -129,6 +129,7 @@ export function decodeLaunchBook(data ) {
|
|
|
129
129
|
sqrtP: big(t[0]), sqrtF: big(t[1]), f: big(t[2]), bandMoney: bigs(t[3]), nRanges: nR, ranges,
|
|
130
130
|
sqrtLMax: big(t[6]), floorTokens: big(t[7]), bandTokens: bigs(t[8]), bandEdge: bigs(t[9]), nBands: n(t[10]), nC: n(t[11]),
|
|
131
131
|
bandF: bigs(t[12]), bandFClaim: bigs(t[13]), ckAtF: big(t[14]), ckFloorTokens: big(t[15]), graduated: t[16] , feePpm: nums(t[17]),
|
|
132
|
+
kAtF: big(t[18]), kFloorTokens: big(t[19]), kpot: t[20] ,
|
|
132
133
|
};
|
|
133
134
|
}
|
|
134
135
|
export function decodeSimBuy(data ) {
|
|
@@ -253,6 +254,7 @@ export function evmSettleInputsV2(b , row , sup , m
|
|
|
253
254
|
bandEdge: pad(b.bandEdge, BIDS_MAX + 1, 0n).slice(0, BIDS_MAX + 1), bandMoney: pad(b.bandMoney, BIDS_MAX, 0n).slice(0, BIDS_MAX),
|
|
254
255
|
bandTokens: pad(b.bandTokens, BIDS_MAX, 0n).slice(0, BIDS_MAX), bandF: pad(b.bandF, BIDS_MAX, 0n).slice(0, BIDS_MAX),
|
|
255
256
|
bandFClaim: pad(b.bandFClaim, BIDS_MAX, 0n).slice(0, BIDS_MAX), ckAtF: b.ckAtF, ckFloorTokens: b.ckFloorTokens,
|
|
257
|
+
kpot: b.kpot, kAtF: b.kAtF, kFloorTokens: b.kFloorTokens,
|
|
256
258
|
feePpm: [...b.feePpm], graduated: b.graduated,
|
|
257
259
|
|
|
258
260
|
feeStartPpm: curve ? [...curve.feeStartPpm] : [0, 0, 0, 0, 0], sqrtFeeA: curve?.sqrtFeeA ?? 0n, sqrtFeeB: curve?.sqrtFeeB ?? 0n,
|
package/dist/v2/layouts.js
CHANGED
|
@@ -130,7 +130,11 @@ export const LAUNCH_V2 = [
|
|
|
130
130
|
["backing_credited", "u64"],
|
|
131
131
|
["incinerated", "u64"],
|
|
132
132
|
["last_ts", "i64"],
|
|
133
|
-
|
|
133
|
+
|
|
134
|
+
["k_at_f", "u64"],
|
|
135
|
+
["k_floor_tokens", "u64"],
|
|
136
|
+
["kpot", "u8"],
|
|
137
|
+
["pad_end", "bytes:15"],
|
|
134
138
|
];
|
|
135
139
|
|
|
136
140
|
export const HOLDER_POSITION = [
|
package/dist/v2/router.js
CHANGED
|
@@ -8,9 +8,9 @@ export function carriesNoRefund(gross , refund , budgetHit
|
|
|
8
8
|
return refund === 0n || isDustRefund(gross, refund, budgetHit);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export const GAS_FLAT = { buy:
|
|
11
|
+
export const GAS_FLAT = { buy: 1_100_000, sell: 850_000 } ;
|
|
12
12
|
|
|
13
|
-
export const GAS_PER_STEP = { buy:
|
|
13
|
+
export const GAS_PER_STEP = { buy: 45_000, sell: 40_000 } ;
|
|
14
14
|
|
|
15
15
|
export const GAS_FLAT_STEPS = 4;
|
|
16
16
|
|
package/dist/v2/solanaSettle.js
CHANGED
|
@@ -52,6 +52,8 @@ export function solanaSettleInputsV2(l , opts
|
|
|
52
52
|
nBands: l.nBands,
|
|
53
53
|
bandEdge: [...l.bandEdge], bandMoney: [...l.bandMoney], bandTokens: [...l.bandTokens],
|
|
54
54
|
nC: l.nC, bandF: [...l.bandF], bandFClaim: [...l.bandFClaim], ckAtF: l.ckAtF, ckFloorTokens: l.ckFloorTokens,
|
|
55
|
+
|
|
56
|
+
kpot: l.kpot !== 0, kAtF: l.kAtF, kFloorTokens: l.kFloorTokens,
|
|
55
57
|
feePpm: l.feePpm.map(n), feeStartPpm: l.feeStartPpm.map(n), sqrtFeeA: l.sqrtFeeA, sqrtFeeB: l.sqrtFeeB,
|
|
56
58
|
graduated: l.graduated !== 0, nRanges: l.nRanges, ranges,
|
|
57
59
|
|
package/docs/aggregator.md
CHANGED
|
@@ -51,33 +51,11 @@ const call = evmRouteCallV2(q, { router, to: recipient, deadline });
|
|
|
51
51
|
// { to, data, ... }: send it from the trader's wallet
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
## Pay with another coin (EVM zap)
|
|
55
|
-
|
|
56
|
-
A buyer who holds the native coin, or an ERC-20 that is not the launch's quote, buys through a FloorZap, which swaps into the quote and buys in one transaction.
|
|
57
|
-
|
|
58
|
-
- Addresses: `FLOOR_ZAP_ADDRESSES` (`@floorlaunchpad/sdk/evm/chains`) holds the deployed zap per chain and router slot, 15 instances on 8 chains. Each `EVM_CHAINS` zap row carries its own `zap`, `null` where that slot is not deployed. Keep no copy of your own.
|
|
59
|
-
- Swap calldata: `zapSwapData` (`@floorlaunchpad/sdk/evm/zap`) builds the zap's `swapData`. The input is the native coin (the default) or an ERC-20 (`input: "token"`). The output is the launch's ERC-20 quote (the default) or, for a launch quoted in the native coin, the native coin (`output: "native"`).
|
|
60
|
-
- A Universal Router fork row passes that row's `urFork` (`"uniswap"`, `"aerodrome"`, `"pancake"` or `"ramses"`). Uniswap v4 is one pool given as `route.v4`. A native-input Universal Router swap ends with a `SWEEP`, so anything the swap did not spend goes back to the zap, which refunds it.
|
|
61
|
-
- Bridged buys: `buyHookNative` (in `src/evm/squid.ts`) builds the destination-chain hook calls. Pass the launch's `quote`. For an ERC-20 quote the hook adds a third call that passes the quote refund on to the user. Absent or address(0), it is the two calls of 0.4.0.
|
|
62
|
-
|
|
63
|
-
## FloorRouter addresses (EVM)
|
|
64
|
-
|
|
65
|
-
`evmRouteCallV2` takes the FloorRouter's address as `router`. The SDK books one per chain and zap slot: `FLOOR_ROUTER_ADDRESSES` and each zap row's `floorRouter` (`@floorlaunchpad/sdk/evm/chains`), the same address for a slot on every chain that has it. They are derived ahead of the routers' deploy, so an address is usable only once it has code on that chain. Before then a call to it still succeeds and buys nothing, and a native-in buy's coin goes to the empty address and is lost. Check it first (`getCode` answering "0x" or `undefined` is no code):
|
|
66
|
-
|
|
67
|
-
```ts
|
|
68
|
-
import { FLOOR_ROUTER_ADDRESSES } from "@floorlaunchpad/sdk/evm/chains";
|
|
69
|
-
import { assertFloorRouterLive } from "@floorlaunchpad/sdk/evm/router";
|
|
70
|
-
|
|
71
|
-
const router = await assertFloorRouterLive({ getCode: (a) => rpc.getCode(a) }, { chain: "base", slot: "uniswap-ur" });
|
|
72
|
-
// throws while the router has no code; otherwise pass `router` to evmRouteCallV2
|
|
73
|
-
```
|
|
74
|
-
|
|
75
54
|
## Things to know
|
|
76
55
|
|
|
77
56
|
- The SDK never sends or signs. It returns instructions or calldata.
|
|
78
57
|
- Fees are added on top of the amount in and come out of the quote you build the call from. Do not subtract them again.
|
|
79
58
|
- Every launch trades from its first block and neither buys nor sells can be paused. A hop that fails does so because of the amount or the slippage bound, not a switch.
|
|
80
59
|
- Amounts are `bigint` in the coin's smallest unit on both chains.
|
|
81
|
-
- A failed EVM call decodes with `decodeEvmProgramError` (`@floorlaunchpad/sdk/errors`), which also knows the five errors the contracts' math libraries revert with: `PriceOrder()`, `ZeroLiquidity()`, `SqrtRange()`, `Zero()` and `VaultShareOutOfRange()`.
|
|
82
60
|
|
|
83
61
|
See also: [README](../README.md), [bot guide](bot.md) for reading launches to build your pool list.
|
package/docs/bot.md
CHANGED
|
@@ -55,14 +55,6 @@ Each candle carries `floorX64`, the floor at the bucket's close, in the same Q64
|
|
|
55
55
|
`null` where a bucket has none, and absent from an indexer older than this build. Use the launch's own `floorX64` for
|
|
56
56
|
that candle then. [floor-line.md](floor-line.md) shows how to draw it.
|
|
57
57
|
|
|
58
|
-
### Many launches in one request
|
|
59
|
-
|
|
60
|
-
`readLaunchLists(get, { quotes, cursors })` returns one `launches` page per quote coin (up to 16) in one answer, each list resumed with its own cursor (`"-"` asks a first page). `readCandlesMany(get, { ids, interval })` returns the newest candles of up to 40 launches at once. Both are in `@floorlaunchpad/sdk/indexer/read`; the limits are in [cursor-pages.md](cursor-pages.md).
|
|
61
|
-
|
|
62
|
-
### Dev buys through a zap or router
|
|
63
|
-
|
|
64
|
-
A buy through a zap or a router has the contract as the trade's `trader`. Pass the person that contract's own event names as `ctx.buyer` to `devBuyFromTrade` (`@floorlaunchpad/sdk/v2/devbuy`), and a creator's or team member's buy through it counts as a dev buy, with that person as `trader`. The trade's recipient alone never names one.
|
|
65
|
-
|
|
66
58
|
## Follow the live stream
|
|
67
59
|
|
|
68
60
|
```ts
|
package/docs/cursor-pages.md
CHANGED
|
@@ -22,8 +22,6 @@ newest page. Asked with none of these, each route answers its whole list in one
|
|
|
22
22
|
| `search?q=` | `readLaunchSearch` | `cursor` | `SEARCH_PAGE_DEFAULT` (12) | `SEARCH_PAGE_MAX` (100) |
|
|
23
23
|
| `wallets/<w>/positions`, `locks`, `claims`, `roles/<w>`, `referrals/<w>/people` | `readPositions`, `readWalletLocks`, `readClaimHistory`, `readRoles`, `readPeople` | `cursor` | `WALLET_PAGE_DEFAULT` (100) | `WALLET_PAGE_MAX` (500) |
|
|
24
24
|
| `wallets/<w>/inbox` | `readInbox` | `before` | `INBOX_PAGE_DEFAULT` (100) | `INBOX_PAGE_MAX` (500) |
|
|
25
|
-
| `launch-lists` (up to 16 quotes) | `readLaunchLists` | `cursors`, one per quote (`"-"` = its first page) | 100 per list | `limit` × quotes ≤ 1,000 rows |
|
|
26
|
-
| `candles/many` (up to 40 launches) | `readCandlesMany` | `before` | 1,000 candles per launch | `limit` × ids ≤ 40,000 candles |
|
|
27
25
|
|
|
28
26
|
No request answers every launch: a bare `launches` is one page of 100. The list body also carries `cursors` (the cursor
|
|
29
27
|
after each row) and `keys` (each row's ranked key); `launches` takes a `preset` filter.
|
package/docs/frontend.md
CHANGED
|
@@ -24,8 +24,6 @@ Use the routing functions in [docs/aggregator.md](aggregator.md). For a single l
|
|
|
24
24
|
|
|
25
25
|
- Route modules in `src/route` and `src/v2/route.ts` contain no host names, so a strict content security policy does not trip on them. Anything that talks to a hosted service is in `route-jupiter.ts` and is opt-in.
|
|
26
26
|
- Keep the quote fresh: re-quote when the user changes the amount and just before they sign.
|
|
27
|
-
- A buy paid in another coin goes through the chain's FloorZap: take its address from the zap row's `zap` (`FLOOR_ZAP_ADDRESSES`, `@floorlaunchpad/sdk/evm/chains`) and its swap from `zapSwapData`; [aggregator.md](aggregator.md) has the details.
|
|
28
|
-
- The create page's preset menu on EVM: `readPresetMenuEvmV2` (`@floorlaunchpad/sdk/v2/presetRowEvm`) reads the rows through one Multicall3 `aggregate3` per 100 ids. Pass `{ multicall }` for another Multicall3 address, or `{ multicall: null }` on a chain without one (one call per id). A row that fails throws; the menu never has a gap.
|
|
29
27
|
- Chain choice happens once, at the edge. Past that point the same quote and build calls work on both chains.
|
|
30
28
|
|
|
31
29
|
See also: [README](../README.md), [wallet guide](wallet.md).
|