@chipi-stack/core 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE-starknet-sdk.md +13 -0
- package/README.md +62 -0
- package/dist/index.d.ts +1534 -16
- package/dist/index.js +10996 -16
- package/dist/index.js.map +1 -1
- package/package.json +8 -5
- package/dist/estimation/estimate-fee.d.ts +0 -21
- package/dist/estimation/estimate-fee.d.ts.map +0 -1
- package/dist/estimation/estimate-fee.js +0 -34
- package/dist/estimation/estimate-fee.js.map +0 -1
- package/dist/estimation/types.d.ts +0 -14
- package/dist/estimation/types.d.ts.map +0 -1
- package/dist/estimation/types.js +0 -2
- package/dist/estimation/types.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/signers/create-account.d.ts +0 -21
- package/dist/signers/create-account.d.ts.map +0 -1
- package/dist/signers/create-account.js +0 -19
- package/dist/signers/create-account.js.map +0 -1
- package/dist/signers/direct-signer.d.ts +0 -18
- package/dist/signers/direct-signer.d.ts.map +0 -1
- package/dist/signers/direct-signer.js +0 -32
- package/dist/signers/direct-signer.js.map +0 -1
- package/dist/signers/external-signer.d.ts +0 -17
- package/dist/signers/external-signer.d.ts.map +0 -1
- package/dist/signers/external-signer.js +0 -19
- package/dist/signers/external-signer.js.map +0 -1
- package/dist/signers/passkey-signer.d.ts +0 -25
- package/dist/signers/passkey-signer.d.ts.map +0 -1
- package/dist/signers/passkey-signer.js +0 -24
- package/dist/signers/passkey-signer.js.map +0 -1
- package/dist/signers/starknet-signer-adapter.d.ts +0 -18
- package/dist/signers/starknet-signer-adapter.d.ts.map +0 -1
- package/dist/signers/starknet-signer-adapter.js +0 -26
- package/dist/signers/starknet-signer-adapter.js.map +0 -1
- package/dist/signers/types.d.ts +0 -19
- package/dist/signers/types.d.ts.map +0 -1
- package/dist/signers/types.js +0 -2
- package/dist/signers/types.js.map +0 -1
- package/dist/tokens/amount.d.ts +0 -72
- package/dist/tokens/amount.d.ts.map +0 -1
- package/dist/tokens/amount.js +0 -166
- package/dist/tokens/amount.js.map +0 -1
- package/dist/tokens/erc20.d.ts +0 -38
- package/dist/tokens/erc20.d.ts.map +0 -1
- package/dist/tokens/erc20.js +0 -79
- package/dist/tokens/erc20.js.map +0 -1
- package/dist/tokens/presets/mainnet.json +0 -38
- package/dist/tokens/presets/sepolia.json +0 -20
- package/dist/tokens/registry.d.ts +0 -27
- package/dist/tokens/registry.d.ts.map +0 -1
- package/dist/tokens/registry.js +0 -38
- package/dist/tokens/registry.js.map +0 -1
- package/dist/transactions/tx-builder.d.ts +0 -74
- package/dist/transactions/tx-builder.d.ts.map +0 -1
- package/dist/transactions/tx-builder.js +0 -117
- package/dist/transactions/tx-builder.js.map +0 -1
- package/dist/transactions/types.d.ts +0 -11
- package/dist/transactions/types.d.ts.map +0 -1
- package/dist/transactions/types.js +0 -2
- package/dist/transactions/types.js.map +0 -1
- package/dist/x402/client.d.ts +0 -112
- package/dist/x402/client.d.ts.map +0 -1
- package/dist/x402/client.js +0 -270
- package/dist/x402/client.js.map +0 -1
- package/dist/x402/index.d.ts +0 -2
- package/dist/x402/index.d.ts.map +0 -1
- package/dist/x402/index.js +0 -2
- package/dist/x402/index.js.map +0 -1
package/dist/tokens/amount.js
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Immutable representation of a token amount.
|
|
3
|
-
* Stores raw base units (e.g., wei for ETH, micro-units for USDC).
|
|
4
|
-
* All arithmetic is exact BigInt math — no floating point.
|
|
5
|
-
*/
|
|
6
|
-
export class Amount {
|
|
7
|
-
constructor(raw, decimals, symbol) {
|
|
8
|
-
this.raw = raw;
|
|
9
|
-
this.decimals = decimals;
|
|
10
|
-
this.symbol = symbol;
|
|
11
|
-
}
|
|
12
|
-
static assertValidDecimals(decimals) {
|
|
13
|
-
if (!Number.isInteger(decimals) || decimals < 0) {
|
|
14
|
-
throw new Error("Token decimals must be a non-negative integer");
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
// ── Factory Methods ──────────────────────────────────────────
|
|
18
|
-
/**
|
|
19
|
-
* Parse a human-readable string into an Amount.
|
|
20
|
-
* @param value - Human-readable value (e.g., "1.5")
|
|
21
|
-
* @param token - Token info with decimals and symbol
|
|
22
|
-
* @throws If value is negative, non-numeric, or has too many decimal places
|
|
23
|
-
*/
|
|
24
|
-
static parse(value, token) {
|
|
25
|
-
Amount.assertValidDecimals(token.decimals);
|
|
26
|
-
if (!/^\d+(\.\d+)?$/.test(value)) {
|
|
27
|
-
throw new Error(`Invalid amount: "${value}" — must be a non-negative number`);
|
|
28
|
-
}
|
|
29
|
-
const [whole, fraction = ""] = value.split(".");
|
|
30
|
-
if (fraction.length > token.decimals) {
|
|
31
|
-
throw new Error(`Too many decimal places: ${fraction.length} > ${token.decimals} for ${token.symbol}`);
|
|
32
|
-
}
|
|
33
|
-
const padded = fraction.padEnd(token.decimals, "0");
|
|
34
|
-
const raw = BigInt(whole + padded);
|
|
35
|
-
return new Amount(raw, token.decimals, token.symbol);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Create an Amount from a raw bigint value (base units).
|
|
39
|
-
* @param raw - Raw value in base units
|
|
40
|
-
* @param decimals - Token decimal places
|
|
41
|
-
* @param symbol - Token symbol (defaults to "")
|
|
42
|
-
*/
|
|
43
|
-
static fromRaw(raw, decimals, symbol = "") {
|
|
44
|
-
if (raw < 0n)
|
|
45
|
-
throw new Error("Amount cannot be negative");
|
|
46
|
-
Amount.assertValidDecimals(decimals);
|
|
47
|
-
return new Amount(raw, decimals, symbol);
|
|
48
|
-
}
|
|
49
|
-
// ── Arithmetic ───────────────────────────────────────────────
|
|
50
|
-
/** Add two amounts. Both must have the same decimals. */
|
|
51
|
-
add(other) {
|
|
52
|
-
this.assertSameDecimals(other);
|
|
53
|
-
return new Amount(this.raw + other.raw, this.decimals, this.symbol);
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Subtract an amount.
|
|
57
|
-
* @throws If result would be negative
|
|
58
|
-
*/
|
|
59
|
-
subtract(other) {
|
|
60
|
-
this.assertSameDecimals(other);
|
|
61
|
-
if (this.raw < other.raw) {
|
|
62
|
-
throw new Error("Subtraction would result in negative amount");
|
|
63
|
-
}
|
|
64
|
-
return new Amount(this.raw - other.raw, this.decimals, this.symbol);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Multiply by a scalar bigint.
|
|
68
|
-
* @throws If scalar is negative
|
|
69
|
-
*/
|
|
70
|
-
multiply(scalar) {
|
|
71
|
-
if (scalar < 0n)
|
|
72
|
-
throw new Error("Scalar cannot be negative");
|
|
73
|
-
return new Amount(this.raw * scalar, this.decimals, this.symbol);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Divide by a scalar bigint. Truncates (no rounding).
|
|
77
|
-
* @throws If divisor is zero or negative
|
|
78
|
-
*/
|
|
79
|
-
divide(divisor) {
|
|
80
|
-
if (divisor === 0n)
|
|
81
|
-
throw new Error("Division by zero");
|
|
82
|
-
if (divisor < 0n)
|
|
83
|
-
throw new Error("Divisor cannot be negative");
|
|
84
|
-
return new Amount(this.raw / divisor, this.decimals, this.symbol);
|
|
85
|
-
}
|
|
86
|
-
// ── Comparisons ──────────────────────────────────────────────
|
|
87
|
-
eq(other) {
|
|
88
|
-
this.assertSameDecimals(other);
|
|
89
|
-
return this.raw === other.raw;
|
|
90
|
-
}
|
|
91
|
-
gt(other) {
|
|
92
|
-
this.assertSameDecimals(other);
|
|
93
|
-
return this.raw > other.raw;
|
|
94
|
-
}
|
|
95
|
-
gte(other) {
|
|
96
|
-
this.assertSameDecimals(other);
|
|
97
|
-
return this.raw >= other.raw;
|
|
98
|
-
}
|
|
99
|
-
lt(other) {
|
|
100
|
-
this.assertSameDecimals(other);
|
|
101
|
-
return this.raw < other.raw;
|
|
102
|
-
}
|
|
103
|
-
lte(other) {
|
|
104
|
-
this.assertSameDecimals(other);
|
|
105
|
-
return this.raw <= other.raw;
|
|
106
|
-
}
|
|
107
|
-
isZero() {
|
|
108
|
-
return this.raw === 0n;
|
|
109
|
-
}
|
|
110
|
-
// ── Formatting ───────────────────────────────────────────────
|
|
111
|
-
/** Returns the raw bigint value (base units). */
|
|
112
|
-
toBase() {
|
|
113
|
-
return this.raw;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Returns human-readable string (e.g., "1.5").
|
|
117
|
-
* Trailing zeros after decimal are preserved to one place minimum.
|
|
118
|
-
*/
|
|
119
|
-
toUnit() {
|
|
120
|
-
const str = this.raw.toString().padStart(this.decimals + 1, "0");
|
|
121
|
-
const whole = str.slice(0, str.length - this.decimals) || "0";
|
|
122
|
-
const fraction = str.slice(str.length - this.decimals);
|
|
123
|
-
if (this.decimals === 0)
|
|
124
|
-
return whole;
|
|
125
|
-
// Trim trailing zeros but keep at least one decimal place
|
|
126
|
-
const trimmed = fraction.replace(/0+$/, "") || "0";
|
|
127
|
-
return `${whole}.${trimmed}`;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Returns formatted string with symbol (e.g., "1.5 USDC").
|
|
131
|
-
* @param compressed - If true, shorten large numbers (e.g., "1.5M USDC")
|
|
132
|
-
*/
|
|
133
|
-
toFormatted(compressed = false) {
|
|
134
|
-
if (compressed) {
|
|
135
|
-
// Use BigInt arithmetic to avoid parseFloat precision loss
|
|
136
|
-
const scale = 10n ** BigInt(this.decimals);
|
|
137
|
-
const wholePart = this.raw / scale;
|
|
138
|
-
let display;
|
|
139
|
-
if (wholePart >= 1000000n) {
|
|
140
|
-
const major = wholePart / 1000000n;
|
|
141
|
-
const minor = (wholePart % 1000000n) / 100000n; // one decimal
|
|
142
|
-
display = `${major}.${minor}M`;
|
|
143
|
-
}
|
|
144
|
-
else if (wholePart >= 1000n) {
|
|
145
|
-
const major = wholePart / 1000n;
|
|
146
|
-
const minor = (wholePart % 1000n) / 100n; // one decimal
|
|
147
|
-
display = `${major}.${minor}K`;
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
display = this.toUnit();
|
|
151
|
-
}
|
|
152
|
-
return this.symbol ? `${display} ${this.symbol}` : display;
|
|
153
|
-
}
|
|
154
|
-
return this.symbol ? `${this.toUnit()} ${this.symbol}` : this.toUnit();
|
|
155
|
-
}
|
|
156
|
-
// ── Internal ─────────────────────────────────────────────────
|
|
157
|
-
assertSameDecimals(other) {
|
|
158
|
-
if (this.decimals !== other.decimals) {
|
|
159
|
-
throw new Error(`Cannot operate on amounts with different decimals: ${this.decimals} vs ${other.decimals}`);
|
|
160
|
-
}
|
|
161
|
-
if (this.symbol && other.symbol && this.symbol !== other.symbol) {
|
|
162
|
-
throw new Error(`Cannot operate on amounts with different symbols: ${this.symbol} vs ${other.symbol}`);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
//# sourceMappingURL=amount.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../../src/tokens/amount.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,MAAM,OAAO,MAAM;IAQjB,YAAoB,GAAW,EAAE,QAAgB,EAAE,MAAc;QAC/D,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEO,MAAM,CAAC,mBAAmB,CAAC,QAAgB;QACjD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;YAChD,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;IAED,gEAAgE;IAEhE;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,KAAa,EAAE,KAAgB;QAC1C,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC3C,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AAI,IAAI,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CACb,sDAAsD,IAAI,CAAC,QAAQ,OAAO,KAAK,CAAC,QAAQ,EAAE,CAC3F,CAAC;QACJ,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;YAChE,MAAM,IAAI,KAAK,CACb,qDAAqD,IAAI,CAAC,MAAM,OAAO,KAAK,CAAC,MAAM,EAAE,CACtF,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
package/dist/tokens/erc20.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { Account, Call } from "starknet";
|
|
2
|
-
import { Amount, type TokenInfo } from "./amount.js";
|
|
3
|
-
/**
|
|
4
|
-
* Typed ERC20 contract wrapper.
|
|
5
|
-
* Generates Call objects for approve/transfer and queries for balance/allowance.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* const usdc = new Erc20({ symbol: 'USDC', decimals: 6, address: '0x...' }, account);
|
|
9
|
-
* const balance = await usdc.balanceOf(myAddress);
|
|
10
|
-
* console.log(balance.toFormatted()); // "150.5 USDC"
|
|
11
|
-
*/
|
|
12
|
-
export declare class Erc20 {
|
|
13
|
-
private readonly token;
|
|
14
|
-
private readonly account;
|
|
15
|
-
constructor(token: TokenInfo, account: Account);
|
|
16
|
-
/**
|
|
17
|
-
* Query the balance of an address.
|
|
18
|
-
* @returns Amount representing the balance
|
|
19
|
-
*/
|
|
20
|
-
balanceOf(address: string): Promise<Amount>;
|
|
21
|
-
/**
|
|
22
|
-
* Query the allowance of owner for spender.
|
|
23
|
-
* @returns Amount representing the allowance
|
|
24
|
-
*/
|
|
25
|
-
allowance(owner: string, spender: string): Promise<Amount>;
|
|
26
|
-
/**
|
|
27
|
-
* Build an approve Call (does not execute).
|
|
28
|
-
* @returns Call object for use with TxBuilder or Account.execute()
|
|
29
|
-
*/
|
|
30
|
-
approveCall(spender: string, amount: Amount): Call;
|
|
31
|
-
/**
|
|
32
|
-
* Build a transfer Call (does not execute).
|
|
33
|
-
* @returns Call object for use with TxBuilder or Account.execute()
|
|
34
|
-
*/
|
|
35
|
-
transferCall(recipient: string, amount: Amount): Call;
|
|
36
|
-
private assertCompatibleAmount;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=erc20.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"erc20.d.ts","sourceRoot":"","sources":["../../src/tokens/erc20.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAErD;;;;;;;;GAQG;AACH,qBAAa,KAAK;IAChB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAY;IAClC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;gBAEtB,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO;IAK9C;;;OAGG;IACG,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAWjD;;;OAGG;IACG,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAUhE;;;OAGG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAUlD;;;OAGG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAUrD,OAAO,CAAC,sBAAsB;CAY/B"}
|
package/dist/tokens/erc20.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { uint256 } from "starknet";
|
|
2
|
-
import { Amount } from "./amount.js";
|
|
3
|
-
/**
|
|
4
|
-
* Typed ERC20 contract wrapper.
|
|
5
|
-
* Generates Call objects for approve/transfer and queries for balance/allowance.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* const usdc = new Erc20({ symbol: 'USDC', decimals: 6, address: '0x...' }, account);
|
|
9
|
-
* const balance = await usdc.balanceOf(myAddress);
|
|
10
|
-
* console.log(balance.toFormatted()); // "150.5 USDC"
|
|
11
|
-
*/
|
|
12
|
-
export class Erc20 {
|
|
13
|
-
constructor(token, account) {
|
|
14
|
-
this.token = token;
|
|
15
|
-
this.account = account;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Query the balance of an address.
|
|
19
|
-
* @returns Amount representing the balance
|
|
20
|
-
*/
|
|
21
|
-
async balanceOf(address) {
|
|
22
|
-
const result = await this.account.callContract({
|
|
23
|
-
contractAddress: this.token.address,
|
|
24
|
-
entrypoint: "balanceOf",
|
|
25
|
-
calldata: [address],
|
|
26
|
-
});
|
|
27
|
-
// StarkNet returns uint256 as [low, high]
|
|
28
|
-
const raw = uint256.uint256ToBN({ low: result[0], high: result[1] });
|
|
29
|
-
return Amount.fromRaw(raw, this.token.decimals, this.token.symbol);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Query the allowance of owner for spender.
|
|
33
|
-
* @returns Amount representing the allowance
|
|
34
|
-
*/
|
|
35
|
-
async allowance(owner, spender) {
|
|
36
|
-
const result = await this.account.callContract({
|
|
37
|
-
contractAddress: this.token.address,
|
|
38
|
-
entrypoint: "allowance",
|
|
39
|
-
calldata: [owner, spender],
|
|
40
|
-
});
|
|
41
|
-
const raw = uint256.uint256ToBN({ low: result[0], high: result[1] });
|
|
42
|
-
return Amount.fromRaw(raw, this.token.decimals, this.token.symbol);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Build an approve Call (does not execute).
|
|
46
|
-
* @returns Call object for use with TxBuilder or Account.execute()
|
|
47
|
-
*/
|
|
48
|
-
approveCall(spender, amount) {
|
|
49
|
-
this.assertCompatibleAmount(amount);
|
|
50
|
-
const u256 = uint256.bnToUint256(amount.toBase());
|
|
51
|
-
return {
|
|
52
|
-
contractAddress: this.token.address,
|
|
53
|
-
entrypoint: "approve",
|
|
54
|
-
calldata: [spender, u256.low.toString(), u256.high.toString()],
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Build a transfer Call (does not execute).
|
|
59
|
-
* @returns Call object for use with TxBuilder or Account.execute()
|
|
60
|
-
*/
|
|
61
|
-
transferCall(recipient, amount) {
|
|
62
|
-
this.assertCompatibleAmount(amount);
|
|
63
|
-
const u256 = uint256.bnToUint256(amount.toBase());
|
|
64
|
-
return {
|
|
65
|
-
contractAddress: this.token.address,
|
|
66
|
-
entrypoint: "transfer",
|
|
67
|
-
calldata: [recipient, u256.low.toString(), u256.high.toString()],
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
assertCompatibleAmount(amount) {
|
|
71
|
-
if (amount.decimals !== this.token.decimals) {
|
|
72
|
-
throw new Error(`Amount decimals mismatch: expected ${this.token.decimals}, got ${amount.decimals}`);
|
|
73
|
-
}
|
|
74
|
-
if (amount.symbol && amount.symbol !== this.token.symbol) {
|
|
75
|
-
throw new Error(`Amount symbol mismatch: expected ${this.token.symbol}, got ${amount.symbol}`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=erc20.js.map
|
package/dist/tokens/erc20.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"erc20.js","sourceRoot":"","sources":["../../src/tokens/erc20.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,MAAM,EAAkB,MAAM,aAAa,CAAC;AAErD;;;;;;;;GAQG;AACH,MAAM,OAAO,KAAK;IAIhB,YAAY,KAAgB,EAAE,OAAgB;QAC5C,IAAI,CAA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QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"symbol": "ETH",
|
|
4
|
-
"decimals": 18,
|
|
5
|
-
"address": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
|
|
6
|
-
"name": "Ether"
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
"symbol": "USDC",
|
|
10
|
-
"decimals": 6,
|
|
11
|
-
"address": "0x033068f6539f8e6e6b131e6b2b814e6c34a5224bc66947c47dab9dfee93b35fb",
|
|
12
|
-
"name": "USD Coin"
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"symbol": "USDT",
|
|
16
|
-
"decimals": 6,
|
|
17
|
-
"address": "0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8",
|
|
18
|
-
"name": "Tether USD"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"symbol": "DAI",
|
|
22
|
-
"decimals": 18,
|
|
23
|
-
"address": "0x00da114221cb83fa859dbdb4c44beeaa0bb37c7537ad5ae66fe5e0efd20e6eb3",
|
|
24
|
-
"name": "Dai Stablecoin"
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"symbol": "STRK",
|
|
28
|
-
"decimals": 18,
|
|
29
|
-
"address": "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
|
|
30
|
-
"name": "Starknet Token"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"symbol": "WBTC",
|
|
34
|
-
"decimals": 8,
|
|
35
|
-
"address": "0x03fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac",
|
|
36
|
-
"name": "Wrapped Bitcoin"
|
|
37
|
-
}
|
|
38
|
-
]
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"symbol": "ETH",
|
|
4
|
-
"decimals": 18,
|
|
5
|
-
"address": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
|
|
6
|
-
"name": "Ether"
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
"symbol": "USDC",
|
|
10
|
-
"decimals": 6,
|
|
11
|
-
"address": "0x005a643907b9a4bc6a55e9069c4fd5fd1f5c79a22470690f75556c4736e34426",
|
|
12
|
-
"name": "USD Coin (Testnet)"
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"symbol": "STRK",
|
|
16
|
-
"decimals": 18,
|
|
17
|
-
"address": "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
|
|
18
|
-
"name": "Starknet Token"
|
|
19
|
-
}
|
|
20
|
-
]
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { TokenInfo } from "./amount.js";
|
|
2
|
-
export type Network = "mainnet" | "sepolia";
|
|
3
|
-
interface TokenEntry extends TokenInfo {
|
|
4
|
-
name: string;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Registry for looking up token metadata by symbol or address.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* const registry = new TokenRegistry('mainnet');
|
|
11
|
-
* const usdc = registry.bySymbol('USDC');
|
|
12
|
-
* const amount = Amount.parse('10.0', usdc!);
|
|
13
|
-
*/
|
|
14
|
-
export declare class TokenRegistry {
|
|
15
|
-
private readonly tokens;
|
|
16
|
-
private readonly bySymbolMap;
|
|
17
|
-
private readonly byAddressMap;
|
|
18
|
-
constructor(network: Network);
|
|
19
|
-
/** Find a token by its symbol (case-insensitive). */
|
|
20
|
-
bySymbol(symbol: string): TokenEntry | undefined;
|
|
21
|
-
/** Find a token by its contract address (case-insensitive). */
|
|
22
|
-
byAddress(address: string): TokenEntry | undefined;
|
|
23
|
-
/** List all tokens in this registry. */
|
|
24
|
-
all(): TokenEntry[];
|
|
25
|
-
}
|
|
26
|
-
export {};
|
|
27
|
-
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/tokens/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAI7C,MAAM,MAAM,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;AAE5C,UAAU,UAAW,SAAQ,SAAS;IACpC,IAAI,EAAE,MAAM,CAAC;CACd;AAOD;;;;;;;GAOG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA0B;IACtD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA0B;gBAE3C,OAAO,EAAE,OAAO;IAU5B,qDAAqD;IACrD,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAIhD,+DAA+D;IAC/D,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAIlD,wCAAwC;IACxC,GAAG,IAAI,UAAU,EAAE;CAGpB"}
|
package/dist/tokens/registry.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import mainnetTokens from "./presets/mainnet.json" with { type: "json" };
|
|
2
|
-
import sepoliaTokens from "./presets/sepolia.json" with { type: "json" };
|
|
3
|
-
const PRESETS = {
|
|
4
|
-
mainnet: mainnetTokens,
|
|
5
|
-
sepolia: sepoliaTokens,
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Registry for looking up token metadata by symbol or address.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* const registry = new TokenRegistry('mainnet');
|
|
12
|
-
* const usdc = registry.bySymbol('USDC');
|
|
13
|
-
* const amount = Amount.parse('10.0', usdc!);
|
|
14
|
-
*/
|
|
15
|
-
export class TokenRegistry {
|
|
16
|
-
constructor(network) {
|
|
17
|
-
const preset = PRESETS[network];
|
|
18
|
-
if (!preset) {
|
|
19
|
-
throw new Error(`Invalid network: "${network}". Must be "mainnet" or "sepolia".`);
|
|
20
|
-
}
|
|
21
|
-
this.tokens = preset;
|
|
22
|
-
this.bySymbolMap = new Map(preset.map((t) => [t.symbol.toUpperCase(), t]));
|
|
23
|
-
this.byAddressMap = new Map(preset.map((t) => [t.address.toLowerCase(), t]));
|
|
24
|
-
}
|
|
25
|
-
/** Find a token by its symbol (case-insensitive). */
|
|
26
|
-
bySymbol(symbol) {
|
|
27
|
-
return this.bySymbolMap.get(symbol.toUpperCase());
|
|
28
|
-
}
|
|
29
|
-
/** Find a token by its contract address (case-insensitive). */
|
|
30
|
-
byAddress(address) {
|
|
31
|
-
return this.byAddressMap.get(address.toLowerCase());
|
|
32
|
-
}
|
|
33
|
-
/** List all tokens in this registry. */
|
|
34
|
-
all() {
|
|
35
|
-
return [...this.tokens];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=registry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/tokens/registry.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,MAAM,wBAAwB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACzE,OAAO,aAAa,MAAM,wBAAwB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAQzE,MAAM,OAAO,GAAkC;IAC7C,OAAO,EAAE,aAA6B;IACtC,OAAO,EAAE,aAA6B;CACvC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,OAAO,aAAa;IAKxB,YAAY,OAAgB;QAC1B,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;QAChC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,qBAAqB,OAAO,oCAAoC,CAAC,CAAC;QACpF,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3E,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/E,CAAC;IAED,qDAAqD;IACrD,QAAQ,CAAC,MAAc;QACrB,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;IACpD,CAAC;IAED,+DAA+D;IAC/D,SAAS,CAAC,OAAe;QACvB,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IACtD,CAAC;IAED,wCAAwC;IACxC,GAAG;QACD,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import type { Account, Call, InvokeFunctionResponse, EstimateFeeResponseOverhead } from "starknet";
|
|
2
|
-
import type { PaymasterAdapter } from "@chipi-stack/types";
|
|
3
|
-
import type { TransferTarget, PreflightResult } from "./types.js";
|
|
4
|
-
/**
|
|
5
|
-
* Fluent builder for batching Starknet calls.
|
|
6
|
-
* All calls execute atomically via Account.execute().
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* const result = await new TxBuilder(account)
|
|
10
|
-
* .approve(tokenAddr, spenderAddr, amount)
|
|
11
|
-
* .transfer(tokenAddr, [{ to: recipient, amount: 1000n }])
|
|
12
|
-
* .send();
|
|
13
|
-
*/
|
|
14
|
-
export interface TxBuilderOptions {
|
|
15
|
-
/** PaymasterAdapter for gasless transactions via sendSponsored(). */
|
|
16
|
-
paymaster?: PaymasterAdapter;
|
|
17
|
-
}
|
|
18
|
-
export declare class TxBuilder {
|
|
19
|
-
private readonly account;
|
|
20
|
-
private readonly paymaster?;
|
|
21
|
-
private readonly _calls;
|
|
22
|
-
private sent;
|
|
23
|
-
constructor(account: Account, opts?: TxBuilderOptions);
|
|
24
|
-
/** Returns a copy of the current call batch. */
|
|
25
|
-
calls(): Call[];
|
|
26
|
-
/**
|
|
27
|
-
* Add one or more raw calls.
|
|
28
|
-
* @param call - A single Call or array of Calls
|
|
29
|
-
*/
|
|
30
|
-
add(call: Call | Call[]): this;
|
|
31
|
-
/**
|
|
32
|
-
* Add an ERC20 approve call.
|
|
33
|
-
* @param token - Token contract address
|
|
34
|
-
* @param spender - Address to approve
|
|
35
|
-
* @param amount - Raw amount in base units
|
|
36
|
-
*/
|
|
37
|
-
approve(token: string, spender: string, amount: bigint): this;
|
|
38
|
-
/**
|
|
39
|
-
* Add one or more ERC20 transfer calls.
|
|
40
|
-
* @param token - Token contract address
|
|
41
|
-
* @param targets - Array of { to, amount } pairs
|
|
42
|
-
*/
|
|
43
|
-
transfer(token: string, targets: TransferTarget[]): this;
|
|
44
|
-
/**
|
|
45
|
-
* Execute all batched calls atomically.
|
|
46
|
-
* @throws If no calls have been added
|
|
47
|
-
* @throws If send() was already called
|
|
48
|
-
*/
|
|
49
|
-
send(): Promise<InvokeFunctionResponse>;
|
|
50
|
-
/**
|
|
51
|
-
* Execute via a paymaster (gasless). Requires a PaymasterAdapter.
|
|
52
|
-
*
|
|
53
|
-
* The paymaster handles: prepare typed data -> sign -> submit.
|
|
54
|
-
* For external wallets (Argent X, Braavos), signing triggers the wallet popup.
|
|
55
|
-
*
|
|
56
|
-
* @returns Transaction hash
|
|
57
|
-
* @throws If no paymaster was configured
|
|
58
|
-
* @throws If no calls have been added
|
|
59
|
-
* @throws If sendSponsored() or send() was already called
|
|
60
|
-
*/
|
|
61
|
-
sendSponsored(): Promise<string>;
|
|
62
|
-
/**
|
|
63
|
-
* Estimate fees for the current batch without executing.
|
|
64
|
-
* @throws If no calls have been added
|
|
65
|
-
*/
|
|
66
|
-
estimateFee(): Promise<EstimateFeeResponseOverhead>;
|
|
67
|
-
/**
|
|
68
|
-
* Simulate the transaction without submitting to the network.
|
|
69
|
-
* Useful for checking if a transaction would succeed.
|
|
70
|
-
* @throws If no calls have been added
|
|
71
|
-
*/
|
|
72
|
-
preflight(): Promise<PreflightResult>;
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=tx-builder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tx-builder.d.ts","sourceRoot":"","sources":["../../src/transactions/tx-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAEnG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElE;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAC/B,qEAAqE;IACrE,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAmB;IAC9C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IACrC,OAAO,CAAC,IAAI,CAAS;gBAET,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,gBAAgB;IAKrD,gDAAgD;IAChD,KAAK,IAAI,IAAI,EAAE;IAIf;;;OAGG;IACH,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI;IAM9B;;;;;OAKG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAW7D;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI;IAaxD;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,sBAAsB,CAAC;IAQ7C;;;;;;;;;;OAUG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAYtC;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,2BAA2B,CAAC;IAKzD;;;;OAIG;IACG,SAAS,IAAI,OAAO,CAAC,eAAe,CAAC;CAW5C"}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { uint256 } from "starknet";
|
|
2
|
-
export class TxBuilder {
|
|
3
|
-
constructor(account, opts) {
|
|
4
|
-
this._calls = [];
|
|
5
|
-
this.sent = false;
|
|
6
|
-
this.account = account;
|
|
7
|
-
this.paymaster = opts?.paymaster;
|
|
8
|
-
}
|
|
9
|
-
/** Returns a copy of the current call batch. */
|
|
10
|
-
calls() {
|
|
11
|
-
return [...this._calls];
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Add one or more raw calls.
|
|
15
|
-
* @param call - A single Call or array of Calls
|
|
16
|
-
*/
|
|
17
|
-
add(call) {
|
|
18
|
-
const toAdd = Array.isArray(call) ? call : [call];
|
|
19
|
-
this._calls.push(...toAdd);
|
|
20
|
-
return this;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Add an ERC20 approve call.
|
|
24
|
-
* @param token - Token contract address
|
|
25
|
-
* @param spender - Address to approve
|
|
26
|
-
* @param amount - Raw amount in base units
|
|
27
|
-
*/
|
|
28
|
-
approve(token, spender, amount) {
|
|
29
|
-
if (amount < 0n)
|
|
30
|
-
throw new RangeError("Approve amount cannot be negative");
|
|
31
|
-
const u256 = uint256.bnToUint256(amount);
|
|
32
|
-
this._calls.push({
|
|
33
|
-
contractAddress: token,
|
|
34
|
-
entrypoint: "approve",
|
|
35
|
-
calldata: [spender, u256.low.toString(), u256.high.toString()],
|
|
36
|
-
});
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Add one or more ERC20 transfer calls.
|
|
41
|
-
* @param token - Token contract address
|
|
42
|
-
* @param targets - Array of { to, amount } pairs
|
|
43
|
-
*/
|
|
44
|
-
transfer(token, targets) {
|
|
45
|
-
for (const { to, amount } of targets) {
|
|
46
|
-
if (amount < 0n)
|
|
47
|
-
throw new RangeError("Transfer amount cannot be negative");
|
|
48
|
-
const u256 = uint256.bnToUint256(amount);
|
|
49
|
-
this._calls.push({
|
|
50
|
-
contractAddress: token,
|
|
51
|
-
entrypoint: "transfer",
|
|
52
|
-
calldata: [to, u256.low.toString(), u256.high.toString()],
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Execute all batched calls atomically.
|
|
59
|
-
* @throws If no calls have been added
|
|
60
|
-
* @throws If send() was already called
|
|
61
|
-
*/
|
|
62
|
-
async send() {
|
|
63
|
-
if (this.sent)
|
|
64
|
-
throw new Error("TxBuilder already sent — create a new builder");
|
|
65
|
-
if (this._calls.length === 0)
|
|
66
|
-
throw new Error("No calls to execute");
|
|
67
|
-
this.sent = true;
|
|
68
|
-
const calls = [...this._calls];
|
|
69
|
-
return this.account.execute(calls);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Execute via a paymaster (gasless). Requires a PaymasterAdapter.
|
|
73
|
-
*
|
|
74
|
-
* The paymaster handles: prepare typed data -> sign -> submit.
|
|
75
|
-
* For external wallets (Argent X, Braavos), signing triggers the wallet popup.
|
|
76
|
-
*
|
|
77
|
-
* @returns Transaction hash
|
|
78
|
-
* @throws If no paymaster was configured
|
|
79
|
-
* @throws If no calls have been added
|
|
80
|
-
* @throws If sendSponsored() or send() was already called
|
|
81
|
-
*/
|
|
82
|
-
async sendSponsored() {
|
|
83
|
-
if (!this.paymaster) {
|
|
84
|
-
throw new Error("No paymaster configured. Pass { paymaster } to TxBuilder constructor.");
|
|
85
|
-
}
|
|
86
|
-
if (this.sent)
|
|
87
|
-
throw new Error("TxBuilder already sent — create a new builder");
|
|
88
|
-
if (this._calls.length === 0)
|
|
89
|
-
throw new Error("No calls to execute");
|
|
90
|
-
this.sent = true;
|
|
91
|
-
return this.paymaster.execute({ account: this.account, calls: [...this._calls] });
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Estimate fees for the current batch without executing.
|
|
95
|
-
* @throws If no calls have been added
|
|
96
|
-
*/
|
|
97
|
-
async estimateFee() {
|
|
98
|
-
if (this._calls.length === 0)
|
|
99
|
-
throw new Error("No calls to estimate");
|
|
100
|
-
return this.account.estimateInvokeFee([...this._calls]);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Simulate the transaction without submitting to the network.
|
|
104
|
-
* Useful for checking if a transaction would succeed.
|
|
105
|
-
* @throws If no calls have been added
|
|
106
|
-
*/
|
|
107
|
-
async preflight() {
|
|
108
|
-
if (this._calls.length === 0)
|
|
109
|
-
throw new Error("No calls to preflight");
|
|
110
|
-
const result = await this.account.simulateTransaction([{ type: "INVOKE", payload: [...this._calls] }], { skipValidate: false });
|
|
111
|
-
if (!result || result.length === 0) {
|
|
112
|
-
throw new Error("Simulation returned no results");
|
|
113
|
-
}
|
|
114
|
-
return result[0];
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
//# sourceMappingURL=tx-builder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tx-builder.js","sourceRoot":"","sources":["../../src/transactions/tx-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAmBnC,MAAM,OAAO,SAAS;IAMpB,YAAY,OAAgB,EAAE,IAAuB;QAHpC,WAAM,GAAW,EAAE,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