@upcoming/multichain-library 0.3.0 → 0.5.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.
@@ -0,0 +1 @@
1
+ export declare function selectGasPrice(attempt: number): bigint;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.selectGasPrice = selectGasPrice;
4
+ const cafe_utility_1 = require("cafe-utility");
5
+ function selectGasPrice(attempt) {
6
+ const gasPrices = ['0.1 gwei', '1 gwei', '2 gwei', '5 gwei', '10 gwei'];
7
+ if (attempt < 0 || attempt >= gasPrices.length - 1) {
8
+ throw Error('Attempt number out of range for gas price selection.');
9
+ }
10
+ return BigInt(cafe_utility_1.Numbers.make(gasPrices[attempt]));
11
+ }
@@ -0,0 +1,41 @@
1
+ export declare const GnosisBzzABI: ({
2
+ constant: boolean;
3
+ inputs: {
4
+ name: string;
5
+ type: string;
6
+ }[];
7
+ name: string;
8
+ outputs: {
9
+ name: string;
10
+ type: string;
11
+ }[];
12
+ payable: boolean;
13
+ stateMutability: string;
14
+ type: string;
15
+ anonymous?: undefined;
16
+ } | {
17
+ inputs: {
18
+ name: string;
19
+ type: string;
20
+ }[];
21
+ payable: boolean;
22
+ stateMutability: string;
23
+ type: string;
24
+ constant?: undefined;
25
+ name?: undefined;
26
+ outputs?: undefined;
27
+ anonymous?: undefined;
28
+ } | {
29
+ anonymous: boolean;
30
+ inputs: {
31
+ indexed: boolean;
32
+ name: string;
33
+ type: string;
34
+ }[];
35
+ name: string;
36
+ type: string;
37
+ constant?: undefined;
38
+ outputs?: undefined;
39
+ payable?: undefined;
40
+ stateMutability?: undefined;
41
+ })[];
@@ -0,0 +1,424 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GnosisBzzABI = void 0;
4
+ exports.GnosisBzzABI = [
5
+ {
6
+ constant: true,
7
+ inputs: [],
8
+ name: 'name',
9
+ outputs: [
10
+ {
11
+ name: '',
12
+ type: 'string'
13
+ }
14
+ ],
15
+ payable: false,
16
+ stateMutability: 'view',
17
+ type: 'function'
18
+ },
19
+ {
20
+ constant: false,
21
+ inputs: [
22
+ {
23
+ name: 'spender',
24
+ type: 'address'
25
+ },
26
+ {
27
+ name: 'amount',
28
+ type: 'uint256'
29
+ }
30
+ ],
31
+ name: 'approve',
32
+ outputs: [
33
+ {
34
+ name: '',
35
+ type: 'bool'
36
+ }
37
+ ],
38
+ payable: false,
39
+ stateMutability: 'nonpayable',
40
+ type: 'function'
41
+ },
42
+ {
43
+ constant: true,
44
+ inputs: [],
45
+ name: 'totalSupply',
46
+ outputs: [
47
+ {
48
+ name: '',
49
+ type: 'uint256'
50
+ }
51
+ ],
52
+ payable: false,
53
+ stateMutability: 'view',
54
+ type: 'function'
55
+ },
56
+ {
57
+ constant: false,
58
+ inputs: [
59
+ {
60
+ name: 'sender',
61
+ type: 'address'
62
+ },
63
+ {
64
+ name: 'recipient',
65
+ type: 'address'
66
+ },
67
+ {
68
+ name: 'amount',
69
+ type: 'uint256'
70
+ }
71
+ ],
72
+ name: 'transferFrom',
73
+ outputs: [
74
+ {
75
+ name: '',
76
+ type: 'bool'
77
+ }
78
+ ],
79
+ payable: false,
80
+ stateMutability: 'nonpayable',
81
+ type: 'function'
82
+ },
83
+ {
84
+ constant: true,
85
+ inputs: [],
86
+ name: 'decimals',
87
+ outputs: [
88
+ {
89
+ name: '',
90
+ type: 'uint8'
91
+ }
92
+ ],
93
+ payable: false,
94
+ stateMutability: 'view',
95
+ type: 'function'
96
+ },
97
+ {
98
+ constant: true,
99
+ inputs: [],
100
+ name: 'cap',
101
+ outputs: [
102
+ {
103
+ name: '',
104
+ type: 'uint256'
105
+ }
106
+ ],
107
+ payable: false,
108
+ stateMutability: 'view',
109
+ type: 'function'
110
+ },
111
+ {
112
+ constant: false,
113
+ inputs: [
114
+ {
115
+ name: 'spender',
116
+ type: 'address'
117
+ },
118
+ {
119
+ name: 'addedValue',
120
+ type: 'uint256'
121
+ }
122
+ ],
123
+ name: 'increaseAllowance',
124
+ outputs: [
125
+ {
126
+ name: '',
127
+ type: 'bool'
128
+ }
129
+ ],
130
+ payable: false,
131
+ stateMutability: 'nonpayable',
132
+ type: 'function'
133
+ },
134
+ {
135
+ constant: false,
136
+ inputs: [
137
+ {
138
+ name: 'account',
139
+ type: 'address'
140
+ },
141
+ {
142
+ name: 'amount',
143
+ type: 'uint256'
144
+ }
145
+ ],
146
+ name: 'mint',
147
+ outputs: [
148
+ {
149
+ name: '',
150
+ type: 'bool'
151
+ }
152
+ ],
153
+ payable: false,
154
+ stateMutability: 'nonpayable',
155
+ type: 'function'
156
+ },
157
+ {
158
+ constant: false,
159
+ inputs: [
160
+ {
161
+ name: 'amount',
162
+ type: 'uint256'
163
+ }
164
+ ],
165
+ name: 'burn',
166
+ outputs: [],
167
+ payable: false,
168
+ stateMutability: 'nonpayable',
169
+ type: 'function'
170
+ },
171
+ {
172
+ constant: true,
173
+ inputs: [
174
+ {
175
+ name: 'account',
176
+ type: 'address'
177
+ }
178
+ ],
179
+ name: 'balanceOf',
180
+ outputs: [
181
+ {
182
+ name: '',
183
+ type: 'uint256'
184
+ }
185
+ ],
186
+ payable: false,
187
+ stateMutability: 'view',
188
+ type: 'function'
189
+ },
190
+ {
191
+ constant: false,
192
+ inputs: [
193
+ {
194
+ name: 'account',
195
+ type: 'address'
196
+ },
197
+ {
198
+ name: 'amount',
199
+ type: 'uint256'
200
+ }
201
+ ],
202
+ name: 'burnFrom',
203
+ outputs: [],
204
+ payable: false,
205
+ stateMutability: 'nonpayable',
206
+ type: 'function'
207
+ },
208
+ {
209
+ constant: true,
210
+ inputs: [],
211
+ name: 'symbol',
212
+ outputs: [
213
+ {
214
+ name: '',
215
+ type: 'string'
216
+ }
217
+ ],
218
+ payable: false,
219
+ stateMutability: 'view',
220
+ type: 'function'
221
+ },
222
+ {
223
+ constant: false,
224
+ inputs: [
225
+ {
226
+ name: 'account',
227
+ type: 'address'
228
+ }
229
+ ],
230
+ name: 'addMinter',
231
+ outputs: [],
232
+ payable: false,
233
+ stateMutability: 'nonpayable',
234
+ type: 'function'
235
+ },
236
+ {
237
+ constant: false,
238
+ inputs: [],
239
+ name: 'renounceMinter',
240
+ outputs: [],
241
+ payable: false,
242
+ stateMutability: 'nonpayable',
243
+ type: 'function'
244
+ },
245
+ {
246
+ constant: false,
247
+ inputs: [
248
+ {
249
+ name: 'spender',
250
+ type: 'address'
251
+ },
252
+ {
253
+ name: 'subtractedValue',
254
+ type: 'uint256'
255
+ }
256
+ ],
257
+ name: 'decreaseAllowance',
258
+ outputs: [
259
+ {
260
+ name: '',
261
+ type: 'bool'
262
+ }
263
+ ],
264
+ payable: false,
265
+ stateMutability: 'nonpayable',
266
+ type: 'function'
267
+ },
268
+ {
269
+ constant: false,
270
+ inputs: [
271
+ {
272
+ name: 'recipient',
273
+ type: 'address'
274
+ },
275
+ {
276
+ name: 'amount',
277
+ type: 'uint256'
278
+ }
279
+ ],
280
+ name: 'transfer',
281
+ outputs: [
282
+ {
283
+ name: '',
284
+ type: 'bool'
285
+ }
286
+ ],
287
+ payable: false,
288
+ stateMutability: 'nonpayable',
289
+ type: 'function'
290
+ },
291
+ {
292
+ constant: true,
293
+ inputs: [
294
+ {
295
+ name: 'account',
296
+ type: 'address'
297
+ }
298
+ ],
299
+ name: 'isMinter',
300
+ outputs: [
301
+ {
302
+ name: '',
303
+ type: 'bool'
304
+ }
305
+ ],
306
+ payable: false,
307
+ stateMutability: 'view',
308
+ type: 'function'
309
+ },
310
+ {
311
+ constant: true,
312
+ inputs: [
313
+ {
314
+ name: 'owner',
315
+ type: 'address'
316
+ },
317
+ {
318
+ name: 'spender',
319
+ type: 'address'
320
+ }
321
+ ],
322
+ name: 'allowance',
323
+ outputs: [
324
+ {
325
+ name: '',
326
+ type: 'uint256'
327
+ }
328
+ ],
329
+ payable: false,
330
+ stateMutability: 'view',
331
+ type: 'function'
332
+ },
333
+ {
334
+ inputs: [
335
+ {
336
+ name: '_name',
337
+ type: 'string'
338
+ },
339
+ {
340
+ name: '_symbol',
341
+ type: 'string'
342
+ },
343
+ {
344
+ name: '_decimals',
345
+ type: 'uint8'
346
+ },
347
+ {
348
+ name: '_cap',
349
+ type: 'uint256'
350
+ }
351
+ ],
352
+ payable: false,
353
+ stateMutability: 'nonpayable',
354
+ type: 'constructor'
355
+ },
356
+ {
357
+ anonymous: false,
358
+ inputs: [
359
+ {
360
+ indexed: true,
361
+ name: 'account',
362
+ type: 'address'
363
+ }
364
+ ],
365
+ name: 'MinterAdded',
366
+ type: 'event'
367
+ },
368
+ {
369
+ anonymous: false,
370
+ inputs: [
371
+ {
372
+ indexed: true,
373
+ name: 'account',
374
+ type: 'address'
375
+ }
376
+ ],
377
+ name: 'MinterRemoved',
378
+ type: 'event'
379
+ },
380
+ {
381
+ anonymous: false,
382
+ inputs: [
383
+ {
384
+ indexed: true,
385
+ name: 'from',
386
+ type: 'address'
387
+ },
388
+ {
389
+ indexed: true,
390
+ name: 'to',
391
+ type: 'address'
392
+ },
393
+ {
394
+ indexed: false,
395
+ name: 'value',
396
+ type: 'uint256'
397
+ }
398
+ ],
399
+ name: 'Transfer',
400
+ type: 'event'
401
+ },
402
+ {
403
+ anonymous: false,
404
+ inputs: [
405
+ {
406
+ indexed: true,
407
+ name: 'owner',
408
+ type: 'address'
409
+ },
410
+ {
411
+ indexed: true,
412
+ name: 'spender',
413
+ type: 'address'
414
+ },
415
+ {
416
+ indexed: false,
417
+ name: 'value',
418
+ type: 'uint256'
419
+ }
420
+ ],
421
+ name: 'Approval',
422
+ type: 'event'
423
+ }
424
+ ];
@@ -0,0 +1,9 @@
1
+ import { RollingValueProvider } from 'cafe-utility';
2
+ import { MultichainLibrarySettings } from './Settings';
3
+ export interface TransferGnosisBzzOptions {
4
+ amount: string | bigint;
5
+ originPrivateKey: `0x${string}`;
6
+ originAddress: `0x${string}`;
7
+ to: `0x${string}`;
8
+ }
9
+ export declare function transferGnosisBzz(options: TransferGnosisBzzOptions, settings: MultichainLibrarySettings, jsonRpcProvider: RollingValueProvider<string>): Promise<`0x${string}`>;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transferGnosisBzz = transferGnosisBzz;
4
+ const cafe_utility_1 = require("cafe-utility");
5
+ const viem_1 = require("viem");
6
+ const accounts_1 = require("viem/accounts");
7
+ const chains_1 = require("viem/chains");
8
+ const Constants_1 = require("./Constants");
9
+ const GasPriceSelector_1 = require("./GasPriceSelector");
10
+ const GnosisBzzAbi_1 = require("./GnosisBzzAbi");
11
+ const GnosisTransactionCount_1 = require("./GnosisTransactionCount");
12
+ async function transferGnosisBzz(options, settings, jsonRpcProvider) {
13
+ const account = (0, accounts_1.privateKeyToAccount)(options.originPrivateKey);
14
+ const client = (0, viem_1.createWalletClient)({
15
+ chain: chains_1.gnosis,
16
+ transport: (0, viem_1.http)(jsonRpcProvider.current())
17
+ });
18
+ for (let i = 0; i < 4; i++) {
19
+ try {
20
+ const hash = await client.writeContract({
21
+ account,
22
+ abi: GnosisBzzAbi_1.GnosisBzzABI,
23
+ address: Constants_1.Constants.bzzGnosisAddress,
24
+ functionName: 'transfer',
25
+ args: [options.to, BigInt(options.amount)],
26
+ gas: 100000n,
27
+ gasPrice: (0, GasPriceSelector_1.selectGasPrice)(i),
28
+ type: 'legacy',
29
+ chain: chains_1.gnosis,
30
+ nonce: await (0, GnosisTransactionCount_1.getGnosisTransactionCount)(options.originAddress, settings, jsonRpcProvider)
31
+ });
32
+ return hash;
33
+ }
34
+ catch (error) {
35
+ if (cafe_utility_1.Objects.errorMatches(error, 'FeeTooLow')) {
36
+ await cafe_utility_1.System.sleepMillis(cafe_utility_1.Dates.seconds(2));
37
+ }
38
+ else {
39
+ throw error;
40
+ }
41
+ }
42
+ }
43
+ throw Error('Failed to write contract after multiple attempts due to low fees.');
44
+ }
@@ -5,5 +5,6 @@ export interface TransferGnosisNativeOptions {
5
5
  originPrivateKey: `0x${string}`;
6
6
  originAddress: `0x${string}`;
7
7
  to: `0x${string}`;
8
+ nonce?: number;
8
9
  }
9
10
  export declare function transferGnosisNative(options: TransferGnosisNativeOptions, settings: MultichainLibrarySettings, jsonRpcProvider: RollingValueProvider<string>): Promise<`0x${string}`>;
@@ -6,6 +6,7 @@ const viem_1 = require("viem");
6
6
  const accounts_1 = require("viem/accounts");
7
7
  const chains_1 = require("viem/chains");
8
8
  const Constants_1 = require("./Constants");
9
+ const GasPriceSelector_1 = require("./GasPriceSelector");
9
10
  const GnosisTransactionCount_1 = require("./GnosisTransactionCount");
10
11
  async function transferGnosisNative(options, settings, jsonRpcProvider) {
11
12
  const account = (0, accounts_1.privateKeyToAccount)(options.originPrivateKey);
@@ -13,18 +14,18 @@ async function transferGnosisNative(options, settings, jsonRpcProvider) {
13
14
  chain: chains_1.gnosis,
14
15
  transport: (0, viem_1.http)(jsonRpcProvider.current())
15
16
  });
16
- for (let i = 1; i <= 5; i++) {
17
+ for (let i = 0; i < 4; i++) {
17
18
  try {
18
19
  const serializedTransaction = await account.signTransaction({
19
20
  chain: Constants_1.Constants.gnosisChainId,
20
21
  chainId: Constants_1.Constants.gnosisChainId,
21
22
  account: options.originAddress,
22
- gas: BigInt(21000),
23
- gasPrice: BigInt(cafe_utility_1.Numbers.make(`${i} gwei`)),
23
+ gas: 21000n,
24
+ gasPrice: (0, GasPriceSelector_1.selectGasPrice)(i),
24
25
  type: 'legacy',
25
26
  to: options.to,
26
27
  value: BigInt(options.amount),
27
- nonce: await (0, GnosisTransactionCount_1.getGnosisTransactionCount)(options.originAddress, settings, jsonRpcProvider)
28
+ nonce: options.nonce ?? (await (0, GnosisTransactionCount_1.getGnosisTransactionCount)(options.originAddress, settings, jsonRpcProvider))
28
29
  });
29
30
  const hash = await client.sendRawTransaction({ serializedTransaction });
30
31
  return hash;
@@ -0,0 +1,22 @@
1
+ import { RollingValueProvider } from 'cafe-utility';
2
+ import { MultichainLibrarySettings } from './Settings';
3
+ export interface MultiTransferGnosisNativeOptions {
4
+ amount: string | bigint;
5
+ originPrivateKey: `0x${string}`;
6
+ originAddress: `0x${string}`;
7
+ to: `0x${string}`[];
8
+ nonce?: number;
9
+ }
10
+ export interface AddressfulTransaction {
11
+ address: `0x${string}`;
12
+ transaction: `0x${string}`;
13
+ }
14
+ export interface AddressfulError {
15
+ address: `0x${string}`;
16
+ error: Error;
17
+ }
18
+ export interface MultiTransferGnosisNativeResult {
19
+ transactions: AddressfulTransaction[];
20
+ errors: AddressfulError[];
21
+ }
22
+ export declare function multiTransferGnosisNative(options: MultiTransferGnosisNativeOptions, settings: MultichainLibrarySettings, jsonRpcProvider: RollingValueProvider<string>): Promise<MultiTransferGnosisNativeResult>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.multiTransferGnosisNative = multiTransferGnosisNative;
4
+ const GnosisNativeTransfer_1 = require("./GnosisNativeTransfer");
5
+ const GnosisTransactionCount_1 = require("./GnosisTransactionCount");
6
+ async function multiTransferGnosisNative(options, settings, jsonRpcProvider) {
7
+ const transactions = [];
8
+ const errors = [];
9
+ let nonce = options.nonce ?? (await (0, GnosisTransactionCount_1.getGnosisTransactionCount)(options.originAddress, settings, jsonRpcProvider));
10
+ for (const address of options.to) {
11
+ try {
12
+ const transaction = await (0, GnosisNativeTransfer_1.transferGnosisNative)({
13
+ amount: options.amount,
14
+ originPrivateKey: options.originPrivateKey,
15
+ originAddress: options.originAddress,
16
+ to: address,
17
+ nonce: nonce++
18
+ }, settings, jsonRpcProvider);
19
+ transactions.push({ address, transaction });
20
+ }
21
+ catch (error) {
22
+ errors.push({ address, error: error });
23
+ }
24
+ }
25
+ return { transactions, errors };
26
+ }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { FixedPointNumber, RollingValueProvider } from 'cafe-utility';
2
2
  import { Constants } from './Constants';
3
+ import { TransferGnosisBzzOptions } from './GnosisBzzTransfer';
3
4
  import { TransferGnosisNativeOptions } from './GnosisNativeTransfer';
4
5
  import { GnosisSwapAutoOptions, GnosisSwapCustomOptions } from './GnosisSwap';
6
+ import { MultiTransferGnosisNativeOptions, MultiTransferGnosisNativeResult } from './MultiGnosisNativeTransfer';
5
7
  import { MultichainLibrarySettings } from './Settings';
6
8
  import { SushiResponse } from './SushiSwap';
7
9
  export { MultichainLibrarySettings } from './Settings';
@@ -16,6 +18,8 @@ export declare class MultichainLibrary {
16
18
  getTokenPrice(tokenAddress: `0x${string}`, chainId: number): Promise<number>;
17
19
  getGnosisBzzTokenPrice(): Promise<number>;
18
20
  transferGnosisNative(options: TransferGnosisNativeOptions): Promise<`0x${string}`>;
21
+ multiTransferGnosisNative(options: MultiTransferGnosisNativeOptions): Promise<MultiTransferGnosisNativeResult>;
22
+ transferGnosisBzz(options: TransferGnosisBzzOptions): Promise<`0x${string}`>;
19
23
  waitForGnosisBzzBalanceToIncrease(address: string, initialBalance: bigint): Promise<void>;
20
24
  waitForGnosisNativeBalanceToDecrease(address: `0x${string}`, initialBalance: bigint): Promise<void>;
21
25
  waitForGnosisNativeBalanceToIncrease(address: `0x${string}`, initialBalance: bigint): Promise<void>;
package/dist/index.js CHANGED
@@ -4,10 +4,12 @@ exports.MultichainLibrary = void 0;
4
4
  const cafe_utility_1 = require("cafe-utility");
5
5
  const Constants_1 = require("./Constants");
6
6
  const GnosisBzzBalance_1 = require("./GnosisBzzBalance");
7
+ const GnosisBzzTransfer_1 = require("./GnosisBzzTransfer");
7
8
  const GnosisNativeBalance_1 = require("./GnosisNativeBalance");
8
9
  const GnosisNativeTransfer_1 = require("./GnosisNativeTransfer");
9
10
  const GnosisSwap_1 = require("./GnosisSwap");
10
11
  const GnosisTransactionCount_1 = require("./GnosisTransactionCount");
12
+ const MultiGnosisNativeTransfer_1 = require("./MultiGnosisNativeTransfer");
11
13
  const Settings_1 = require("./Settings");
12
14
  const SushiSwap_1 = require("./SushiSwap");
13
15
  const TokenPrice_1 = require("./TokenPrice");
@@ -35,6 +37,12 @@ class MultichainLibrary {
35
37
  transferGnosisNative(options) {
36
38
  return (0, GnosisNativeTransfer_1.transferGnosisNative)(options, this.settings, this.jsonRpcProvider);
37
39
  }
40
+ multiTransferGnosisNative(options) {
41
+ return (0, MultiGnosisNativeTransfer_1.multiTransferGnosisNative)(options, this.settings, this.jsonRpcProvider);
42
+ }
43
+ transferGnosisBzz(options) {
44
+ return (0, GnosisBzzTransfer_1.transferGnosisBzz)(options, this.settings, this.jsonRpcProvider);
45
+ }
38
46
  waitForGnosisBzzBalanceToIncrease(address, initialBalance) {
39
47
  return (0, Waiter_1.waitForGnosisBzzBalanceToIncrease)(address, initialBalance, this.settings, this.jsonRpcProvider);
40
48
  }
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@upcoming/multichain-library",
3
3
  "private": false,
4
- "version": "0.3.0",
4
+ "version": "0.5.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
9
  "import": "./dist/index.js",
10
+ "require": "./dist/index.js",
10
11
  "types": "./dist/index.d.ts"
11
12
  }
12
13
  },
@@ -22,7 +23,6 @@
22
23
  "viem": "^2.38.2"
23
24
  },
24
25
  "devDependencies": {
25
- "@types/node": "^24.7.2",
26
26
  "typescript": "^5.9.3"
27
27
  }
28
28
  }
package/tsconfig.json CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  "compilerOptions": {
6
6
  "outDir": "dist",
7
- "lib": ["ES2022"],
7
+ "lib": ["ES2022", "DOM"],
8
8
  "module": "CommonJS",
9
9
  "target": "ES2022",
10
10
  "declaration": true,