sally-defi-ts-sdk 0.3.2

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.
Files changed (125) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +263 -0
  3. package/dist/aio/client.d.ts +93 -0
  4. package/dist/aio/client.d.ts.map +1 -0
  5. package/dist/aio/client.js +283 -0
  6. package/dist/aio/client.js.map +1 -0
  7. package/dist/aio/index.d.ts +20 -0
  8. package/dist/aio/index.d.ts.map +1 -0
  9. package/dist/aio/index.js +19 -0
  10. package/dist/aio/index.js.map +1 -0
  11. package/dist/aio/modules/fees.d.ts +19 -0
  12. package/dist/aio/modules/fees.d.ts.map +1 -0
  13. package/dist/aio/modules/fees.js +47 -0
  14. package/dist/aio/modules/fees.js.map +1 -0
  15. package/dist/aio/modules/liquidity.d.ts +47 -0
  16. package/dist/aio/modules/liquidity.d.ts.map +1 -0
  17. package/dist/aio/modules/liquidity.js +115 -0
  18. package/dist/aio/modules/liquidity.js.map +1 -0
  19. package/dist/aio/modules/prices.d.ts +18 -0
  20. package/dist/aio/modules/prices.d.ts.map +1 -0
  21. package/dist/aio/modules/prices.js +48 -0
  22. package/dist/aio/modules/prices.js.map +1 -0
  23. package/dist/aio/modules/swap.d.ts +50 -0
  24. package/dist/aio/modules/swap.d.ts.map +1 -0
  25. package/dist/aio/modules/swap.js +267 -0
  26. package/dist/aio/modules/swap.js.map +1 -0
  27. package/dist/aio/modules/wallet.d.ts +13 -0
  28. package/dist/aio/modules/wallet.d.ts.map +1 -0
  29. package/dist/aio/modules/wallet.js +27 -0
  30. package/dist/aio/modules/wallet.js.map +1 -0
  31. package/dist/aio/token.d.ts +19 -0
  32. package/dist/aio/token.d.ts.map +1 -0
  33. package/dist/aio/token.js +50 -0
  34. package/dist/aio/token.js.map +1 -0
  35. package/dist/client.d.ts +142 -0
  36. package/dist/client.d.ts.map +1 -0
  37. package/dist/client.js +452 -0
  38. package/dist/client.js.map +1 -0
  39. package/dist/constants.d.ts +36 -0
  40. package/dist/constants.d.ts.map +1 -0
  41. package/dist/constants.js +39 -0
  42. package/dist/constants.js.map +1 -0
  43. package/dist/data/deployment.json +1 -0
  44. package/dist/deployment.d.ts +44 -0
  45. package/dist/deployment.d.ts.map +1 -0
  46. package/dist/deployment.js +118 -0
  47. package/dist/deployment.js.map +1 -0
  48. package/dist/errors.d.ts +57 -0
  49. package/dist/errors.d.ts.map +1 -0
  50. package/dist/errors.js +197 -0
  51. package/dist/errors.js.map +1 -0
  52. package/dist/index.d.ts +48 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/dist/index.js +47 -0
  55. package/dist/index.js.map +1 -0
  56. package/dist/modules/fees.d.ts +32 -0
  57. package/dist/modules/fees.d.ts.map +1 -0
  58. package/dist/modules/fees.js +64 -0
  59. package/dist/modules/fees.js.map +1 -0
  60. package/dist/modules/liquidity.d.ts +134 -0
  61. package/dist/modules/liquidity.d.ts.map +1 -0
  62. package/dist/modules/liquidity.js +277 -0
  63. package/dist/modules/liquidity.js.map +1 -0
  64. package/dist/modules/prices.d.ts +47 -0
  65. package/dist/modules/prices.d.ts.map +1 -0
  66. package/dist/modules/prices.js +85 -0
  67. package/dist/modules/prices.js.map +1 -0
  68. package/dist/modules/swap.d.ts +102 -0
  69. package/dist/modules/swap.d.ts.map +1 -0
  70. package/dist/modules/swap.js +400 -0
  71. package/dist/modules/swap.js.map +1 -0
  72. package/dist/modules/wallet.d.ts +16 -0
  73. package/dist/modules/wallet.d.ts.map +1 -0
  74. package/dist/modules/wallet.js +30 -0
  75. package/dist/modules/wallet.js.map +1 -0
  76. package/dist/permit2.d.ts +97 -0
  77. package/dist/permit2.d.ts.map +1 -0
  78. package/dist/permit2.js +130 -0
  79. package/dist/permit2.js.map +1 -0
  80. package/dist/previews.d.ts +57 -0
  81. package/dist/previews.d.ts.map +1 -0
  82. package/dist/previews.js +69 -0
  83. package/dist/previews.js.map +1 -0
  84. package/dist/safety.d.ts +80 -0
  85. package/dist/safety.d.ts.map +1 -0
  86. package/dist/safety.js +133 -0
  87. package/dist/safety.js.map +1 -0
  88. package/dist/token.d.ts +215 -0
  89. package/dist/token.d.ts.map +1 -0
  90. package/dist/token.js +239 -0
  91. package/dist/token.js.map +1 -0
  92. package/dist/types.d.ts +229 -0
  93. package/dist/types.d.ts.map +1 -0
  94. package/dist/types.js +462 -0
  95. package/dist/types.js.map +1 -0
  96. package/dist/util.d.ts +13 -0
  97. package/dist/util.d.ts.map +1 -0
  98. package/dist/util.js +22 -0
  99. package/dist/util.js.map +1 -0
  100. package/package.json +48 -0
  101. package/src/aio/client.ts +329 -0
  102. package/src/aio/index.ts +20 -0
  103. package/src/aio/modules/fees.ts +60 -0
  104. package/src/aio/modules/liquidity.ts +181 -0
  105. package/src/aio/modules/prices.ts +57 -0
  106. package/src/aio/modules/swap.ts +347 -0
  107. package/src/aio/modules/wallet.ts +34 -0
  108. package/src/aio/token.ts +59 -0
  109. package/src/client.ts +526 -0
  110. package/src/constants.ts +43 -0
  111. package/src/data/deployment.json +1 -0
  112. package/src/deployment.ts +132 -0
  113. package/src/errors.ts +215 -0
  114. package/src/index.ts +90 -0
  115. package/src/modules/fees.ts +78 -0
  116. package/src/modules/liquidity.ts +446 -0
  117. package/src/modules/prices.ts +97 -0
  118. package/src/modules/swap.ts +502 -0
  119. package/src/modules/wallet.ts +37 -0
  120. package/src/permit2.ts +169 -0
  121. package/src/previews.ts +95 -0
  122. package/src/safety.ts +152 -0
  123. package/src/token.ts +254 -0
  124. package/src/types.ts +438 -0
  125. package/src/util.ts +20 -0
@@ -0,0 +1,215 @@
1
+ /**
2
+ * ERC-20 helpers: metadata, balances, approvals and human <-> raw amounts.
3
+ *
4
+ * Anything with non-18 decimals (USDC = 6, WBTC = 8) needs explicit scaling.
5
+ * {@link TokenAmount} carries the decimals with the value so you never multiply
6
+ * by the wrong power.
7
+ */
8
+ import { Contract } from "ethers";
9
+ import type { SallyClient } from "./client.js";
10
+ export declare const NATIVE = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
11
+ export declare const ZERO = "0x0000000000000000000000000000000000000000";
12
+ export declare const MAX_UINT256: bigint;
13
+ export declare const ERC20_ABI: readonly [{
14
+ readonly name: "name";
15
+ readonly type: "function";
16
+ readonly stateMutability: "view";
17
+ readonly inputs: readonly [];
18
+ readonly outputs: readonly [{
19
+ readonly type: "string";
20
+ }];
21
+ }, {
22
+ readonly name: "symbol";
23
+ readonly type: "function";
24
+ readonly stateMutability: "view";
25
+ readonly inputs: readonly [];
26
+ readonly outputs: readonly [{
27
+ readonly type: "string";
28
+ }];
29
+ }, {
30
+ readonly name: "decimals";
31
+ readonly type: "function";
32
+ readonly stateMutability: "view";
33
+ readonly inputs: readonly [];
34
+ readonly outputs: readonly [{
35
+ readonly type: "uint8";
36
+ }];
37
+ }, {
38
+ readonly name: "totalSupply";
39
+ readonly type: "function";
40
+ readonly stateMutability: "view";
41
+ readonly inputs: readonly [];
42
+ readonly outputs: readonly [{
43
+ readonly type: "uint256";
44
+ }];
45
+ }, {
46
+ readonly name: "balanceOf";
47
+ readonly type: "function";
48
+ readonly stateMutability: "view";
49
+ readonly inputs: readonly [{
50
+ readonly name: "a";
51
+ readonly type: "address";
52
+ }];
53
+ readonly outputs: readonly [{
54
+ readonly type: "uint256";
55
+ }];
56
+ }, {
57
+ readonly name: "allowance";
58
+ readonly type: "function";
59
+ readonly stateMutability: "view";
60
+ readonly inputs: readonly [{
61
+ readonly name: "o";
62
+ readonly type: "address";
63
+ }, {
64
+ readonly name: "s";
65
+ readonly type: "address";
66
+ }];
67
+ readonly outputs: readonly [{
68
+ readonly type: "uint256";
69
+ }];
70
+ }, {
71
+ readonly name: "approve";
72
+ readonly type: "function";
73
+ readonly stateMutability: "nonpayable";
74
+ readonly inputs: readonly [{
75
+ readonly name: "s";
76
+ readonly type: "address";
77
+ }, {
78
+ readonly name: "v";
79
+ readonly type: "uint256";
80
+ }];
81
+ readonly outputs: readonly [{
82
+ readonly type: "bool";
83
+ }];
84
+ }, {
85
+ readonly name: "transfer";
86
+ readonly type: "function";
87
+ readonly stateMutability: "nonpayable";
88
+ readonly inputs: readonly [{
89
+ readonly name: "t";
90
+ readonly type: "address";
91
+ }, {
92
+ readonly name: "v";
93
+ readonly type: "uint256";
94
+ }];
95
+ readonly outputs: readonly [{
96
+ readonly type: "bool";
97
+ }];
98
+ }, {
99
+ readonly name: "nonces";
100
+ readonly type: "function";
101
+ readonly stateMutability: "view";
102
+ readonly inputs: readonly [{
103
+ readonly name: "o";
104
+ readonly type: "address";
105
+ }];
106
+ readonly outputs: readonly [{
107
+ readonly type: "uint256";
108
+ }];
109
+ }, {
110
+ readonly name: "DOMAIN_SEPARATOR";
111
+ readonly type: "function";
112
+ readonly stateMutability: "view";
113
+ readonly inputs: readonly [];
114
+ readonly outputs: readonly [{
115
+ readonly type: "bytes32";
116
+ }];
117
+ }, {
118
+ readonly name: "version";
119
+ readonly type: "function";
120
+ readonly stateMutability: "view";
121
+ readonly inputs: readonly [];
122
+ readonly outputs: readonly [{
123
+ readonly type: "string";
124
+ }];
125
+ }, {
126
+ readonly name: "permit";
127
+ readonly type: "function";
128
+ readonly stateMutability: "nonpayable";
129
+ readonly inputs: readonly [{
130
+ readonly name: "owner";
131
+ readonly type: "address";
132
+ }, {
133
+ readonly name: "spender";
134
+ readonly type: "address";
135
+ }, {
136
+ readonly name: "value";
137
+ readonly type: "uint256";
138
+ }, {
139
+ readonly name: "deadline";
140
+ readonly type: "uint256";
141
+ }, {
142
+ readonly name: "v";
143
+ readonly type: "uint8";
144
+ }, {
145
+ readonly name: "r";
146
+ readonly type: "bytes32";
147
+ }, {
148
+ readonly name: "s";
149
+ readonly type: "bytes32";
150
+ }];
151
+ readonly outputs: readonly [];
152
+ }];
153
+ export declare function isNative(address: string): boolean;
154
+ /**
155
+ * Convert a human amount to raw base units. Sub-unit precision is truncated
156
+ * toward zero (e.g. `0.0000001` of a 6-decimal token -> `0` raw), matching
157
+ * Python's `int()` semantics.
158
+ */
159
+ export declare function humanToRaw(amount: string | number | bigint, decimals: number): bigint;
160
+ /** Convert raw base units back to a human float. */
161
+ export declare function rawToHuman(raw: bigint, decimals: number): number;
162
+ /**
163
+ * A token amount that knows its own decimals.
164
+ *
165
+ * `TokenAmount.fromHuman("1.5", 6).raw` -> 1500000n (1.5 USDC)
166
+ */
167
+ export declare class TokenAmount {
168
+ readonly raw: bigint;
169
+ readonly decimals: number;
170
+ constructor(raw: bigint, decimals: number);
171
+ static fromHuman(amount: string | number | bigint, decimals: number): TokenAmount;
172
+ get human(): number;
173
+ toBigInt(): bigint;
174
+ }
175
+ /** A live ERC-20 bound to a client. Metadata is fetched lazily and cached. */
176
+ export declare class Token {
177
+ readonly client: SallyClient;
178
+ readonly address: string;
179
+ readonly contract: Contract;
180
+ private _decimals;
181
+ private _symbol;
182
+ constructor(client: SallyClient, address: string);
183
+ decimals(): Promise<number>;
184
+ symbol(): Promise<string>;
185
+ balanceOf(owner: string): Promise<bigint>;
186
+ allowance(owner: string, spender: string): Promise<bigint>;
187
+ toRaw(human: string | number | bigint): Promise<bigint>;
188
+ toHuman(raw: bigint): Promise<number>;
189
+ /** Approve `spender` (defaults to unlimited). Returns a receipt. */
190
+ approve(spender: string, amount?: bigint, tx?: Record<string, any>): Promise<any>;
191
+ /** Unsigned ERC-20 approve tx (for sign-externally mode). */
192
+ buildApprove(spender: string, amount?: bigint): Promise<Record<string, any>>;
193
+ /**
194
+ * Approve only if the current allowance is insufficient (idempotent).
195
+ *
196
+ * Approves exactly `amount` (pass `MAX_UINT256` for unlimited) — never silently
197
+ * escalates to infinite.
198
+ */
199
+ ensureAllowance(spender: string, amount: bigint, tx?: Record<string, any>): Promise<any>;
200
+ /** True if the token exposes EIP-2612 `nonces` + `DOMAIN_SEPARATOR`. */
201
+ supportsPermit(): Promise<boolean>;
202
+ private _permitVersion;
203
+ /**
204
+ * Set an allowance via an EIP-2612 signature (one `permit` tx, no approve).
205
+ *
206
+ * `value` is required (pass `MAX_UINT256` explicitly for unlimited) so an
207
+ * infinite allowance is never granted by accident. Requires the client's signer
208
+ * to own the tokens. Returns the receipt.
209
+ */
210
+ permit(spender: string, value: bigint, opts?: {
211
+ deadline?: number;
212
+ tx?: Record<string, any>;
213
+ }): Promise<any>;
214
+ }
215
+ //# sourceMappingURL=token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../src/token.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAc,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,eAAO,MAAM,MAAM,+CAA+C,CAAC;AACnE,eAAO,MAAM,IAAI,+CAA+C,CAAC;AACjE,eAAO,MAAM,WAAW,QAAkB,CAAC;AAG3C,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoBZ,CAAC;AAEX,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAkBrF;AAyBD,oDAAoD;AACpD,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED;;;;GAIG;AACH,qBAAa,WAAW;aACM,GAAG,EAAE,MAAM;aAAkB,QAAQ,EAAE,MAAM;gBAA7C,GAAG,EAAE,MAAM,EAAkB,QAAQ,EAAE,MAAM;IAEzE,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,G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M,GAAG,OAAO,CAAC,GAAG,CAAC;IASlG,wEAAwE;IAClE,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;YAU1B,cAAc;IAQ5B;;;;;;OAMG;IACG,MAAM,CACV,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,IAAI,GAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAO,GACzD,OAAO,CAAC,GAAG,CAAC;CA4BhB"}
package/dist/token.js ADDED
@@ -0,0 +1,239 @@
1
+ /**
2
+ * ERC-20 helpers: metadata, balances, approvals and human <-> raw amounts.
3
+ *
4
+ * Anything with non-18 decimals (USDC = 6, WBTC = 8) needs explicit scaling.
5
+ * {@link TokenAmount} carries the decimals with the value so you never multiply
6
+ * by the wrong power.
7
+ */
8
+ import { Contract, getAddress } from "ethers";
9
+ // The native gas token sentinel used across DeFi for ETH/BNB.
10
+ export const NATIVE = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
11
+ export const ZERO = "0x0000000000000000000000000000000000000000";
12
+ export const MAX_UINT256 = 2n ** 256n - 1n;
13
+ // Minimal ERC-20 ABI — enough for reads + approve.
14
+ export const ERC20_ABI = [
15
+ { name: "name", type: "function", stateMutability: "view", inputs: [], outputs: [{ type: "string" }] },
16
+ { name: "symbol", type: "function", stateMutability: "view", inputs: [], outputs: [{ type: "string" }] },
17
+ { name: "decimals", type: "function", stateMutability: "view", inputs: [], outputs: [{ type: "uint8" }] },
18
+ { name: "totalSupply", type: "function", stateMutability: "view", inputs: [], outputs: [{ type: "uint256" }] },
19
+ { name: "balanceOf", type: "function", stateMutability: "view", inputs: [{ name: "a", type: "address" }], outputs: [{ type: "uint256" }] },
20
+ { name: "allowance", type: "function", stateMutability: "view", inputs: [{ name: "o", type: "address" }, { name: "s", type: "address" }], outputs: [{ type: "uint256" }] },
21
+ { name: "approve", type: "function", stateMutability: "nonpayable", inputs: [{ name: "s", type: "address" }, { name: "v", type: "uint256" }], outputs: [{ type: "bool" }] },
22
+ { name: "transfer", type: "function", stateMutability: "nonpayable", inputs: [{ name: "t", type: "address" }, { name: "v", type: "uint256" }], outputs: [{ type: "bool" }] },
23
+ // EIP-2612
24
+ { name: "nonces", type: "function", stateMutability: "view", inputs: [{ name: "o", type: "address" }], outputs: [{ type: "uint256" }] },
25
+ { name: "DOMAIN_SEPARATOR", type: "function", stateMutability: "view", inputs: [], outputs: [{ type: "bytes32" }] },
26
+ { name: "version", type: "function", stateMutability: "view", inputs: [], outputs: [{ type: "string" }] },
27
+ {
28
+ name: "permit", type: "function", stateMutability: "nonpayable", inputs: [
29
+ { name: "owner", type: "address" }, { name: "spender", type: "address" },
30
+ { name: "value", type: "uint256" }, { name: "deadline", type: "uint256" },
31
+ { name: "v", type: "uint8" }, { name: "r", type: "bytes32" }, { name: "s", type: "bytes32" },
32
+ ], outputs: [],
33
+ },
34
+ ];
35
+ export function isNative(address) {
36
+ return address.toLowerCase() === NATIVE.toLowerCase() || address.toLowerCase() === ZERO.toLowerCase();
37
+ }
38
+ /**
39
+ * Convert a human amount to raw base units. Sub-unit precision is truncated
40
+ * toward zero (e.g. `0.0000001` of a 6-decimal token -> `0` raw), matching
41
+ * Python's `int()` semantics.
42
+ */
43
+ export function humanToRaw(amount, decimals) {
44
+ if (typeof amount === "bigint")
45
+ return amount * 10n ** BigInt(decimals);
46
+ let s = typeof amount === "number" ? numberToPlainString(amount) : String(amount).trim();
47
+ let neg = false;
48
+ if (s.startsWith("-")) {
49
+ neg = true;
50
+ s = s.slice(1);
51
+ }
52
+ else if (s.startsWith("+")) {
53
+ s = s.slice(1);
54
+ }
55
+ let [intPart, fracPart = ""] = s.split(".");
56
+ if (intPart === "")
57
+ intPart = "0";
58
+ // Truncate toward zero: keep at most `decimals` fractional digits.
59
+ fracPart = fracPart.slice(0, decimals).padEnd(decimals, "0");
60
+ const combined = `${intPart}${fracPart}`.replace(/^0+(?=\d)/, "");
61
+ let result = BigInt(combined || "0");
62
+ if (neg)
63
+ result = -result;
64
+ return result;
65
+ }
66
+ /** Render `number` without scientific notation so BigInt parsing is exact. */
67
+ function numberToPlainString(n) {
68
+ if (Number.isInteger(n))
69
+ return n.toFixed(0);
70
+ const s = String(n);
71
+ if (!/e/i.test(s))
72
+ return s;
73
+ // Expand exponent notation (e.g. 1e-7) into plain decimal.
74
+ const [mantissa, expRaw] = s.split(/e/i);
75
+ const exp = Number(expRaw);
76
+ const sign = mantissa.startsWith("-") ? "-" : "";
77
+ const digits = mantissa.replace("-", "").replace(".", "");
78
+ const pointIdx = (mantissa.replace("-", "").indexOf(".") === -1)
79
+ ? mantissa.replace("-", "").length
80
+ : mantissa.replace("-", "").indexOf(".");
81
+ let newPoint = pointIdx + exp;
82
+ if (newPoint <= 0) {
83
+ return `${sign}0.${"0".repeat(-newPoint)}${digits}`;
84
+ }
85
+ if (newPoint >= digits.length) {
86
+ return `${sign}${digits}${"0".repeat(newPoint - digits.length)}`;
87
+ }
88
+ return `${sign}${digits.slice(0, newPoint)}.${digits.slice(newPoint)}`;
89
+ }
90
+ /** Convert raw base units back to a human float. */
91
+ export function rawToHuman(raw, decimals) {
92
+ return Number(raw) / 10 ** decimals;
93
+ }
94
+ /**
95
+ * A token amount that knows its own decimals.
96
+ *
97
+ * `TokenAmount.fromHuman("1.5", 6).raw` -> 1500000n (1.5 USDC)
98
+ */
99
+ export class TokenAmount {
100
+ raw;
101
+ decimals;
102
+ constructor(raw, decimals) {
103
+ this.raw = raw;
104
+ this.decimals = decimals;
105
+ }
106
+ static fromHuman(amount, decimals) {
107
+ return new TokenAmount(humanToRaw(amount, decimals), decimals);
108
+ }
109
+ get human() {
110
+ return rawToHuman(this.raw, this.decimals);
111
+ }
112
+ toBigInt() {
113
+ return this.raw;
114
+ }
115
+ }
116
+ /** A live ERC-20 bound to a client. Metadata is fetched lazily and cached. */
117
+ export class Token {
118
+ client;
119
+ address;
120
+ contract;
121
+ _decimals = null;
122
+ _symbol = null;
123
+ constructor(client, address) {
124
+ this.client = client;
125
+ this.address = getAddress(address);
126
+ this.contract = new Contract(this.address, ERC20_ABI, client.w3);
127
+ }
128
+ // -- metadata --------------------------------------------------------- //
129
+ async decimals() {
130
+ if (this._decimals === null) {
131
+ this._decimals = Number(await this.contract.decimals());
132
+ }
133
+ return this._decimals;
134
+ }
135
+ async symbol() {
136
+ if (this._symbol === null) {
137
+ try {
138
+ this._symbol = await this.contract.symbol();
139
+ }
140
+ catch {
141
+ this._symbol = "?";
142
+ }
143
+ }
144
+ return this._symbol;
145
+ }
146
+ // -- reads ------------------------------------------------------------ //
147
+ async balanceOf(owner) {
148
+ return BigInt(await this.contract.balanceOf(getAddress(owner)));
149
+ }
150
+ async allowance(owner, spender) {
151
+ return BigInt(await this.contract.allowance(getAddress(owner), getAddress(spender)));
152
+ }
153
+ async toRaw(human) {
154
+ return TokenAmount.fromHuman(human, await this.decimals()).raw;
155
+ }
156
+ async toHuman(raw) {
157
+ return rawToHuman(raw, await this.decimals());
158
+ }
159
+ // -- writes ----------------------------------------------------------- //
160
+ /** Approve `spender` (defaults to unlimited). Returns a receipt. */
161
+ async approve(spender, amount = MAX_UINT256, tx = {}) {
162
+ const fn = this.contract.getFunction("approve");
163
+ return this.client.send(fn, [getAddress(spender), amount], tx);
164
+ }
165
+ /** Unsigned ERC-20 approve tx (for sign-externally mode). */
166
+ async buildApprove(spender, amount = MAX_UINT256) {
167
+ const fn = this.contract.getFunction("approve");
168
+ return this.client.send(fn, [getAddress(spender), amount], { simulate: false, buildOnly: true });
169
+ }
170
+ /**
171
+ * Approve only if the current allowance is insufficient (idempotent).
172
+ *
173
+ * Approves exactly `amount` (pass `MAX_UINT256` for unlimited) — never silently
174
+ * escalates to infinite.
175
+ */
176
+ async ensureAllowance(spender, amount, tx = {}) {
177
+ const owner = this.client.requireAddress();
178
+ if ((await this.allowance(owner, spender)) >= amount) {
179
+ return null;
180
+ }
181
+ return this.approve(spender, amount, tx);
182
+ }
183
+ // -- EIP-2612 permit -------------------------------------------------- //
184
+ /** True if the token exposes EIP-2612 `nonces` + `DOMAIN_SEPARATOR`. */
185
+ async supportsPermit() {
186
+ try {
187
+ await this.contract.nonces(ZERO);
188
+ await this.contract.DOMAIN_SEPARATOR();
189
+ return true;
190
+ }
191
+ catch {
192
+ return false;
193
+ }
194
+ }
195
+ async _permitVersion() {
196
+ try {
197
+ return String(await this.contract.version());
198
+ }
199
+ catch {
200
+ return "1";
201
+ }
202
+ }
203
+ /**
204
+ * Set an allowance via an EIP-2612 signature (one `permit` tx, no approve).
205
+ *
206
+ * `value` is required (pass `MAX_UINT256` explicitly for unlimited) so an
207
+ * infinite allowance is never granted by accident. Requires the client's signer
208
+ * to own the tokens. Returns the receipt.
209
+ */
210
+ async permit(spender, value, opts = {}) {
211
+ const { signPermit2612 } = await import("./permit2.js");
212
+ const owner = this.client.requireAddress();
213
+ const account = this.client.account;
214
+ if (account === null)
215
+ throw new Error("permit requires a signer");
216
+ spender = getAddress(spender);
217
+ let deadline = opts.deadline;
218
+ if (deadline === undefined) {
219
+ const block = await this.client.w3.getBlock("latest");
220
+ deadline = Number(block.timestamp) + 1200;
221
+ }
222
+ const nonce = Number(await this.contract.nonces(owner));
223
+ const name = await this.contract.name();
224
+ const [v, r, s] = await signPermit2612(account, {
225
+ token: this.address,
226
+ tokenName: name,
227
+ version: await this._permitVersion(),
228
+ chainId: this.client.chainId,
229
+ owner,
230
+ spender,
231
+ value,
232
+ nonce,
233
+ deadline,
234
+ });
235
+ const fn = this.contract.getFunction("permit");
236
+ return this.client.send(fn, [owner, spender, value, deadline, v, r, s], opts.tx ?? {});
237
+ }
238
+ }
239
+ //# sourceMappingURL=token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.js","sourceRoot":"","sources":["../src/token.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,QAAQ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