@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
package/docs/ton.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# FLOOR on TON
|
|
2
|
+
|
|
3
|
+
> TON is not deployed yet: the module ships in `@floorlaunchpad/sdk` 0.6.0, switched off: the TON chain row stays off until a mainnet factory is live.
|
|
4
|
+
|
|
5
|
+
`@floorlaunchpad/sdk/ton` builds the messages a wallet sends to the FLOOR program on TON and reads what the program answers.
|
|
6
|
+
It holds no key, sends nothing and opens no connection of its own: you give it a read function (`TonRpc`) and a wallet.
|
|
7
|
+
Amounts are in nanoGRAM (GRAM has 9 decimals).
|
|
8
|
+
|
|
9
|
+
## Build a trade
|
|
10
|
+
|
|
11
|
+
A trade is a `TonTx`: `{ family: "ton", messages }`, each message with a destination, a value in nanoGRAM, a body cell and a
|
|
12
|
+
`bounce` flag. Build the chain once (`tonChainOf()` uses the built-in mainnet constants; see "Built-in constants"), then build the message:
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { tonChainOf, launchAddress, buildBuyGram, simBuy } from "@floorlaunchpad/sdk/ton";
|
|
16
|
+
|
|
17
|
+
const chain = tonChainOf(); // mainnet, from the SDK's own constants
|
|
18
|
+
const launch = launchAddress(chain, launchId); // needs the launch init code, see below
|
|
19
|
+
const quote = await simBuy(rpc, launch, 1_000_000_000n, BigInt(nowSeconds));
|
|
20
|
+
const tx = buildBuyGram({ launch, money: 1_000_000_000n, minTokens: quote.tokens * 99n / 100n, deadline: nowSeconds + 300, recipient: myAddress });
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`simBuy` and `simSell` run the program's own `get` methods on the launch: they are the quote path. There is no second
|
|
24
|
+
price formula in the SDK for TON. A builder refuses bad input (a zero amount, a deadline in the past) with a `RangeError`
|
|
25
|
+
before it makes a message.
|
|
26
|
+
|
|
27
|
+
`tonChainOf` can derive the wallet, account and trader addresses. It cannot derive a launch address, because the launch
|
|
28
|
+
init code is not in the book: `launchAddress` throws `launch init code not supplied` rather than guess. Pass the launch
|
|
29
|
+
address you read from the factory, or supply the code.
|
|
30
|
+
|
|
31
|
+
## Send it
|
|
32
|
+
|
|
33
|
+
`tonConnectRequest` turns a `TonTx` into the request a TON Connect wallet takes:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { tonConnectRequest } from "@floorlaunchpad/sdk/ton";
|
|
37
|
+
|
|
38
|
+
const request = tonConnectRequest(tx, { nowS: Math.floor(Date.now() / 1000) });
|
|
39
|
+
await tonConnectUi.sendTransaction(request);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Each message maps to `{ address, amount, payload, stateInit? }`: the address with its bounce flag, the value as a decimal
|
|
43
|
+
string, the body and any state init as base64. `validUntil` is `nowS` plus `validForS` (default 300, at most 600). A
|
|
44
|
+
request carries 1 to `maxMessages` messages (default 4); more is a `RangeError`. The function is pure.
|
|
45
|
+
|
|
46
|
+
## Read the result
|
|
47
|
+
|
|
48
|
+
A message that reaches the chain can still be refused by the program. Ask the indexer, by the wallet and the message's
|
|
49
|
+
query id:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { readTonOutcome } from "@floorlaunchpad/sdk";
|
|
53
|
+
|
|
54
|
+
const outcome = await readTonOutcome(get, walletAddress, queryId);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The answer says whether the message landed, was refused (with the program's error) or is not seen yet. Treat "not seen yet"
|
|
58
|
+
as pending, never as failed. Use a fresh `queryId` for each message.
|
|
59
|
+
|
|
60
|
+
## Built-in constants
|
|
61
|
+
|
|
62
|
+
The SDK carries TON mainnet's factory and timelock addresses and the three small init codes (wallet, account, trader) as
|
|
63
|
+
constants in a generated module (`TON_MAINNET`, `TON_INIT_CODES_BASE64`, `TON_PINNED_CODE_HASHES`). `tonChainOf()` with no
|
|
64
|
+
argument builds the mainnet chain from them: no file to fetch. The module is written by `node sdk/scripts/gen-ton-consts.mjs`
|
|
65
|
+
from the pinned codes (`ton/contracts/codes.mjs`) and the deploy output (`sdk/scripts/ton-mainnet-deploy.json`); `--check`
|
|
66
|
+
fails while the committed module differs. Mainnet is not deployed yet, so `TON_MAINNET.factory` and `.timelock` are `null`
|
|
67
|
+
(`placeholder: true`) and `tonChainOf()` throws `TonBookError` until the deploy output is filled in and the generator re-run.
|
|
68
|
+
|
|
69
|
+
## The book file (another network or deployment)
|
|
70
|
+
|
|
71
|
+
For a testnet or any other deployment, pass a book: a small JSON file for one network:
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"chain": "ton", "network": "mainnet", "globalId": -239,
|
|
76
|
+
"factory": "0:<64 hex>", "timelock": "0:<64 hex>",
|
|
77
|
+
"codeHashes": { "factory": "…", "timelock": "…", "launch": "…", "wallet": "…", "account": "…", "trader": "…" },
|
|
78
|
+
"familyInit": { "launch": "…", "account": "…", "trader": "…" },
|
|
79
|
+
"codes": { "wallet": "<base64 BoC>", "account": "<base64 BoC>", "trader": "<base64 BoC>" },
|
|
80
|
+
"readAt": "<ISO 8601 time>", "deploySeqno": 123456
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { parseTonBook, tonChainOf } from "@floorlaunchpad/sdk/ton";
|
|
86
|
+
const chain = tonChainOf(parseTonBook(JSON.parse(bookFileText), { file: "ton-testnet.json" }));
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
`network` is `mainnet` with `globalId` -239, or `testnet` with -3. `familyInit` and `deploySeqno` are optional; other keys
|
|
90
|
+
are ignored. `parseTonBook` checks every field and the three code cells against their hashes and the pinned code, and throws
|
|
91
|
+
`TonBookError` (`ton book <file>: <field>: <what>`) on the first fault. A book that parses derives addresses identical to
|
|
92
|
+
the chain's. `checkTonBookOnChain(rpc, book)` compares the book with the chain and returns a list of mismatches (empty means
|
|
93
|
+
consistent); run it from your own machine, not in a page.
|
|
94
|
+
|
|
95
|
+
## Gas
|
|
96
|
+
|
|
97
|
+
Every builder has a default value that covers the program's gas and forwarding on the current network prices. The claim
|
|
98
|
+
costs are priced in `gas.ts` from a `TonGasConfig` (basechain prices); the default is the mainnet config, and you can pass
|
|
99
|
+
a live one. Unused value comes back as a refund. A message that carries too little value is refused by the program, so
|
|
100
|
+
raise the value rather than lower it.
|
|
101
|
+
|
|
102
|
+
## What the SDK does not do
|
|
103
|
+
|
|
104
|
+
- It does not sign and it does not send. `tonConnectRequest` is the end of its work.
|
|
105
|
+
- It has no decoder for the book's cells beyond what `parseTonBook` checks, and no reader for the factory's internals.
|
|
106
|
+
- It has no price formula for TON: `simBuy` and `simSell` are the quote path.
|
|
107
|
+
- It does not guess an address it cannot derive: it throws.
|
package/docs/wallet.md
CHANGED
|
@@ -30,8 +30,6 @@ import { decodeErrorV2 } from "@floorlaunchpad/sdk/v2/evm";
|
|
|
30
30
|
const name = decodeErrorV2(revertData); // the custom error's name, or null
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
`decodeEvmProgramError` (`@floorlaunchpad/sdk/errors`) returns the same name with the module and code, and also knows five errors from the contracts' math libraries that the ABI does not list: `PriceOrder()`, `ZeroLiquidity()`, `SqrtRange()`, `Zero()` and `VaultShareOutOfRange()`.
|
|
34
|
-
|
|
35
33
|
Show the name and your own plain wording for it. The SDK gives you the identifier, not a sentence.
|
|
36
34
|
|
|
37
35
|
## Claim
|
package/examples/floor-line.html
CHANGED
|
@@ -238,7 +238,7 @@ const floor = floorOf(BigInt(event.sqrtF), quoteDecimals);</script>
|
|
|
238
238
|
</div></script>
|
|
239
239
|
|
|
240
240
|
<script>
|
|
241
|
-
const DATA = /*DATA*/{"run":"A simulated launch with a USDC quote at $1: 74 buys and 8 sells","quoteDecimals":6,"series":[{"i":0,"price":0.01,"floor":null,"graduated":false,"side":"open"},{"i":1,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":2,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":3,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":4,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":5,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":6,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":7,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":8,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":9,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":10,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":11,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":12,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":13,"price":0.01022274,"floor":0.01,"graduated":true,"side":"buy"},{"i":14,"price":0.01045981,"floor":0.01000702,"graduated":true,"side":"buy"},{"i":15,"price":0.01069961,"floor":0.01001356,"graduated":true,"side":"buy"},{"i":16,"price":0.01092692,"floor":0.01001968,"graduated":true,"side":"buy"},{"i":17,"price":0.01110845,"floor":0.01002545,"graduated":true,"side":"buy"},{"i":18,"price":0.0112915,"floor":0.0100309,"graduated":true,"side":"buy"},{"i":19,"price":0.01147605,"floor":0.01003607,"graduated":true,"side":"buy"},{"i":20,"price":0.0116621,"floor":0.01004098,"graduated":true,"side":"buy"},{"i":21,"price":0.01184832,"floor":0.01004568,"graduated":true,"side":"buy"},{"i":22,"price":0.0119884,"floor":0.01005016,"graduated":true,"side":"buy"},{"i":23,"price":0.01212932,"floor":0.01005447,"graduated":true,"side":"buy"},{"i":24,"price":0.01227106,"floor":0.0100586,"graduated":true,"side":"buy"},{"i":25,"price":0.01284634,"floor":0.01007293,"graduated":true,"side":"buy"},{"i":26,"price":0.01329322,"floor":0.01008562,"graduated":true,"side":"buy"},{"i":27,"price":0.01373598,"floor":0.01030198,"graduated":true,"side":"buy"},{"i":28,"price":0.01414542,"floor":0.01060907,"graduated":true,"side":"buy"},{"i":29,"price":0.01448348,"floor":0.01086261,"graduated":true,"side":"buy"},{"i":30,"price":0.01482555,"floor":0.01111917,"graduated":true,"side":"buy"},{"i":31,"price":0.01517165,"floor":0.01137874,"graduated":true,"side":"buy"},{"i":32,"price":0.01545607,"floor":0.01159206,"graduated":true,"side":"buy"},{"i":33,"price":0.0157178,"floor":0.01178835,"graduated":true,"side":"buy"},{"i":34,"price":0.01598174,"floor":0.01198631,"graduated":true,"side":"buy"},{"i":35,"price":0.01624789,"floor":0.01218592,"graduated":true,"side":"buy"},{"i":36,"price":0.01651626,"floor":0.0123872,"graduated":true,"side":"buy"},{"i":37,"price":0.01674282,"floor":0.01255712,"graduated":true,"side":"buy"},{"i":38,"price":0.01694468,"floor":0.01270851,"graduated":true,"side":"buy"},{"i":39,"price":0.01714776,"floor":0.01286082,"graduated":true,"side":"buy"},{"i":40,"price":0.01735205,"floor":0.01301404,"graduated":true,"side":"buy"},{"i":41,"price":0.01755756,"floor":0.01316817,"graduated":true,"side":"buy"},{"i":42,"price":0.01776429,"floor":0.01332322,"graduated":true,"side":"buy"},{"i":43,"price":0.01797224,"floor":0.01347918,"graduated":true,"side":"buy"},{"i":44,"price":0.01815632,"floor":0.01361724,"graduated":true,"side":"buy"},{"i":45,"price":0.01831214,"floor":0.01373411,"graduated":true,"side":"buy"},{"i":46,"price":0.01846863,"floor":0.01385147,"graduated":true,"side":"buy"},{"i":47,"price":0.0186258,"floor":0.01396935,"graduated":true,"side":"buy"},{"i":48,"price":0.01878363,"floor":0.01408772,"graduated":true,"side":"buy"},{"i":49,"price":0.01859303,"floor":0.01408772,"graduated":true,"side":"sell"},{"i":50,"price":0.
|
|
241
|
+
const DATA = /*DATA*/{"run":"A simulated launch with a USDC quote at $1: 74 buys and 8 sells","quoteDecimals":6,"series":[{"i":0,"price":0.01,"floor":null,"graduated":false,"side":"open"},{"i":1,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":2,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":3,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":4,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":5,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":6,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":7,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":8,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":9,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":10,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":11,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":12,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":13,"price":0.01022274,"floor":0.01,"graduated":true,"side":"buy"},{"i":14,"price":0.01045981,"floor":0.01000702,"graduated":true,"side":"buy"},{"i":15,"price":0.01069961,"floor":0.01001356,"graduated":true,"side":"buy"},{"i":16,"price":0.01092692,"floor":0.01001968,"graduated":true,"side":"buy"},{"i":17,"price":0.01110845,"floor":0.01002545,"graduated":true,"side":"buy"},{"i":18,"price":0.0112915,"floor":0.0100309,"graduated":true,"side":"buy"},{"i":19,"price":0.01147605,"floor":0.01003607,"graduated":true,"side":"buy"},{"i":20,"price":0.0116621,"floor":0.01004098,"graduated":true,"side":"buy"},{"i":21,"price":0.01184832,"floor":0.01004568,"graduated":true,"side":"buy"},{"i":22,"price":0.0119884,"floor":0.01005016,"graduated":true,"side":"buy"},{"i":23,"price":0.01212932,"floor":0.01005447,"graduated":true,"side":"buy"},{"i":24,"price":0.01227106,"floor":0.0100586,"graduated":true,"side":"buy"},{"i":25,"price":0.01284634,"floor":0.01007293,"graduated":true,"side":"buy"},{"i":26,"price":0.01329322,"floor":0.01008562,"graduated":true,"side":"buy"},{"i":27,"price":0.01373598,"floor":0.01030198,"graduated":true,"side":"buy"},{"i":28,"price":0.01414542,"floor":0.01060907,"graduated":true,"side":"buy"},{"i":29,"price":0.01448348,"floor":0.01086261,"graduated":true,"side":"buy"},{"i":30,"price":0.01482555,"floor":0.01111917,"graduated":true,"side":"buy"},{"i":31,"price":0.01517165,"floor":0.01137874,"graduated":true,"side":"buy"},{"i":32,"price":0.01545607,"floor":0.01159206,"graduated":true,"side":"buy"},{"i":33,"price":0.0157178,"floor":0.01178835,"graduated":true,"side":"buy"},{"i":34,"price":0.01598174,"floor":0.01198631,"graduated":true,"side":"buy"},{"i":35,"price":0.01624789,"floor":0.01218592,"graduated":true,"side":"buy"},{"i":36,"price":0.01651626,"floor":0.0123872,"graduated":true,"side":"buy"},{"i":37,"price":0.01674282,"floor":0.01255712,"graduated":true,"side":"buy"},{"i":38,"price":0.01694468,"floor":0.01270851,"graduated":true,"side":"buy"},{"i":39,"price":0.01714776,"floor":0.01286082,"graduated":true,"side":"buy"},{"i":40,"price":0.01735205,"floor":0.01301404,"graduated":true,"side":"buy"},{"i":41,"price":0.01755756,"floor":0.01316817,"graduated":true,"side":"buy"},{"i":42,"price":0.01776429,"floor":0.01332322,"graduated":true,"side":"buy"},{"i":43,"price":0.01797224,"floor":0.01347918,"graduated":true,"side":"buy"},{"i":44,"price":0.01815632,"floor":0.01361724,"graduated":true,"side":"buy"},{"i":45,"price":0.01831214,"floor":0.01373411,"graduated":true,"side":"buy"},{"i":46,"price":0.01846863,"floor":0.01385147,"graduated":true,"side":"buy"},{"i":47,"price":0.0186258,"floor":0.01396935,"graduated":true,"side":"buy"},{"i":48,"price":0.01878363,"floor":0.01408772,"graduated":true,"side":"buy"},{"i":49,"price":0.01859303,"floor":0.01408772,"graduated":true,"side":"sell"},{"i":50,"price":0.01830951,"floor":0.01408772,"graduated":true,"side":"sell"},{"i":51,"price":0.01718636,"floor":0.01408772,"graduated":true,"side":"sell"},{"i":52,"price":0.01619404,"floor":0.01408772,"graduated":true,"side":"sell"},{"i":53,"price":0.01855915,"floor":0.01408772,"graduated":true,"side":"buy"},{"i":54,"price":0.01903381,"floor":0.01427536,"graduated":true,"side":"buy"},{"i":55,"price":0.01951452,"floor":0.01463589,"graduated":true,"side":"buy"},{"i":56,"price":0.01991845,"floor":0.01493884,"graduated":true,"side":"buy"},{"i":57,"price":0.02028262,"floor":0.01521197,"graduated":true,"side":"buy"},{"i":58,"price":0.02065011,"floor":0.01548759,"graduated":true,"side":"buy"},{"i":59,"price":0.02102093,"floor":0.01576569,"graduated":true,"side":"buy"},{"i":60,"price":0.02139506,"floor":0.0160463,"graduated":true,"side":"buy"},{"i":61,"price":0.02168119,"floor":0.01626089,"graduated":true,"side":"buy"},{"i":62,"price":0.02196271,"floor":0.01647203,"graduated":true,"side":"buy"},{"i":63,"price":0.02224606,"floor":0.01668454,"graduated":true,"side":"buy"},{"i":64,"price":0.02253123,"floor":0.01689842,"graduated":true,"side":"buy"},{"i":65,"price":0.02281824,"floor":0.01711368,"graduated":true,"side":"buy"},{"i":66,"price":0.02310707,"floor":0.01733031,"graduated":true,"side":"buy"},{"i":67,"price":0.02337554,"floor":0.01753165,"graduated":true,"side":"buy"},{"i":68,"price":0.02359221,"floor":0.01769416,"graduated":true,"side":"buy"},{"i":69,"price":0.02347579,"floor":0.01769416,"graduated":true,"side":"sell"},{"i":70,"price":0.02334103,"floor":0.01769416,"graduated":true,"side":"sell"},{"i":71,"price":0.02185754,"floor":0.01769416,"graduated":true,"side":"sell"},{"i":72,"price":0.02053252,"floor":0.01769416,"graduated":true,"side":"sell"},{"i":73,"price":0.02337134,"floor":0.01769416,"graduated":true,"side":"buy"},{"i":74,"price":0.02358799,"floor":0.01769416,"graduated":true,"side":"buy"},{"i":75,"price":0.02380564,"floor":0.01785423,"graduated":true,"side":"buy"},{"i":76,"price":0.02402431,"floor":0.01801823,"graduated":true,"side":"buy"},{"i":77,"price":0.02424398,"floor":0.01818298,"graduated":true,"side":"buy"},{"i":78,"price":0.02446465,"floor":0.01834849,"graduated":true,"side":"buy"},{"i":79,"price":0.02468634,"floor":0.01851475,"graduated":true,"side":"buy"},{"i":80,"price":0.02490903,"floor":0.01868177,"graduated":true,"side":"buy"},{"i":81,"price":0.02513272,"floor":0.01884954,"graduated":true,"side":"buy"},{"i":82,"price":0.02535743,"floor":0.01901807,"graduated":true,"side":"buy"}]}/*END*/;
|
|
242
242
|
const SUPPLY = 1e9; // a FLOOR launch mints 1B tokens; market cap = price x total supply
|
|
243
243
|
const pts = DATA.series;
|
|
244
244
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@floorlaunchpad/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "The FLOOR Program in TypeScript: the math, the quoter, decoders, PDAs and instruction builders for Solana and EVM",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -186,6 +186,11 @@
|
|
|
186
186
|
"import": "./dist/indexer/stream.js",
|
|
187
187
|
"default": "./dist/indexer/stream.js"
|
|
188
188
|
},
|
|
189
|
+
"./ton": {
|
|
190
|
+
"types": "./src/ton/index.ts",
|
|
191
|
+
"import": "./dist/ton/index.js",
|
|
192
|
+
"default": "./dist/ton/index.js"
|
|
193
|
+
},
|
|
189
194
|
"./evm/balances": {
|
|
190
195
|
"types": "./src/evm/balances.ts",
|
|
191
196
|
"import": "./dist/evm/balances.js",
|
package/src/abi/functions.gen.ts
CHANGED
|
@@ -119,7 +119,7 @@ export const FLOOR_AMM_V2_FUNCTIONS: readonly EvmFunctionRow[] = [
|
|
|
119
119
|
{ module: "floorAmmViewsV2", name: "bidMoney", signature: "bidMoney(uint256)", selector: "0x8e403c51", outputs: "(uint256)" },
|
|
120
120
|
{ module: "floorAmmViewsV2", name: "circulatingOf", signature: "circulatingOf(uint256)", selector: "0x72812fcf", outputs: "(uint256,uint256,uint256)" },
|
|
121
121
|
{ module: "floorAmmViewsV2", name: "holderBook", signature: "holderBook(uint256)", selector: "0xf5d23b14", outputs: "((uint128,uint64,uint64,uint128,uint128))" },
|
|
122
|
-
{ module: "floorAmmViewsV2", name: "launchBook", signature: "launchBook(uint256)", selector: "0x926310f1", outputs: "((uint128,uint128,uint128,uint128[],uint8,(uint128,uint128,uint64,uint64,uint64,uint128,uint16,uint16,uint8,uint8)[48],uint128,uint64,uint64[],uint128[],uint8,uint8,uint128[],uint128[],uint128,uint64,bool,uint32[5]))" },
|
|
122
|
+
{ module: "floorAmmViewsV2", name: "launchBook", signature: "launchBook(uint256)", selector: "0x926310f1", outputs: "((uint128,uint128,uint128,uint128[],uint8,(uint128,uint128,uint64,uint64,uint64,uint128,uint16,uint16,uint8,uint8)[48],uint128,uint64,uint64[],uint128[],uint8,uint8,uint128[],uint128[],uint128,uint64,bool,uint32[5],uint128,uint64,bool))" },
|
|
123
123
|
{ module: "floorAmmViewsV2", name: "launchCount", signature: "launchCount()", selector: "0x27cca59f", outputs: "(uint256)" },
|
|
124
124
|
{ module: "floorAmmViewsV2", name: "launchFeeCurve", signature: "launchFeeCurve(uint256)", selector: "0xc598083f", outputs: "((uint32[5],uint128,uint128))" },
|
|
125
125
|
{ module: "floorAmmViewsV2", name: "launchMilestones", signature: "launchMilestones(uint256)", selector: "0x2414ccf1", outputs: "((uint128[4],uint128[4]))" },
|
package/src/config/generated.ts
CHANGED
|
@@ -27113,6 +27113,83 @@ export const CHAIN_ROWS = [
|
|
|
27113
27113
|
"address": "0xfd6f06d323f6cb08ee9eeb2d201e9ec0e9112c88",
|
|
27114
27114
|
"decimals": 18,
|
|
27115
27115
|
"kind": "stock"
|
|
27116
|
+
},
|
|
27117
|
+
{
|
|
27118
|
+
"symbol": "EQQQQ",
|
|
27119
|
+
"name": "EQX Tokenized QQQ",
|
|
27120
|
+
"address": "0x095cca17f0619596115eA09bbE1D80431685Ba1A",
|
|
27121
|
+
"decimals": 8,
|
|
27122
|
+
"kind": "stock"
|
|
27123
|
+
},
|
|
27124
|
+
{
|
|
27125
|
+
"symbol": "EQSPY",
|
|
27126
|
+
"name": "EQX Tokenized SPY",
|
|
27127
|
+
"address": "0x07A76acCed707De999A54D39aFF62A2d7ac4CC81",
|
|
27128
|
+
"decimals": 8,
|
|
27129
|
+
"kind": "stock"
|
|
27130
|
+
},
|
|
27131
|
+
{
|
|
27132
|
+
"symbol": "EQNVDA",
|
|
27133
|
+
"name": "EQX Tokenized NVDA",
|
|
27134
|
+
"address": "0xA23aFe6Bd466BdB806a83AfDDA76F644FC4347CF",
|
|
27135
|
+
"decimals": 8,
|
|
27136
|
+
"kind": "stock"
|
|
27137
|
+
},
|
|
27138
|
+
{
|
|
27139
|
+
"symbol": "EQTSLA",
|
|
27140
|
+
"name": "EQX Tokenized TSLA",
|
|
27141
|
+
"address": "0x883DAd2Aa97175c0D1569E1de61204ac47b2b8fb",
|
|
27142
|
+
"decimals": 8,
|
|
27143
|
+
"kind": "stock"
|
|
27144
|
+
},
|
|
27145
|
+
{
|
|
27146
|
+
"symbol": "EQAAPL",
|
|
27147
|
+
"name": "EQX Tokenized AAPL",
|
|
27148
|
+
"address": "0x15d82780780Ca72570818f91587B752562D655bc",
|
|
27149
|
+
"decimals": 8,
|
|
27150
|
+
"kind": "stock"
|
|
27151
|
+
},
|
|
27152
|
+
{
|
|
27153
|
+
"symbol": "EQGOOG",
|
|
27154
|
+
"name": "EQX Tokenized GOOGL",
|
|
27155
|
+
"address": "0x4720b40C89Ff3A74C6bE8eA34Cf40FaE5eacEd79",
|
|
27156
|
+
"decimals": 8,
|
|
27157
|
+
"kind": "stock"
|
|
27158
|
+
},
|
|
27159
|
+
{
|
|
27160
|
+
"symbol": "EQMETA",
|
|
27161
|
+
"name": "EQX Tokenized META",
|
|
27162
|
+
"address": "0xF5c6190d9178097563372a4acA15D52Ec24F129A",
|
|
27163
|
+
"decimals": 8,
|
|
27164
|
+
"kind": "stock"
|
|
27165
|
+
},
|
|
27166
|
+
{
|
|
27167
|
+
"symbol": "EQMSFT",
|
|
27168
|
+
"name": "EQX Tokenized MSFT",
|
|
27169
|
+
"address": "0xca911A8ae21baAf9CDec0baa45259c64Ec8AE59E",
|
|
27170
|
+
"decimals": 8,
|
|
27171
|
+
"kind": "stock"
|
|
27172
|
+
},
|
|
27173
|
+
{
|
|
27174
|
+
"symbol": "EQAMZN",
|
|
27175
|
+
"name": "EQX Tokenized AMZN",
|
|
27176
|
+
"address": "0x582C6ADd0eb720EA1c2e2019fF9b7c21Fe99288F",
|
|
27177
|
+
"decimals": 8,
|
|
27178
|
+
"kind": "stock"
|
|
27179
|
+
},
|
|
27180
|
+
{
|
|
27181
|
+
"symbol": "EQMU",
|
|
27182
|
+
"name": "EQX Tokenized MU",
|
|
27183
|
+
"address": "0x9164Fd5f67FE4188Ff79675182183512bC37d66D",
|
|
27184
|
+
"decimals": 8,
|
|
27185
|
+
"kind": "stock"
|
|
27186
|
+
},
|
|
27187
|
+
{
|
|
27188
|
+
"symbol": "EQSPCX",
|
|
27189
|
+
"name": "EQX Tokenized SPCX",
|
|
27190
|
+
"address": "0xF115FF708A795cD0E06531Dec57ed716138bE8BD",
|
|
27191
|
+
"decimals": 8,
|
|
27192
|
+
"kind": "stock"
|
|
27116
27193
|
}
|
|
27117
27194
|
]
|
|
27118
27195
|
},
|
package/src/evm/chains.ts
CHANGED
|
@@ -22,8 +22,6 @@ export interface ZapRouter {
|
|
|
22
22
|
urFork?: ZapUrFork;
|
|
23
23
|
|
|
24
24
|
zap: string | null;
|
|
25
|
-
|
|
26
|
-
floorRouter: string;
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
export interface EvmChain {
|
|
@@ -48,6 +46,8 @@ function strict(a: string): string {
|
|
|
48
46
|
return c;
|
|
49
47
|
}
|
|
50
48
|
|
|
49
|
+
type ZapRouterSpec = Omit<ZapRouter, "zap">;
|
|
50
|
+
|
|
51
51
|
const UR_FORK_OF_SLOT: Readonly<Record<string, ZapUrFork>> = { "aerodrome-ur": "aerodrome", "pancake-ur": "pancake", "ramses-ur": "ramses" };
|
|
52
52
|
function urForkOf(slot: string): ZapUrFork {
|
|
53
53
|
const f = UR_FORK_OF_SLOT[slot];
|
|
@@ -55,8 +55,6 @@ function urForkOf(slot: string): ZapUrFork {
|
|
|
55
55
|
return f;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
type ZapRouterSpec = Omit<ZapRouter, "zap" | "floorRouter">;
|
|
59
|
-
|
|
60
58
|
const r = (slot: string, amm: string, router: string, family: ZapFamily, confidence: ZapRouter["confidence"], optional = false, forkEncoding = false): ZapRouterSpec => ({
|
|
61
59
|
slot,
|
|
62
60
|
amm,
|
|
@@ -93,28 +91,9 @@ export const FLOOR_ZAP_ADDRESSES: Readonly<Record<ChainKey, Readonly<Record<stri
|
|
|
93
91
|
elysium: { "uniswap-ur": strict("0x56F22be922Ffc9e955169E0673D3Ae42B1151995") },
|
|
94
92
|
};
|
|
95
93
|
|
|
96
|
-
export const FLOOR_ROUTER_DEPLOYER = strict("0x3e70158e54E91d2984c0F3B66ce2cE730d1E0e11");
|
|
97
|
-
|
|
98
|
-
const ROUTER_PROXY_INITCODE = "0x67363d3d37363d34f03d5260086018f3";
|
|
99
|
-
|
|
100
|
-
function slotWord(slot: string): Uint8Array {
|
|
101
|
-
const b = new TextEncoder().encode(slot);
|
|
102
|
-
if (b.length === 0 || b.length > 32) throw new RangeError(`a router slot is 1..32 bytes: ${JSON.stringify(slot)}`);
|
|
103
|
-
const w = new Uint8Array(32);
|
|
104
|
-
w.set(b);
|
|
105
|
-
return w;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export function floorRouterAddress(slot: string, deployer: string = FLOOR_ROUTER_DEPLOYER): string {
|
|
109
|
-
const s = keccak256(encodeAbi(["string", "bytes32"], ["floor-router.v1.FloorRouter", bytesToHex(slotWord(slot))]));
|
|
110
|
-
const proxy = create2Address({ deployer, salt: s, initCode: ROUTER_PROXY_INITCODE });
|
|
111
|
-
|
|
112
|
-
return checksumAddress(bytesToHex(keccak256(hexToBytes("0xd694" + proxy.slice(2) + "01")).slice(12)));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
94
|
function withBookedZaps(key: ChainKey, rows: readonly ZapRouterSpec[]): ZapRouter[] {
|
|
116
95
|
const book = FLOOR_ZAP_ADDRESSES[key];
|
|
117
|
-
return rows.map((row) => ({ ...row, zap: book[row.slot] ?? null
|
|
96
|
+
return rows.map((row) => ({ ...row, zap: book[row.slot] ?? null }));
|
|
118
97
|
}
|
|
119
98
|
|
|
120
99
|
const UNISWAP_UR = "uniswap-ur";
|
|
@@ -190,10 +169,6 @@ export const EVM_CHAINS: Record<ChainKey, EvmChain> = Object.fromEntries(
|
|
|
190
169
|
CHAIN_REGISTRY.flatMap((c) => (c.family === "evm" ? [[c.slug, { key: c.slug, chainId: c.chainId, name: c.label, nativeSymbol: c.native.symbol, ...ROUTES[c.slug], ...((c.v2DayOne as boolean) === false ? { v2DayOne: false as const } : {}) }]] : [])),
|
|
191
170
|
) as Record<ChainKey, EvmChain>;
|
|
192
171
|
|
|
193
|
-
export const FLOOR_ROUTER_ADDRESSES: Readonly<Record<ChainKey, Readonly<Record<string, string>>>> = Object.freeze(
|
|
194
|
-
Object.fromEntries(Object.values(EVM_CHAINS).map((c) => [c.key, Object.freeze(Object.fromEntries(c.zapRouters.map((r) => [r.slot, r.floorRouter])))])),
|
|
195
|
-
) as Readonly<Record<ChainKey, Readonly<Record<string, string>>>>;
|
|
196
|
-
|
|
197
172
|
export const v2DayOneChains = (): EvmChain[] => Object.values(EVM_CHAINS).filter((c) => c.v2DayOne !== false);
|
|
198
173
|
export const chainById = (chainId: number): EvmChain | null => Object.values(EVM_CHAINS).find((c) => c.chainId === chainId) ?? null;
|
|
199
174
|
|
package/src/evm/router.ts
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
import { encodeFunctionData } from "./items.ts";
|
|
4
4
|
import { deadlineArg } from "./floor/calls.ts";
|
|
5
5
|
import { EVM_NATIVE, NoRouteError, coinKey } from "../route/graph.ts";
|
|
6
|
-
import {
|
|
7
|
-
import type { ChainKey } from "./chains.ts";
|
|
6
|
+
import { chainById } from "./chains.ts";
|
|
8
7
|
import type { Pool } from "../route/graph.ts";
|
|
9
8
|
import type { HopQuote, RouteQuote } from "../route/quote.ts";
|
|
10
9
|
|
|
@@ -208,27 +207,3 @@ export function evmRouteCall(q: RouteQuote, p: { router: string; to: string; dea
|
|
|
208
207
|
const b: RouterBuy = { path: ids(buys), tokenIn: s.tokenOut, amountIn: 0n, swapData: "0x", minQuoteIn: 0n, minTokensOut: mins(buys), to: p.to, deadline: p.deadline };
|
|
209
208
|
return call(encodeRouterSwap(s, b, p.chainId), 0n);
|
|
210
209
|
}
|
|
211
|
-
|
|
212
|
-
export async function floorRouterLive(rpc: { getCode: (address: string) => Promise<string | undefined> }, at: string | { chain: ChainKey; slot: string }): Promise<boolean> {
|
|
213
|
-
const address = floorRouterAt(at);
|
|
214
|
-
const code: unknown = await rpc.getCode(address);
|
|
215
|
-
if (code === undefined) return false;
|
|
216
|
-
if (typeof code !== "string" || !/^0x([0-9a-fA-F]{2})*$/.test(code)) throw new TypeError(`getCode(${address}) returned ${String(code)}, not hex bytes`);
|
|
217
|
-
return code.length > 2;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
export async function assertFloorRouterLive(rpc: { getCode: (address: string) => Promise<string | undefined> }, at: string | { chain: ChainKey; slot: string }): Promise<string> {
|
|
221
|
-
const address = floorRouterAt(at);
|
|
222
|
-
if (!(await floorRouterLive(rpc, address))) throw new RangeError(`FloorRouter ${address} has no code on this chain yet: it is derived ahead of its deploy; do not send to it (a native coin sent to it is lost)`);
|
|
223
|
-
return address;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function floorRouterAt(at: string | { chain: ChainKey; slot: string }): string {
|
|
227
|
-
if (typeof at === "string") {
|
|
228
|
-
if (!/^0x[0-9a-fA-F]{40}$/.test(at)) throw new RangeError(`a FloorRouter is a 20-byte address: ${at}`);
|
|
229
|
-
return at;
|
|
230
|
-
}
|
|
231
|
-
const row = EVM_CHAINS[at.chain]?.zapRouters.find((r) => r.slot === at.slot);
|
|
232
|
-
if (row === undefined) throw new RangeError(`no FloorRouter slot ${at.slot} on ${at.chain}`);
|
|
233
|
-
return row.floorRouter;
|
|
234
|
-
}
|
package/src/evm/squid.ts
CHANGED
|
@@ -39,7 +39,7 @@ export type SquidHook = {
|
|
|
39
39
|
|
|
40
40
|
export const SQUID_TOKEN_SCALE = 10n ** 12n;
|
|
41
41
|
|
|
42
|
-
export const SQUID_GAS = { transfer: 65_000, buy:
|
|
42
|
+
export const SQUID_GAS = { transfer: 65_000, buy: 1_100_000, sell: 850_000, zapBuy: 1_300_000, passOn: 30_000 } as const;
|
|
43
43
|
|
|
44
44
|
type Common = {
|
|
45
45
|
chainId: number | string;
|
|
@@ -96,12 +96,12 @@ export function buyHookErc20(p: Common & { quote: string; minTokensOut: bigint }
|
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
export function buyHookNative(p: Common & { zap: string; swapData: string; minQuoteIn: bigint; minTokensOut: bigint; quote
|
|
99
|
+
export function buyHookNative(p: Common & { zap: string; swapData: string; minQuoteIn: bigint; minTokensOut: bigint; quote: string }): SquidHook {
|
|
100
100
|
checkCommon(p);
|
|
101
101
|
const user = checkUser(p);
|
|
102
102
|
if (p.minQuoteIn <= 0n || p.minTokensOut <= 0n) throw new SquidHookError("NO_MINIMUM", "minQuoteIn and minTokensOut must be > 0");
|
|
103
103
|
const zap = lc(p.zap, "zap");
|
|
104
|
-
const quote = lc(p.quote
|
|
104
|
+
const quote = lc(p.quote, "quote");
|
|
105
105
|
const calls = [
|
|
106
106
|
call(SQUID_CALL.FullNativeBalance, zap, 0n, bytesToHex(encodeCall("buyWithEth(uint256,bytes,uint256,uint256,address,uint256)", [p.launchId, p.swapData, p.minQuoteIn, p.minTokensOut, user, p.deadline])), "0x", SQUID_GAS.zapBuy),
|
|
107
107
|
call(SQUID_CALL.FullNativeBalance, user, 0n, "0x", "0x", SQUID_GAS.passOn),
|
package/src/index.ts
CHANGED
|
@@ -87,6 +87,7 @@ export * as abi from "./abi/index.ts";
|
|
|
87
87
|
export * as v2Press from "./v2/press.ts";
|
|
88
88
|
export * as v2ReceiptTx from "./v2/receipt-tx.ts";
|
|
89
89
|
export * as config from "./config/index.ts";
|
|
90
|
+
export * as ton from "./ton/index.ts";
|
|
90
91
|
export * as fixtures from "./fixtures.ts";
|
|
91
92
|
export * as client from "./client/index.ts";
|
|
92
93
|
export * as errors from "./errors.ts";
|
package/src/indexer/bodies.ts
CHANGED
|
@@ -135,6 +135,10 @@ const LISTED_FIELDS = {
|
|
|
135
135
|
volume24hGross: nullable(big),
|
|
136
136
|
holders: int,
|
|
137
137
|
|
|
138
|
+
newHolders1h: optional(nullable(int)),
|
|
139
|
+
|
|
140
|
+
newHolders24h: optional(nullable(int)),
|
|
141
|
+
|
|
138
142
|
maxLossPpm: optional(nullable(int)),
|
|
139
143
|
|
|
140
144
|
backedPpm: nullable(int),
|
package/src/math/v2/book.ts
CHANGED
|
@@ -66,6 +66,12 @@ export interface Book {
|
|
|
66
66
|
ckAtF: bigint;
|
|
67
67
|
|
|
68
68
|
ckFloorTokens: bigint;
|
|
69
|
+
|
|
70
|
+
kpot: boolean;
|
|
71
|
+
|
|
72
|
+
kAtF: bigint;
|
|
73
|
+
|
|
74
|
+
kFloorTokens: bigint;
|
|
69
75
|
feePpm: number[];
|
|
70
76
|
|
|
71
77
|
feeStartPpm: number[];
|
|
@@ -125,7 +131,7 @@ export function emptyBook(sqrtP: Sqrt, feePpm: readonly number[]): Book {
|
|
|
125
131
|
return {
|
|
126
132
|
sqrtP, sqrtF: 0n, sqrtLMax: 0n, floor: 0n, floorTokens: 0n, nBands: 0, nC: 0,
|
|
127
133
|
bandEdge: new Array(BIDS_MAX + 1).fill(0n), bandMoney: new Array(BIDS_MAX).fill(0n), bandTokens: new Array(BIDS_MAX).fill(0n),
|
|
128
|
-
bandF: new Array(BIDS_MAX).fill(0n), bandFClaim: new Array(BIDS_MAX).fill(0n), ckAtF: 0n, ckFloorTokens: 0n, feePpm: [...feePpm], feeStartPpm: [0, 0, 0, 0, 0], sqrtFeeA: 0n, sqrtFeeB: 0n, graduated: false, nRanges: 0, ranges: Array.from({ length: RANGES_MAX }, emptyRange),
|
|
134
|
+
bandF: new Array(BIDS_MAX).fill(0n), bandFClaim: new Array(BIDS_MAX).fill(0n), ckAtF: 0n, ckFloorTokens: 0n, kpot: true, kAtF: 0n, kFloorTokens: 0n, feePpm: [...feePpm], feeStartPpm: [0, 0, 0, 0, 0], sqrtFeeA: 0n, sqrtFeeB: 0n, graduated: false, nRanges: 0, ranges: Array.from({ length: RANGES_MAX }, emptyRange),
|
|
129
135
|
};
|
|
130
136
|
}
|
|
131
137
|
|
|
@@ -249,6 +255,21 @@ export const ckMoney = (b: Book): bigint => sum(b.bandMoney, b.nBands) - sum(b.b
|
|
|
249
255
|
|
|
250
256
|
export const ckHeld = (b: Book): bigint => sum(b.bandTokens, b.nBands) + b.ckFloorTokens;
|
|
251
257
|
|
|
258
|
+
export const kSeg = (b: Book): number | null => (b.kpot && b.nBands === b.nC + 1 ? b.nC : null);
|
|
259
|
+
|
|
260
|
+
export const cMoney = (b: Book): bigint => sum(b.bandMoney, b.nC) - sum(b.bandF, b.nC) + (b.ckAtF - b.kAtF);
|
|
261
|
+
|
|
262
|
+
export const kMoney = (b: Book): bigint => ckMoney(b) - cMoney(b);
|
|
263
|
+
|
|
264
|
+
export const cHeld = (b: Book): bigint => sum(b.bandTokens, b.nC) + (b.ckFloorTokens - b.kFloorTokens);
|
|
265
|
+
|
|
266
|
+
export const kHeld = (b: Book): bigint => ckHeld(b) - cHeld(b);
|
|
267
|
+
|
|
268
|
+
export function kHolds(b: Book): boolean {
|
|
269
|
+
const k = kSeg(b);
|
|
270
|
+
return k !== null && (b.bandTokens[k] > 0n || b.bandFClaim[k] > 0n);
|
|
271
|
+
}
|
|
272
|
+
|
|
252
273
|
const bidMoneySum = (b: Book): bigint => b.floor + sum(b.bandMoney, b.nBands);
|
|
253
274
|
|
|
254
275
|
export const placeMoney = (b: Book): bigint => {
|
|
@@ -312,6 +333,8 @@ export function checkBook(b: Book): void {
|
|
|
312
333
|
}
|
|
313
334
|
}
|
|
314
335
|
if (b.ckAtF > b.floor || b.ckFloorTokens > b.floorTokens) fail("Overflow");
|
|
336
|
+
if (b.kAtF > b.ckAtF || b.kFloorTokens > b.ckFloorTokens) fail("Overflow");
|
|
337
|
+
if (b.kpot && b.nBands > b.nC + 1) fail("SqrtRange");
|
|
315
338
|
}
|
|
316
339
|
|
|
317
340
|
function flatUp(b: Book): FlatPart | null {
|
|
@@ -396,6 +419,14 @@ function floorRebuy(b: Book, take: bigint, cost: bigint): void {
|
|
|
396
419
|
if (xe > 0n) {
|
|
397
420
|
const back = (cost * xe) / x0;
|
|
398
421
|
const gone = min((take * xe + x0 - 1n) / x0, xe);
|
|
422
|
+
|
|
423
|
+
const xk = b.kFloorTokens;
|
|
424
|
+
if (xk > 0n) {
|
|
425
|
+
const backK = (back * xk) / xe;
|
|
426
|
+
const goneK = min(min((gone * xk + xe - 1n) / xe, xk), gone);
|
|
427
|
+
b.kAtF = u128(b.kAtF + backK);
|
|
428
|
+
b.kFloorTokens -= goneK;
|
|
429
|
+
}
|
|
399
430
|
b.ckAtF = u128(b.ckAtF + back);
|
|
400
431
|
b.ckFloorTokens -= gone;
|
|
401
432
|
}
|
|
@@ -587,12 +618,14 @@ export function walkDownAcc(b: Book, tokens: bigint, acc: FeeAcc, u: Undo = new
|
|
|
587
618
|
charge(b, acc, q);
|
|
588
619
|
if (fp.t === "floor") {
|
|
589
620
|
|
|
590
|
-
const ce = min(q, b.ckAtF);
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
621
|
+
const ce = min(q, b.ckAtF - b.kAtF);
|
|
622
|
+
const ke = min(q - ce, b.kAtF);
|
|
623
|
+
const xc = ce > 0n ? min(ov(flatTokensForMoney(s, ce, DOWN)), take) : 0n;
|
|
624
|
+
const xk = ke > 0n ? min(ov(flatTokensForMoney(s, ke, DOWN)), take - xc) : 0n;
|
|
625
|
+
b.ckAtF -= ce + ke;
|
|
626
|
+
b.kAtF -= ke;
|
|
627
|
+
b.ckFloorTokens = u64(b.ckFloorTokens + xc + xk);
|
|
628
|
+
b.kFloorTokens = u64(b.kFloorTokens + xk);
|
|
596
629
|
b.floor -= q;
|
|
597
630
|
b.floorTokens = u64(b.floorTokens + take);
|
|
598
631
|
w.fromF += q;
|
|
@@ -638,6 +671,8 @@ export function walkDownAcc(b: Book, tokens: bigint, acc: FeeAcc, u: Undo = new
|
|
|
638
671
|
|
|
639
672
|
b.floor = u128(b.floor + b.bandMoney[j]);
|
|
640
673
|
b.ckAtF = u128(b.ckAtF + b.bandMoney[j] - b.bandF[j]);
|
|
674
|
+
|
|
675
|
+
if (kSeg(b) === j) b.kAtF = u128(b.kAtF + b.bandMoney[j] - b.bandF[j]);
|
|
641
676
|
b.bandMoney[j] = 0n;
|
|
642
677
|
b.bandF[j] = 0n;
|
|
643
678
|
}
|
package/src/math/v2/create.ts
CHANGED
|
@@ -132,7 +132,7 @@ export function teamBuyV2(book: Book, gross: bigint, max: bigint): BookBuy {
|
|
|
132
132
|
const take = gross < max ? gross : max;
|
|
133
133
|
if (take === 0n) {
|
|
134
134
|
return { gross, net: 0n, refund: gross, tokens: 0n, fees: [0n, 0n, 0n, 0n, 0n], fromResale: 0n, fromFirst: 0n, steps: 0, budgetHit: false, graduatedNow: false, sqrtBefore: book.sqrtP, sqrtAfter: book.sqrtP,
|
|
135
|
-
split: { dF: 0n, ckAdd: 0n, ckTake: 0n, ms: 0n, booked: [0n, 0n, 0n, 0n], sqrtFNew: 0n }, relay: { nC: 0, nK: 0, laidC: 0n, laidK: 0n, atF: 0n, kept: 0 } };
|
|
135
|
+
split: { dF: 0n, ckAdd: 0n, ckTake: 0n, cAdd: 0n, kAdd: 0n, cTake: 0n, kTake: 0n, ms: 0n, booked: [0n, 0n, 0n, 0n], sqrtFNew: 0n }, relay: { nC: 0, nK: 0, laidC: 0n, laidK: 0n, atF: 0n, kAtF: 0n, kept: 0 } };
|
|
136
136
|
}
|
|
137
137
|
const r = bookBuy(book, take, 0n);
|
|
138
138
|
return { ...r, refund: r.refund + gross - take, gross };
|