@floorlaunchpad/sdk 0.1.0 → 0.3.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 +84 -0
- package/LICENSE +201 -60
- package/README.md +45 -24
- package/dist/abi/evm-event-names.js +12 -0
- package/dist/abi/evm.gen.js +130 -0
- package/dist/abi/functions.gen.js +144 -0
- package/dist/abi/index.js +17 -0
- package/dist/abi/solana.gen.js +128 -0
- package/dist/burn.js +21 -0
- package/dist/client/evm/index.js +191 -0
- package/dist/client/index.js +19 -0
- package/dist/client/solana/index.js +259 -0
- package/dist/client/types.js +5 -0
- package/dist/codec.js +77 -0
- package/dist/config/codeHash.js +9 -0
- package/dist/config/generated.js +746 -0
- package/dist/config/index.js +49 -0
- package/dist/config/registry.gen.js +118 -0
- package/dist/config/solana-genesis.js +7 -0
- package/dist/ed25519.js +31 -0
- package/dist/errors.js +249 -0
- package/dist/events/index.js +40 -0
- package/dist/events/types.gen.js +3 -0
- package/dist/evm/abi.js +283 -0
- package/dist/evm/balances.js +26 -0
- package/dist/evm/chains.js +144 -0
- package/dist/evm/floor/abi.gen.js +195 -0
- package/dist/evm/floor/calls.js +230 -0
- package/dist/evm/floor/create.js +49 -0
- package/dist/evm/floor/events.js +41 -0
- package/dist/evm/floor/iface.js +44 -0
- package/dist/evm/items.js +209 -0
- package/dist/evm/keccak.js +118 -0
- package/dist/evm/multicall.js +30 -0
- package/dist/evm/router.js +184 -0
- package/dist/evm/zap.js +128 -0
- package/dist/fixtures.js +53 -0
- package/dist/generated/index.js +28 -0
- package/dist/generated/interface.gen.js +146 -0
- package/dist/handle.js +22 -0
- package/dist/index.js +91 -7
- package/dist/indexer/bodies.js +473 -0
- package/dist/indexer/client.js +104 -0
- package/dist/indexer/contract.js +349 -0
- package/dist/indexer/decode.js +97 -0
- package/dist/indexer/partners.js +100 -0
- package/dist/indexer/paths.js +127 -0
- package/dist/indexer/read.js +109 -0
- package/dist/indexer/stream.js +71 -0
- package/dist/lock.js +16 -0
- package/dist/math/fixed.js +154 -0
- package/dist/math/genesis.js +39 -0
- package/dist/math/index.js +20 -0
- package/dist/math/u256.js +49 -0
- package/dist/math/v2/ask.js +162 -0
- package/dist/math/v2/book.js +607 -0
- package/dist/math/v2/circulating.js +62 -0
- package/dist/math/v2/create.js +122 -0
- package/dist/math/v2/display.js +208 -0
- package/dist/math/v2/error.js +17 -0
- package/dist/math/v2/feasibility.js +174 -0
- package/dist/math/v2/fees.js +121 -0
- package/dist/math/v2/holders.js +105 -0
- package/dist/math/v2/milestones.js +40 -0
- package/dist/math/v2/pow.js +69 -0
- package/dist/math/v2/preset.js +151 -0
- package/dist/math/v2/receipt.js +108 -0
- package/dist/math/v2/relay.js +217 -0
- package/dist/math/v2/rows.js +365 -0
- package/dist/math/v2/split.js +111 -0
- package/dist/math/v2/sqrt.js +84 -0
- package/dist/math/v2/supply.js +21 -0
- package/dist/math/v2/team.js +75 -0
- package/dist/math/v2/trade.js +126 -0
- package/dist/math/v2/wide.js +51 -0
- package/dist/quote.js +6 -0
- package/dist/registryPrice.js +23 -0
- package/dist/route/edge-jupiter.js +42 -0
- package/dist/route/edge.js +11 -0
- package/dist/route/graph.js +51 -0
- package/dist/route/path.js +75 -0
- package/dist/route/quote.js +15 -0
- package/dist/route-jupiter.js +35 -0
- package/dist/route.js +8 -0
- package/dist/sha256.js +61 -0
- package/dist/solana/alt.js +18 -0
- package/dist/solana/floor/accounts.js +390 -0
- package/dist/solana/floor/borsh.js +66 -0
- package/dist/solana/floor/create.js +65 -0
- package/dist/solana/floor/events.js +140 -0
- package/dist/solana/floor/genesis.js +91 -0
- package/dist/solana/floor/genesisList.js +68 -0
- package/dist/solana/floor/instructions.js +435 -0
- package/dist/solana/floor/metadata.js +198 -0
- package/dist/solana/floor/mint.js +206 -0
- package/dist/solana/floor/program.js +64 -0
- package/dist/solana/floor/registry.js +83 -0
- package/dist/solana/instruction.js +49 -0
- package/dist/solana/pda.js +88 -0
- package/dist/solana/tx.js +138 -0
- package/dist/v2/burnPreview.js +35 -0
- package/dist/v2/circulating.js +11 -0
- package/dist/v2/claimAllEvm.js +70 -0
- package/dist/v2/claims-evm.js +120 -0
- package/dist/v2/claims.js +218 -0
- package/dist/v2/dead.js +21 -0
- package/dist/v2/devbuy.js +37 -0
- package/dist/v2/events.js +115 -0
- package/dist/v2/evm.js +299 -0
- package/dist/v2/evmReads.js +76 -0
- package/dist/v2/genesis.js +76 -0
- package/dist/v2/layouts.js +217 -0
- package/dist/v2/market-evm.js +74 -0
- package/dist/v2/presetRowEvm.js +45 -0
- package/dist/v2/press.js +106 -0
- package/dist/v2/quoteMint.js +52 -0
- package/dist/v2/receipt-tx.js +149 -0
- package/dist/v2/route-alt.js +114 -0
- package/dist/v2/route.js +389 -0
- package/dist/v2/solana.js +391 -0
- package/dist/v2/solanaSettle.js +97 -0
- package/dist/v2/tx/evm.js +126 -0
- package/dist/v2/tx/genesis.js +47 -0
- package/dist/v2/tx/index.js +5 -0
- package/dist/v2/tx/solana.js +118 -0
- package/dist/v2/types.js +13 -0
- package/docs/aggregator.md +61 -0
- package/docs/bot.md +50 -0
- package/docs/frontend.md +29 -0
- package/docs/wallet.md +54 -0
- package/package.json +428 -32
- package/src/abi/evm-event-names.ts +12 -0
- package/src/abi/evm.gen.ts +139 -0
- package/src/abi/functions.gen.ts +154 -0
- package/src/abi/index.ts +30 -0
- package/src/abi/solana.gen.ts +138 -0
- package/src/burn.ts +37 -0
- package/src/client/evm/index.ts +199 -0
- package/src/client/index.ts +23 -0
- package/src/client/solana/index.ts +260 -0
- package/src/client/types.ts +162 -0
- package/src/codec.ts +77 -0
- package/src/config/codeHash.ts +9 -0
- package/src/config/generated.ts +746 -0
- package/src/config/index.ts +91 -0
- package/src/config/registry.gen.ts +118 -0
- package/src/config/solana-genesis.ts +7 -0
- package/src/ed25519.ts +31 -0
- package/src/errors.ts +270 -0
- package/src/events/index.ts +44 -0
- package/src/events/types.gen.ts +831 -0
- package/src/evm/abi.ts +292 -0
- package/src/evm/balances.ts +26 -0
- package/src/evm/chains.ts +167 -0
- package/src/evm/floor/abi.gen.ts +195 -0
- package/src/evm/floor/calls.ts +247 -0
- package/src/evm/floor/create.ts +68 -0
- package/src/evm/floor/events.ts +51 -0
- package/src/evm/floor/iface.ts +45 -0
- package/src/evm/items.ts +252 -0
- package/src/evm/keccak.ts +118 -0
- package/src/evm/multicall.ts +43 -0
- package/src/evm/router.ts +209 -0
- package/src/evm/zap.ts +152 -0
- package/src/fixtures.ts +53 -0
- package/src/generated/index.ts +29 -0
- package/src/generated/interface.gen.ts +153 -0
- package/src/handle.ts +22 -0
- package/src/index.ts +91 -6
- package/src/indexer/bodies.ts +528 -0
- package/src/indexer/client.ts +178 -0
- package/src/indexer/contract.ts +410 -0
- package/src/indexer/decode.ts +109 -0
- package/src/indexer/partners.ts +109 -0
- package/src/indexer/paths.ts +190 -0
- package/src/indexer/read.ts +119 -0
- package/src/indexer/stream.ts +83 -0
- package/src/lock.ts +16 -0
- package/src/math/fixed.ts +154 -0
- package/src/math/genesis.ts +39 -0
- package/src/math/index.ts +24 -0
- package/src/math/u256.ts +49 -0
- package/src/math/v2/ask.ts +218 -0
- package/src/math/v2/book.ts +660 -0
- package/src/math/v2/circulating.ts +69 -0
- package/src/math/v2/create.ts +139 -0
- package/src/math/v2/display.ts +250 -0
- package/src/math/v2/error.ts +19 -0
- package/src/math/v2/feasibility.ts +200 -0
- package/src/math/v2/fees.ts +121 -0
- package/src/math/v2/holders.ts +124 -0
- package/src/math/v2/milestones.ts +51 -0
- package/src/math/v2/pow.ts +71 -0
- package/src/math/v2/preset.ts +189 -0
- package/src/math/v2/receipt.ts +162 -0
- package/src/math/v2/relay.ts +235 -0
- package/src/math/v2/rows.ts +412 -0
- package/src/math/v2/split.ts +160 -0
- package/src/math/v2/sqrt.ts +86 -0
- package/src/math/v2/supply.ts +27 -0
- package/src/math/v2/team.ts +75 -0
- package/src/math/v2/trade.ts +145 -0
- package/src/math/v2/wide.ts +52 -0
- package/src/quote.ts +6 -0
- package/src/registryPrice.ts +28 -0
- package/src/route/edge-jupiter.ts +71 -0
- package/src/route/edge.ts +22 -0
- package/src/route/graph.ts +77 -0
- package/src/route/path.ts +84 -0
- package/src/route/quote.ts +46 -0
- package/src/route-jupiter.ts +36 -0
- package/src/route.ts +8 -0
- package/src/sha256.ts +61 -0
- package/src/solana/alt.ts +25 -0
- package/src/solana/floor/accounts.ts +393 -0
- package/src/solana/floor/borsh.ts +66 -0
- package/src/solana/floor/create.ts +89 -0
- package/src/solana/floor/events.ts +147 -0
- package/src/solana/floor/genesis.ts +111 -0
- package/src/solana/floor/genesisList.ts +75 -0
- package/src/solana/floor/instructions.ts +491 -0
- package/src/solana/floor/metadata.ts +246 -0
- package/src/solana/floor/mint.ts +242 -0
- package/src/solana/floor/program.ts +64 -0
- package/src/solana/floor/registry.ts +96 -0
- package/src/solana/instruction.ts +61 -0
- package/src/solana/pda.ts +91 -0
- package/src/solana/tx.ts +143 -0
- package/src/v2/burnPreview.ts +52 -0
- package/src/v2/circulating.ts +22 -0
- package/src/v2/claimAllEvm.ts +97 -0
- package/src/v2/claims-evm.ts +179 -0
- package/src/v2/claims.ts +288 -0
- package/src/v2/dead.ts +21 -0
- package/src/v2/devbuy.ts +55 -0
- package/src/v2/events.ts +131 -0
- package/src/v2/evm.ts +349 -0
- package/src/v2/evmReads.ts +121 -0
- package/src/v2/genesis.ts +80 -0
- package/src/v2/layouts.ts +219 -0
- package/src/v2/market-evm.ts +95 -0
- package/src/v2/presetRowEvm.ts +54 -0
- package/src/v2/press.ts +124 -0
- package/src/v2/quoteMint.ts +63 -0
- package/src/v2/receipt-tx.ts +251 -0
- package/src/v2/route-alt.ts +114 -0
- package/src/v2/route.ts +494 -0
- package/src/v2/solana.ts +439 -0
- package/src/v2/solanaSettle.ts +117 -0
- package/src/v2/tx/evm.ts +152 -0
- package/src/v2/tx/genesis.ts +66 -0
- package/src/v2/tx/index.ts +5 -0
- package/src/v2/tx/solana.ts +140 -0
- package/src/v2/types.ts +284 -0
- package/dist/adapter.d.ts +0 -28
- package/dist/adapter.d.ts.map +0 -1
- package/dist/adapter.js +0 -2
- package/dist/adapter.js.map +0 -1
- package/dist/chain.d.ts +0 -23
- package/dist/chain.d.ts.map +0 -1
- package/dist/chain.js +0 -25
- package/dist/chain.js.map +0 -1
- package/dist/client.d.ts +0 -26
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -43
- package/dist/client.js.map +0 -1
- package/dist/dex-adapter.d.ts +0 -228
- package/dist/dex-adapter.d.ts.map +0 -1
- package/dist/dex-adapter.js +0 -407
- package/dist/dex-adapter.js.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/quotes.d.ts +0 -12
- package/dist/quotes.d.ts.map +0 -1
- package/dist/quotes.gen.d.ts +0 -8
- package/dist/quotes.gen.d.ts.map +0 -1
- package/dist/quotes.gen.js +0 -2170
- package/dist/quotes.gen.js.map +0 -1
- package/dist/quotes.js +0 -24
- package/dist/quotes.js.map +0 -1
- package/dist/types.d.ts +0 -111
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/src/adapter.ts +0 -20
- package/src/chain.ts +0 -39
- package/src/client.ts +0 -41
- package/src/dex-adapter.ts +0 -477
- package/src/quotes.gen.ts +0 -2170
- package/src/quotes.ts +0 -29
- package/src/types.ts +0 -115
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { checksumAddress } from "../abi.ts";
|
|
4
|
+
import { decodeEventLog, itemTopic } from "../items.ts";
|
|
5
|
+
import type { EventArgsOf, EventName, Log } from "../items.ts";
|
|
6
|
+
import { FLOOR_AMM_ABI, FLOOR_AMM_UNFROZEN_EVENTS, FLOOR_ZAP_ABI } from "./iface.ts";
|
|
7
|
+
|
|
8
|
+
export type FloorEventName = EventName<typeof FLOOR_AMM_ABI> | EventName<typeof FLOOR_ZAP_ABI>;
|
|
9
|
+
export type FloorEventArgs<N extends EventName<typeof FLOOR_AMM_ABI>> = EventArgsOf<typeof FLOOR_AMM_ABI, N>;
|
|
10
|
+
|
|
11
|
+
export interface FloorEvmEvent {
|
|
12
|
+
name: string;
|
|
13
|
+
args: Record<string, any>;
|
|
14
|
+
|
|
15
|
+
address?: string;
|
|
16
|
+
|
|
17
|
+
unfrozen?: true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const ALL = [...FLOOR_AMM_ABI, ...FLOOR_ZAP_ABI, ...FLOOR_AMM_UNFROZEN_EVENTS];
|
|
21
|
+
|
|
22
|
+
let unfrozen: Set<string> | undefined;
|
|
23
|
+
const UNFROZEN = (): Set<string> => (unfrozen ??= new Set(FLOOR_AMM_UNFROZEN_EVENTS.map((e) => itemTopic(e))));
|
|
24
|
+
|
|
25
|
+
export const FLOOR_EVENT_TOPICS: Record<string, string> = {};
|
|
26
|
+
for (const i of ALL.filter((i) => i.type === "event").reverse()) {
|
|
27
|
+
const name = i.name;
|
|
28
|
+
const first = ALL.find((j) => j.type === "event" && j.name === name)!;
|
|
29
|
+
if (!(name in FLOOR_EVENT_TOPICS))
|
|
30
|
+
Object.defineProperty(FLOOR_EVENT_TOPICS, name, {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
configurable: true,
|
|
33
|
+
get: () => {
|
|
34
|
+
const value = itemTopic(first);
|
|
35
|
+
Object.defineProperty(FLOOR_EVENT_TOPICS, name, { value, enumerable: true, configurable: true, writable: true });
|
|
36
|
+
return value;
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function decodeFloorLog(log: Log, from?: readonly string[]): FloorEvmEvent | null {
|
|
42
|
+
if (from && (!log.address || !from.some((a) => a.toLowerCase() === log.address!.toLowerCase()))) return null;
|
|
43
|
+
const d: FloorEvmEvent | null = decodeEventLog(ALL, log);
|
|
44
|
+
if (!d) return null;
|
|
45
|
+
if (UNFROZEN().has((log.topics[0] ?? "").toLowerCase())) d.unfrozen = true;
|
|
46
|
+
return log.address ? { ...d, address: checksumAddress(log.address) } : d;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function decodeFloorLogs(logs: readonly Log[], from?: readonly string[]): FloorEvmEvent[] {
|
|
50
|
+
return logs.map((l) => decodeFloorLog(l, from)).filter((e): e is FloorEvmEvent => e !== null);
|
|
51
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import type { MathErrorCode } from "../../math/index.ts";
|
|
4
|
+
import { CLAIM_BITS, CLAIM_RESERVED, CLAIM_CREATOR, CLAIM_CREATOR_REF, CLAIM_TEAM_SLOT, CLAIM_TRADER_REF, CLAIM_RESERVED_HOLDER, CLAIM_EXTRA, CLAIM_TEAM_BUY, CLAIM_SHARE_BOUGHT } from "../../generated/index.ts";
|
|
5
|
+
export { FLOOR_AMM_ABI, FLOOR_AMM_UNFROZEN_EVENTS, FLOOR_TOKEN_ABI, FLOOR_ZAP_ABI } from "./abi.gen.ts";
|
|
6
|
+
|
|
7
|
+
export { CLAIM_CREATOR, CLAIM_CREATOR_REF, CLAIM_TEAM_SLOT, CLAIM_TRADER_REF, CLAIM_RESERVED_HOLDER, CLAIM_EXTRA, CLAIM_TEAM_BUY, CLAIM_SHARE_BOUGHT };
|
|
8
|
+
|
|
9
|
+
export const CLAIM_PAYOUT = CLAIM_BITS.evm.payout;
|
|
10
|
+
|
|
11
|
+
export const CLAIM_KNOWN = CLAIM_CREATOR | CLAIM_CREATOR_REF | CLAIM_TEAM_SLOT | CLAIM_TRADER_REF | CLAIM_EXTRA | CLAIM_PAYOUT | CLAIM_TEAM_BUY | CLAIM_SHARE_BOUGHT;
|
|
12
|
+
|
|
13
|
+
export const OWED_BITS = [
|
|
14
|
+
["creator", CLAIM_CREATOR],
|
|
15
|
+
["creatorRef", CLAIM_CREATOR_REF],
|
|
16
|
+
["teamSlot", CLAIM_TEAM_SLOT],
|
|
17
|
+
["traderRef", CLAIM_TRADER_REF],
|
|
18
|
+
["extra", CLAIM_EXTRA],
|
|
19
|
+
] as const;
|
|
20
|
+
|
|
21
|
+
export const TRADE_CREDIT_PAYEES = [
|
|
22
|
+
"creator",
|
|
23
|
+
"creatorRef1", "creatorRef2", "creatorRef3",
|
|
24
|
+
"member0", "member1", "member2", "member3", "member4", "member5", "member6", "member7", "member8", "member9",
|
|
25
|
+
"traderRef1", "traderRef2", "traderRef3",
|
|
26
|
+
"holder",
|
|
27
|
+
"extra0", "extra1", "extra2", "extra3",
|
|
28
|
+
] as const;
|
|
29
|
+
|
|
30
|
+
export const NATIVE_QUOTE = "0x0000000000000000000000000000000000000000";
|
|
31
|
+
|
|
32
|
+
export const MEMBER_WALLET = 0;
|
|
33
|
+
export const MEMBER_HANDLE = 1;
|
|
34
|
+
export const MEMBER_EMPTY = 0;
|
|
35
|
+
export const MEMBER_REQUESTED = 1;
|
|
36
|
+
export const MEMBER_PAID = 2;
|
|
37
|
+
export const MEMBER_CANCELLED = 3;
|
|
38
|
+
|
|
39
|
+
export const EVM_TOKEN_DECIMALS = 18;
|
|
40
|
+
|
|
41
|
+
export { SWEPT_BURN, SWEPT_DUST, SWEPT_EXIT } from "../../solana/floor/events.ts";
|
|
42
|
+
|
|
43
|
+
export const MATH_ERROR_CODES: readonly MathErrorCode[] = ["VaultShareOutOfRange", "Zero", "Overflow", "NotDue", "NothingToDo",
|
|
44
|
+
"BookEmpty", "StepBudget", "SqrtRange", "RowTooManyRanges", "RowBands", "RowShares", "RowNotFeasible", "TeamBuyOverShare", "LotsFull", "IndexGuard", "NothingToSettle", "SlippageExceeded",
|
|
45
|
+
"QuoteRowCannotOpen", "RangeCover", "RowLength", "RowVersion", "RowEdges", "RowTail", "RowBounds", "RowFees", "RowTeam", "RowFlags", "RowMsClass", "RowNonCanonical"];
|
package/src/evm/items.ts
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { AbiError, bytesToHex, decodeAbi, encodeAbi, parseType } from "./abi.ts";
|
|
4
|
+
import type { AbiValue } from "./abi.ts";
|
|
5
|
+
import { keccak256 } from "./keccak.ts";
|
|
6
|
+
|
|
7
|
+
export interface AbiParam {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly type: string;
|
|
10
|
+
readonly internalType?: string;
|
|
11
|
+
readonly indexed?: boolean;
|
|
12
|
+
readonly components?: readonly AbiParam[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface AbiItem {
|
|
16
|
+
readonly type: "function" | "event" | "error" | "constructor" | "receive" | "fallback";
|
|
17
|
+
readonly name?: string;
|
|
18
|
+
readonly inputs?: readonly AbiParam[];
|
|
19
|
+
readonly outputs?: readonly AbiParam[];
|
|
20
|
+
readonly stateMutability?: "pure" | "view" | "nonpayable" | "payable";
|
|
21
|
+
readonly anonymous?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type Abi = readonly AbiItem[];
|
|
25
|
+
|
|
26
|
+
type Prim<T extends string> = T extends `uint${string}` | `int${string}` ? bigint : T extends "bool" ? boolean : string;
|
|
27
|
+
type Elem<T extends string> = T extends `${infer E}[${string}]` ? Elem<E> : T;
|
|
28
|
+
type Wrap<T extends string, V> = T extends `${infer E}[${string}]` ? Wrap<E, V>[] : V;
|
|
29
|
+
|
|
30
|
+
export type ParamValue<P> = P extends { readonly type: infer T extends string; readonly components: infer C extends readonly AbiParam[] }
|
|
31
|
+
? Wrap<T, Struct<C>>
|
|
32
|
+
: P extends { readonly type: infer T extends string }
|
|
33
|
+
? Wrap<T, Prim<Elem<T>>>
|
|
34
|
+
: never;
|
|
35
|
+
export type Struct<C extends readonly AbiParam[]> = { -readonly [K in C[number] as K["name"]]: ParamValue<K> };
|
|
36
|
+
|
|
37
|
+
type ItemOf<A extends Abi, N extends string, K extends AbiItem["type"]> = Extract<A[number], { readonly type: K; readonly name: N }>;
|
|
38
|
+
export type FunctionName<A extends Abi> = Extract<A[number], { readonly type: "function" }>["name"] & string;
|
|
39
|
+
export type EventName<A extends Abi> = Extract<A[number], { readonly type: "event" }>["name"] & string;
|
|
40
|
+
export type ArgsOf<A extends Abi, N extends string> = ItemOf<A, N, "function"> extends { readonly inputs: infer I extends readonly AbiParam[] } ? Struct<I> : never;
|
|
41
|
+
export type ResultOf<A extends Abi, N extends string> = ItemOf<A, N, "function"> extends { readonly outputs: infer O extends readonly AbiParam[] } ? Struct<O> : never;
|
|
42
|
+
export type EventArgsOf<A extends Abi, N extends string> = ItemOf<A, N, "event"> extends { readonly inputs: infer I extends readonly AbiParam[] } ? Struct<I> : never;
|
|
43
|
+
|
|
44
|
+
export function paramType(p: AbiParam): string {
|
|
45
|
+
if (!p.type.startsWith("tuple")) return p.type;
|
|
46
|
+
if (!p.components) throw new AbiError(`tuple ${p.name} has no components`);
|
|
47
|
+
return `(${p.components.map(paramType).join(",")})${p.type.slice("tuple".length)}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function itemSignature(item: AbiItem): string {
|
|
51
|
+
if (!item.name) throw new AbiError(`a ${item.type} has no signature`);
|
|
52
|
+
return `${item.name}(${(item.inputs ?? []).map(paramType).join(",")})`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const hash = (s: string): Uint8Array => keccak256(new TextEncoder().encode(s));
|
|
56
|
+
|
|
57
|
+
const TOPICS = new WeakMap<AbiItem, string>();
|
|
58
|
+
export const itemTopic = (item: AbiItem): string => {
|
|
59
|
+
let t = TOPICS.get(item);
|
|
60
|
+
if (t === undefined) TOPICS.set(item, (t = bytesToHex(hash(itemSignature(item)))));
|
|
61
|
+
return t;
|
|
62
|
+
};
|
|
63
|
+
export const itemSelector = (item: AbiItem): string => itemTopic(item).slice(0, 10);
|
|
64
|
+
|
|
65
|
+
function arrayLevels(t: string): { base: string; dims: (number | null)[] } {
|
|
66
|
+
const dims: (number | null)[] = [];
|
|
67
|
+
let s = t;
|
|
68
|
+
while (s.endsWith("]")) {
|
|
69
|
+
const i = s.lastIndexOf("[");
|
|
70
|
+
const n = s.slice(i + 1, -1);
|
|
71
|
+
dims.unshift(n === "" ? null : Number(n));
|
|
72
|
+
s = s.slice(0, i);
|
|
73
|
+
}
|
|
74
|
+
return { base: s, dims };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function toValue(p: AbiParam, v: unknown, depth = 0): AbiValue {
|
|
78
|
+
const { base, dims } = arrayLevels(p.type);
|
|
79
|
+
if (depth < dims.length) {
|
|
80
|
+
if (!Array.isArray(v)) throw new AbiError(`${p.name}: expected an array`);
|
|
81
|
+
return v.map((x) => toValue(p, x, depth + 1));
|
|
82
|
+
}
|
|
83
|
+
if (base === "tuple") {
|
|
84
|
+
const c = p.components ?? [];
|
|
85
|
+
if (Array.isArray(v)) return c.map((q, i) => toValue(q, v[i]));
|
|
86
|
+
if (v === null || typeof v !== "object") throw new AbiError(`${p.name}: expected a struct`);
|
|
87
|
+
const o = v as Record<string, unknown>;
|
|
88
|
+
return c.map((q, i) => {
|
|
89
|
+
const key = q.name !== "" ? q.name : String(i);
|
|
90
|
+
if (!(key in o)) throw new AbiError(`${p.name}: missing ${key}`);
|
|
91
|
+
return toValue(q, o[key]);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (/^u?int/.test(base)) {
|
|
95
|
+
if (typeof v === "number" && Number.isSafeInteger(v)) return BigInt(v);
|
|
96
|
+
if (typeof v !== "bigint") throw new AbiError(`${p.name}: expected a bigint`);
|
|
97
|
+
return v;
|
|
98
|
+
}
|
|
99
|
+
return v as AbiValue;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function fromValue(p: AbiParam, v: AbiValue, depth = 0): unknown {
|
|
103
|
+
const { base, dims } = arrayLevels(p.type);
|
|
104
|
+
if (depth < dims.length) return (v as AbiValue[]).map((x) => fromValue(p, x, depth + 1));
|
|
105
|
+
if (base === "tuple") return named(p.components ?? [], v as AbiValue[]);
|
|
106
|
+
return v;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function named(params: readonly AbiParam[], values: readonly AbiValue[]): Record<string, any> {
|
|
110
|
+
const out: Record<string, any> = {};
|
|
111
|
+
params.forEach((p, i) => {
|
|
112
|
+
out[p.name !== "" ? p.name : String(i)] = fromValue(p, values[i]);
|
|
113
|
+
});
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function encodeParams(params: readonly AbiParam[], args: Record<string, unknown> | readonly unknown[]): Uint8Array {
|
|
118
|
+
const vals = params.map((p, i) => {
|
|
119
|
+
if (Array.isArray(args)) return toValue(p, args[i]);
|
|
120
|
+
const o = args as Record<string, unknown>;
|
|
121
|
+
const key = p.name !== "" ? p.name : String(i);
|
|
122
|
+
if (!(key in o)) throw new AbiError(`missing argument ${key}`);
|
|
123
|
+
return toValue(p, o[key]);
|
|
124
|
+
});
|
|
125
|
+
return encodeAbi(params.map(paramType), vals);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function decodeParams(params: readonly AbiParam[], data: Uint8Array | string): Record<string, any> {
|
|
129
|
+
return named(params, decodeAbi(params.map(paramType), data));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function findItem(abi: Abi, kind: AbiItem["type"], key: string): AbiItem {
|
|
133
|
+
const all = abi.filter((i) => i.type === kind);
|
|
134
|
+
const bySig = all.filter((i) => key.includes("(") && itemSignature(i) === key.replace(/\s+/g, ""));
|
|
135
|
+
if (bySig.length === 1) return bySig[0];
|
|
136
|
+
const byName = all.filter((i) => i.name === key);
|
|
137
|
+
if (byName.length === 1) return byName[0];
|
|
138
|
+
throw new AbiError(byName.length > 1 ? `${kind} ${key} is overloaded: name it by signature` : `no ${kind} ${key}`);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const INDEX = new WeakMap<Abi, { len: number; by: Partial<Record<"function" | "event", Map<string, AbiItem>>> }>();
|
|
142
|
+
function lookup(abi: Abi, kind: "function" | "event", key: string): AbiItem | undefined {
|
|
143
|
+
let ix = INDEX.get(abi);
|
|
144
|
+
if (!ix || ix.len !== abi.length) INDEX.set(abi, (ix = { len: abi.length, by: {} }));
|
|
145
|
+
let m = ix.by[kind];
|
|
146
|
+
if (!m) {
|
|
147
|
+
m = new Map();
|
|
148
|
+
for (const i of abi) {
|
|
149
|
+
if (i.type !== kind || (kind === "event" && i.anonymous)) continue;
|
|
150
|
+
const k = kind === "event" ? itemTopic(i) : itemSelector(i);
|
|
151
|
+
if (!m.has(k)) m.set(k, i);
|
|
152
|
+
}
|
|
153
|
+
ix.by[kind] = m;
|
|
154
|
+
}
|
|
155
|
+
return m.get(key);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function encodeFunctionData(abi: Abi, name: string, args: Record<string, unknown> | readonly unknown[] = {}): string {
|
|
159
|
+
const f = findItem(abi, "function", name);
|
|
160
|
+
const body = encodeParams(f.inputs ?? [], args);
|
|
161
|
+
return itemSelector(f) + bytesToHex(body).slice(2);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function decodeFunctionData(abi: Abi, data: string | Uint8Array): { name: string; args: Record<string, any> } {
|
|
165
|
+
const hex = typeof data === "string" ? data.toLowerCase() : bytesToHex(data);
|
|
166
|
+
const f = lookup(abi, "function", hex.slice(0, 10));
|
|
167
|
+
if (!f) throw new AbiError(`no function with selector ${hex.slice(0, 10)}`);
|
|
168
|
+
return { name: f.name as string, args: decodeParams(f.inputs ?? [], "0x" + hex.slice(10)) };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function decodeFunctionResult(abi: Abi, name: string, data: string | Uint8Array): Record<string, any> {
|
|
172
|
+
return decodeParams(findItem(abi, "function", name).outputs ?? [], data);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function encodeFunctionResult(abi: Abi, name: string, result: Record<string, unknown> | readonly unknown[]): string {
|
|
176
|
+
return bytesToHex(encodeParams(findItem(abi, "function", name).outputs ?? [], result));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export interface Log {
|
|
180
|
+
topics: readonly string[];
|
|
181
|
+
data: string;
|
|
182
|
+
address?: string;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const isDynamicType = (t: string): boolean => {
|
|
186
|
+
const at = parseType(t);
|
|
187
|
+
return at.kind === "bytes" || at.kind === "string" || at.kind === "array" || at.kind === "tuple";
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export function decodeEventLog(abi: Abi, log: Log): { name: string; args: Record<string, any> } | null {
|
|
191
|
+
const t0 = (log.topics[0] ?? "").toLowerCase();
|
|
192
|
+
const ev = lookup(abi, "event", t0);
|
|
193
|
+
if (!ev) return null;
|
|
194
|
+
const inputs = ev.inputs ?? [];
|
|
195
|
+
const indexed = inputs.filter((p) => p.indexed);
|
|
196
|
+
if (log.topics.length !== indexed.length + 1) throw new AbiError(`${ev.name}: expected ${indexed.length + 1} topics, got ${log.topics.length}`);
|
|
197
|
+
const plain = inputs.filter((p) => !p.indexed);
|
|
198
|
+
const body = decodeAbi(plain.map(paramType), log.data);
|
|
199
|
+
const out: Record<string, any> = {};
|
|
200
|
+
let ti = 1;
|
|
201
|
+
let di = 0;
|
|
202
|
+
inputs.forEach((p, i) => {
|
|
203
|
+
const key = p.name !== "" ? p.name : String(i);
|
|
204
|
+
if (p.indexed) {
|
|
205
|
+
const topic = log.topics[ti++];
|
|
206
|
+
out[key] = isDynamicType(paramType(p)) ? topic.toLowerCase() : fromValue(p, decodeAbi([paramType(p)], topic)[0]);
|
|
207
|
+
} else out[key] = fromValue(p, body[di++]);
|
|
208
|
+
});
|
|
209
|
+
return { name: ev.name as string, args: out };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export function encodeEventLog(abi: Abi, name: string, args: Record<string, unknown>): Log {
|
|
213
|
+
const ev = findItem(abi, "event", name);
|
|
214
|
+
const inputs = ev.inputs ?? [];
|
|
215
|
+
const topics = [itemTopic(ev)];
|
|
216
|
+
for (const p of inputs.filter((q) => q.indexed)) {
|
|
217
|
+
const t = paramType(p);
|
|
218
|
+
if (isDynamicType(t)) throw new AbiError(`${name}.${p.name}: an indexed dynamic value is hashed; pass the hash`);
|
|
219
|
+
topics.push(bytesToHex(encodeAbi([t], [toValue(p, args[p.name])])));
|
|
220
|
+
}
|
|
221
|
+
const plain = inputs.filter((p) => !p.indexed);
|
|
222
|
+
return { topics, data: bytesToHex(encodeParams(plain, args)) };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const ERROR_STRING: AbiItem = { type: "error", name: "Error", inputs: [{ name: "message", type: "string" }] };
|
|
226
|
+
const PANIC: AbiItem = { type: "error", name: "Panic", inputs: [{ name: "code", type: "uint256" }] };
|
|
227
|
+
|
|
228
|
+
export function decodeErrorResult(abi: Abi, data: string | Uint8Array): { name: string; args: Record<string, any> } | null {
|
|
229
|
+
const hex = typeof data === "string" ? data.toLowerCase() : bytesToHex(data);
|
|
230
|
+
if (hex.length < 10) return null;
|
|
231
|
+
const sel = hex.slice(0, 10);
|
|
232
|
+
const e = abi.find((i) => i.type === "error" && itemSelector(i) === sel) ?? [ERROR_STRING, PANIC].find((i) => itemSelector(i) === sel);
|
|
233
|
+
if (!e) return null;
|
|
234
|
+
return { name: e.name as string, args: decodeParams(e.inputs ?? [], "0x" + hex.slice(10)) };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export function encodeErrorResult(abi: Abi, name: string, args: Record<string, unknown> = {}): string {
|
|
238
|
+
const e = findItem(abi, "error", name);
|
|
239
|
+
return itemSelector(e) + bytesToHex(encodeParams(e.inputs ?? [], args)).slice(2);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function abiOfArtifact(json: unknown): Abi {
|
|
243
|
+
const a = Array.isArray(json) ? json : (json as { abi?: unknown })?.abi;
|
|
244
|
+
if (!Array.isArray(a)) throw new AbiError("not an ABI or a forge artifact");
|
|
245
|
+
return a as Abi;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function signatures(abi: Abi): { functions: string[]; events: string[]; errors: string[] } {
|
|
249
|
+
const of = (k: AbiItem["type"]): string[] => abi.filter((i) => i.type === k).map(itemSignature).sort();
|
|
250
|
+
return { functions: of("function"), events: of("event"), errors: of("error") };
|
|
251
|
+
}
|
|
252
|
+
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
const RC_HI = new Uint32Array(24);
|
|
4
|
+
const RC_LO = new Uint32Array(24);
|
|
5
|
+
{
|
|
6
|
+
|
|
7
|
+
let r = 1;
|
|
8
|
+
for (let i = 0; i < 24; i++) {
|
|
9
|
+
let hi = 0;
|
|
10
|
+
let lo = 0;
|
|
11
|
+
for (let j = 0; j < 7; j++) {
|
|
12
|
+
r = ((r << 1) ^ ((r >> 7) * 0x71)) & 0xff;
|
|
13
|
+
if (r & 2) {
|
|
14
|
+
const bit = (1 << j) - 1;
|
|
15
|
+
if (bit < 32) lo ^= 1 << bit;
|
|
16
|
+
else hi ^= 1 << (bit - 32);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
RC_HI[i] = hi >>> 0;
|
|
20
|
+
RC_LO[i] = lo >>> 0;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const ROT = [0, 1, 62, 28, 27, 36, 44, 6, 55, 20, 3, 10, 43, 25, 39, 41, 45, 15, 21, 8, 18, 2, 61, 56, 14];
|
|
24
|
+
|
|
25
|
+
const bh = new Uint32Array(25);
|
|
26
|
+
const bl = new Uint32Array(25);
|
|
27
|
+
const ch = new Uint32Array(5);
|
|
28
|
+
const cl = new Uint32Array(5);
|
|
29
|
+
|
|
30
|
+
function keccakF(s: Uint32Array): void {
|
|
31
|
+
for (let round = 0; round < 24; round++) {
|
|
32
|
+
for (let x = 0; x < 5; x++) {
|
|
33
|
+
ch[x] = s[2 * x] ^ s[2 * (x + 5)] ^ s[2 * (x + 10)] ^ s[2 * (x + 15)] ^ s[2 * (x + 20)];
|
|
34
|
+
cl[x] = s[2 * x + 1] ^ s[2 * (x + 5) + 1] ^ s[2 * (x + 10) + 1] ^ s[2 * (x + 15) + 1] ^ s[2 * (x + 20) + 1];
|
|
35
|
+
}
|
|
36
|
+
for (let x = 0; x < 5; x++) {
|
|
37
|
+
const h1 = ch[(x + 1) % 5];
|
|
38
|
+
const l1 = cl[(x + 1) % 5];
|
|
39
|
+
const dh = ch[(x + 4) % 5] ^ ((h1 << 1) | (l1 >>> 31));
|
|
40
|
+
const dl = cl[(x + 4) % 5] ^ ((l1 << 1) | (h1 >>> 31));
|
|
41
|
+
for (let y = 0; y < 25; y += 5) {
|
|
42
|
+
s[2 * (x + y)] ^= dh;
|
|
43
|
+
s[2 * (x + y) + 1] ^= dl;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
for (let x = 0; x < 5; x++) {
|
|
48
|
+
for (let y = 0; y < 5; y++) {
|
|
49
|
+
const i = x + 5 * y;
|
|
50
|
+
const h = s[2 * i];
|
|
51
|
+
const l = s[2 * i + 1];
|
|
52
|
+
const r = ROT[i];
|
|
53
|
+
let rh: number;
|
|
54
|
+
let rl: number;
|
|
55
|
+
|
|
56
|
+
if (r === 0) {
|
|
57
|
+
rh = h;
|
|
58
|
+
rl = l;
|
|
59
|
+
} else if (r < 32) {
|
|
60
|
+
rh = (h << r) | (l >>> (32 - r));
|
|
61
|
+
rl = (l << r) | (h >>> (32 - r));
|
|
62
|
+
} else if (r === 32) {
|
|
63
|
+
rh = l;
|
|
64
|
+
rl = h;
|
|
65
|
+
} else {
|
|
66
|
+
rh = (l << (r - 32)) | (h >>> (64 - r));
|
|
67
|
+
rl = (h << (r - 32)) | (l >>> (64 - r));
|
|
68
|
+
}
|
|
69
|
+
const j = y + 5 * ((2 * x + 3 * y) % 5);
|
|
70
|
+
bh[j] = rh;
|
|
71
|
+
bl[j] = rl;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
for (let y = 0; y < 25; y += 5) {
|
|
76
|
+
for (let x = 0; x < 5; x++) {
|
|
77
|
+
s[2 * (x + y)] = bh[x + y] ^ (~bh[((x + 1) % 5) + y] & bh[((x + 2) % 5) + y]);
|
|
78
|
+
s[2 * (x + y) + 1] = bl[x + y] ^ (~bl[((x + 1) % 5) + y] & bl[((x + 2) % 5) + y]);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
s[0] ^= RC_HI[round];
|
|
83
|
+
s[1] ^= RC_LO[round];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function keccak256(data: Uint8Array): Uint8Array {
|
|
88
|
+
return sponge256(data, 0x01);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function sponge256(data: Uint8Array, pad: number): Uint8Array {
|
|
92
|
+
const rate = 136;
|
|
93
|
+
const s = new Uint32Array(50);
|
|
94
|
+
const padded = new Uint8Array(Math.floor(data.length / rate) * rate + rate);
|
|
95
|
+
padded.set(data);
|
|
96
|
+
padded[data.length] ^= pad;
|
|
97
|
+
padded[padded.length - 1] ^= 0x80;
|
|
98
|
+
for (let off = 0; off < padded.length; off += rate) {
|
|
99
|
+
for (let i = 0; i < rate / 8; i++) {
|
|
100
|
+
const o = off + 8 * i;
|
|
101
|
+
const lo = padded[o] | (padded[o + 1] << 8) | (padded[o + 2] << 16) | (padded[o + 3] << 24);
|
|
102
|
+
const hi = padded[o + 4] | (padded[o + 5] << 8) | (padded[o + 6] << 16) | (padded[o + 7] << 24);
|
|
103
|
+
s[2 * i] ^= hi;
|
|
104
|
+
s[2 * i + 1] ^= lo;
|
|
105
|
+
}
|
|
106
|
+
keccakF(s);
|
|
107
|
+
}
|
|
108
|
+
const out = new Uint8Array(32);
|
|
109
|
+
for (let i = 0; i < 4; i++) {
|
|
110
|
+
const hi = s[2 * i];
|
|
111
|
+
const lo = s[2 * i + 1];
|
|
112
|
+
for (let b = 0; b < 4; b++) {
|
|
113
|
+
out[8 * i + b] = (lo >>> (8 * b)) & 0xff;
|
|
114
|
+
out[8 * i + 4 + b] = (hi >>> (8 * b)) & 0xff;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { checksumAddress, decodeAbi, encodeAbi, encodeCall, bytesToHex, functionSelector, hexToBytes } from "./abi.ts";
|
|
4
|
+
import type { AbiValue } from "./abi.ts";
|
|
5
|
+
import type { EvmCall } from "./floor/calls.ts";
|
|
6
|
+
|
|
7
|
+
export const MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
8
|
+
|
|
9
|
+
const AGGREGATE3 = "aggregate3((address,bool,bytes)[])";
|
|
10
|
+
const RESULTS = ["(bool,bytes)[]"] as const;
|
|
11
|
+
|
|
12
|
+
export const AGGREGATE3_SELECTOR = bytesToHex(functionSelector(AGGREGATE3));
|
|
13
|
+
|
|
14
|
+
export interface Call3 {
|
|
15
|
+
target: string;
|
|
16
|
+
allowFailure: boolean;
|
|
17
|
+
callData: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface Call3Result {
|
|
21
|
+
success: boolean;
|
|
22
|
+
returnData: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function aggregate3Call(calls: readonly Call3[], multicall: string = MULTICALL3_ADDRESS): EvmCall {
|
|
26
|
+
const data = encodeCall(AGGREGATE3, [calls.map((c): AbiValue => [checksumAddress(c.target), c.allowFailure, c.callData])]);
|
|
27
|
+
return { to: checksumAddress(multicall), data: bytesToHex(data), value: 0n };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function decodeAggregate3Result(data: string): Call3Result[] {
|
|
31
|
+
const [rows] = decodeAbi(RESULTS, data) as [[boolean, string][]];
|
|
32
|
+
return rows.map(([success, returnData]) => ({ success, returnData }));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function decodeAggregate3Call(data: string): Call3[] {
|
|
36
|
+
const b = hexToBytes(data);
|
|
37
|
+
if (bytesToHex(b.slice(0, 4)) !== AGGREGATE3_SELECTOR) throw new RangeError("not aggregate3 calldata");
|
|
38
|
+
const [rows] = decodeAbi(["(address,bool,bytes)[]"], b.slice(4)) as [[string, boolean, string][]];
|
|
39
|
+
return rows.map(([target, allowFailure, callData]) => ({ target, allowFailure, callData }));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const encodeAggregate3Result = (results: readonly Call3Result[]): string =>
|
|
43
|
+
bytesToHex(encodeAbi(RESULTS, [results.map((r): AbiValue => [r.success, r.returnData])]));
|