@gearbox-protocol/sdk 9.9.7 → 9.10.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/dist/cjs/dev/AccountOpener.js +3 -100
- package/dist/cjs/dev/index.js +2 -0
- package/dist/cjs/dev/mint/AbstractMinter.js +81 -0
- package/dist/cjs/dev/mint/DealMinter.js +54 -0
- package/dist/cjs/dev/mint/DirectMinter.js +68 -0
- package/dist/cjs/dev/mint/FallbackMinter.js +57 -0
- package/dist/cjs/dev/mint/TransferMinter.js +84 -0
- package/dist/cjs/dev/mint/factory.js +38 -0
- package/dist/cjs/dev/mint/index.js +24 -0
- package/dist/cjs/dev/mint/types.js +16 -0
- package/dist/esm/dev/AccountOpener.js +4 -102
- package/dist/esm/dev/index.js +1 -0
- package/dist/esm/dev/mint/AbstractMinter.js +63 -0
- package/dist/esm/dev/mint/DealMinter.js +20 -0
- package/dist/esm/dev/mint/DirectMinter.js +34 -0
- package/dist/esm/dev/mint/FallbackMinter.js +23 -0
- package/dist/esm/dev/mint/TransferMinter.js +50 -0
- package/dist/esm/dev/mint/factory.js +14 -0
- package/dist/esm/dev/mint/index.js +2 -0
- package/dist/esm/dev/mint/types.js +0 -0
- package/dist/types/dev/index.d.ts +1 -0
- package/dist/types/dev/mint/AbstractMinter.d.ts +16 -0
- package/dist/types/dev/mint/DealMinter.d.ts +9 -0
- package/dist/types/dev/mint/DirectMinter.d.ts +9 -0
- package/dist/types/dev/mint/FallbackMinter.d.ts +10 -0
- package/dist/types/dev/mint/TransferMinter.d.ts +9 -0
- package/dist/types/dev/mint/factory.d.ts +5 -0
- package/dist/types/dev/mint/index.d.ts +2 -0
- package/dist/types/dev/mint/types.d.ts +20 -0
- package/package.json +7 -5
|
@@ -30,6 +30,7 @@ var import_sdk = require("../sdk/index.js");
|
|
|
30
30
|
var import_abi = require("./abi.js");
|
|
31
31
|
var import_claimFromFaucet = require("./claimFromFaucet.js");
|
|
32
32
|
var import_createAnvilClient = require("./createAnvilClient.js");
|
|
33
|
+
var import_mint = require("./mint/index.js");
|
|
33
34
|
const DIRECT_TRANSFERS_QUOTA = 10000n;
|
|
34
35
|
class OpenTxRevertedError extends import_viem.BaseError {
|
|
35
36
|
txHash;
|
|
@@ -501,106 +502,8 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
501
502
|
* @param amount
|
|
502
503
|
*/
|
|
503
504
|
async #tryMint(token, dest, amount) {
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
await this.#mint(token, dest, amount);
|
|
507
|
-
} catch (e) {
|
|
508
|
-
this.#logger?.warn(`failed to mint ${amnt} to ${dest.address}: ${e}`);
|
|
509
|
-
}
|
|
510
|
-
return await this.#anvil.readContract({
|
|
511
|
-
address: token,
|
|
512
|
-
abi: import_iERC20.ierc20Abi,
|
|
513
|
-
functionName: "balanceOf",
|
|
514
|
-
args: [dest.address]
|
|
515
|
-
});
|
|
516
|
-
}
|
|
517
|
-
async #mint(token, dest, amount) {
|
|
518
|
-
const symbol = this.sdk.tokensMeta.symbol(token);
|
|
519
|
-
const amnt = this.sdk.tokensMeta.formatBN(token, amount);
|
|
520
|
-
this.#logger?.warn(`minting ${amnt} ${symbol} to ${dest.address}`);
|
|
521
|
-
const owner = await this.#anvil.readContract({
|
|
522
|
-
address: token,
|
|
523
|
-
abi: import_abi.iOwnableAbi,
|
|
524
|
-
functionName: "owner"
|
|
525
|
-
});
|
|
526
|
-
this.#logger?.warn(`owner of ${symbol}: ${owner}`);
|
|
527
|
-
await this.#anvil.impersonateAccount({ address: owner });
|
|
528
|
-
await this.#anvil.setBalance({
|
|
529
|
-
address: owner,
|
|
530
|
-
value: (0, import_viem.parseEther)("1000000")
|
|
531
|
-
});
|
|
532
|
-
try {
|
|
533
|
-
await this.#mintDirectly(owner, token, amount, dest.address);
|
|
534
|
-
} catch (e) {
|
|
535
|
-
this.#logger?.warn(
|
|
536
|
-
`failed to mint directly ${amnt} ${symbol} to ${dest.address}: ${e}`
|
|
537
|
-
);
|
|
538
|
-
try {
|
|
539
|
-
await this.#mintAndTransfer(owner, token, amount, dest.address);
|
|
540
|
-
} catch (e2) {
|
|
541
|
-
this.#logger?.warn(
|
|
542
|
-
`failed to mint and transfer ${amnt} ${symbol} to ${dest.address}: ${e2}`
|
|
543
|
-
);
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
await this.#anvil.stopImpersonatingAccount({ address: owner });
|
|
547
|
-
}
|
|
548
|
-
async #mintDirectly(owner, token, amount, dest) {
|
|
549
|
-
const hash = await this.#anvil.writeContract({
|
|
550
|
-
account: owner,
|
|
551
|
-
address: token,
|
|
552
|
-
abi: (0, import_viem.parseAbi)([
|
|
553
|
-
"function mint(address to, uint256 amount) returns (bool)"
|
|
554
|
-
]),
|
|
555
|
-
functionName: "mint",
|
|
556
|
-
args: [dest, amount],
|
|
557
|
-
chain: this.#anvil.chain
|
|
558
|
-
});
|
|
559
|
-
this.#logger?.debug(
|
|
560
|
-
`mint ${this.sdk.tokensMeta.formatBN(token, amount, { symbol: true })} to ${owner} in tx ${hash}`
|
|
561
|
-
);
|
|
562
|
-
const receipt = await this.#anvil.waitForTransactionReceipt({ hash });
|
|
563
|
-
if (receipt.status === "reverted") {
|
|
564
|
-
throw new Error(
|
|
565
|
-
`failed to mint ${this.sdk.tokensMeta.formatBN(token, amount, { symbol: true })} to ${owner} in tx ${hash}: reverted`
|
|
566
|
-
);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
async #mintAndTransfer(owner, token, amount, dest) {
|
|
570
|
-
let hash = await this.#anvil.writeContract({
|
|
571
|
-
account: owner,
|
|
572
|
-
address: token,
|
|
573
|
-
abi: (0, import_viem.parseAbi)(["function mint(uint256 amount) external returns (bool)"]),
|
|
574
|
-
functionName: "mint",
|
|
575
|
-
args: [amount],
|
|
576
|
-
chain: this.#anvil.chain
|
|
577
|
-
});
|
|
578
|
-
this.#logger?.debug(
|
|
579
|
-
`mint ${this.sdk.tokensMeta.formatBN(token, amount, { symbol: true })} to ${owner} in tx ${hash}`
|
|
580
|
-
);
|
|
581
|
-
let receipt = await this.#anvil.waitForTransactionReceipt({ hash });
|
|
582
|
-
if (receipt.status === "reverted") {
|
|
583
|
-
throw new Error(
|
|
584
|
-
`failed to mint ${this.sdk.tokensMeta.formatBN(token, amount, { symbol: true })} to ${owner} in tx ${hash}: reverted`
|
|
585
|
-
);
|
|
586
|
-
}
|
|
587
|
-
hash = await this.#anvil.writeContract({
|
|
588
|
-
account: owner,
|
|
589
|
-
address: token,
|
|
590
|
-
abi: import_iERC20.ierc20Abi,
|
|
591
|
-
functionName: "transfer",
|
|
592
|
-
args: [dest, amount],
|
|
593
|
-
chain: this.#anvil.chain
|
|
594
|
-
});
|
|
595
|
-
this.#logger?.debug(
|
|
596
|
-
`transfer ${this.sdk.tokensMeta.formatBN(token, amount, { symbol: true })} from ${owner} to ${dest} in tx ${hash}`
|
|
597
|
-
);
|
|
598
|
-
receipt = await this.#anvil.waitForTransactionReceipt({ hash });
|
|
599
|
-
if (receipt.status === "reverted") {
|
|
600
|
-
throw new Error(
|
|
601
|
-
`failed to transfer ${this.sdk.tokensMeta.formatBN(token, amount, { symbol: true })} from ${owner} to ${dest} in tx ${hash}: reverted`
|
|
602
|
-
);
|
|
603
|
-
}
|
|
505
|
+
const minter = (0, import_mint.createMinter)(this.sdk, this.#anvil, token);
|
|
506
|
+
return minter.tryMint(token, dest.address, amount);
|
|
604
507
|
}
|
|
605
508
|
/**
|
|
606
509
|
* Creates borrower wallet,
|
package/dist/cjs/dev/index.js
CHANGED
|
@@ -25,6 +25,7 @@ __reExport(dev_exports, require("./detectChain.js"), module.exports);
|
|
|
25
25
|
__reExport(dev_exports, require("./EthCallSpy.js"), module.exports);
|
|
26
26
|
__reExport(dev_exports, require("./ltUtils.js"), module.exports);
|
|
27
27
|
__reExport(dev_exports, require("./migrateFaucet.js"), module.exports);
|
|
28
|
+
__reExport(dev_exports, require("./mint/index.js"), module.exports);
|
|
28
29
|
__reExport(dev_exports, require("./providers.js"), module.exports);
|
|
29
30
|
__reExport(dev_exports, require("./RevolverTransport.js"), module.exports);
|
|
30
31
|
__reExport(dev_exports, require("./types.js"), module.exports);
|
|
@@ -40,6 +41,7 @@ __reExport(dev_exports, require("./types.js"), module.exports);
|
|
|
40
41
|
...require("./EthCallSpy.js"),
|
|
41
42
|
...require("./ltUtils.js"),
|
|
42
43
|
...require("./migrateFaucet.js"),
|
|
44
|
+
...require("./mint/index.js"),
|
|
43
45
|
...require("./providers.js"),
|
|
44
46
|
...require("./RevolverTransport.js"),
|
|
45
47
|
...require("./types.js")
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var AbstractMinter_exports = {};
|
|
20
|
+
__export(AbstractMinter_exports, {
|
|
21
|
+
default: () => AbstractMinter
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(AbstractMinter_exports);
|
|
24
|
+
var import_viem = require("viem");
|
|
25
|
+
var import_iERC20 = require("../../abi/iERC20.js");
|
|
26
|
+
var import_sdk = require("../../sdk/index.js");
|
|
27
|
+
var import_abi = require("../abi.js");
|
|
28
|
+
class AbstractMinter extends import_sdk.SDKConstruct {
|
|
29
|
+
anvil;
|
|
30
|
+
logger;
|
|
31
|
+
name;
|
|
32
|
+
constructor(sdk, anvil, name = "Minter") {
|
|
33
|
+
super(sdk);
|
|
34
|
+
this.anvil = anvil;
|
|
35
|
+
this.name = name;
|
|
36
|
+
this.logger = sdk.logger?.child?.({ name }) ?? sdk.logger;
|
|
37
|
+
}
|
|
38
|
+
async tryMint(token, dest, amount) {
|
|
39
|
+
const amnt = this.fmt(token, amount);
|
|
40
|
+
const before = await this.balanceOf(token, dest);
|
|
41
|
+
try {
|
|
42
|
+
await this.mint(token, dest, amount);
|
|
43
|
+
} catch (e) {
|
|
44
|
+
this.logger?.warn(`failed to mint ${amnt} to ${dest}: ${e}`);
|
|
45
|
+
}
|
|
46
|
+
const after = await this.balanceOf(token, dest);
|
|
47
|
+
const minted = after - before;
|
|
48
|
+
this.logger?.debug(`minted ${this.fmt(token, minted)} to ${dest}`);
|
|
49
|
+
return after;
|
|
50
|
+
}
|
|
51
|
+
async getOwner(address) {
|
|
52
|
+
const owner = await this.anvil.readContract({
|
|
53
|
+
address,
|
|
54
|
+
abi: import_abi.iOwnableAbi,
|
|
55
|
+
functionName: "owner"
|
|
56
|
+
});
|
|
57
|
+
this.logger?.debug(`owner of ${this.sdk.labelAddress(address)}: ${owner}`);
|
|
58
|
+
return owner;
|
|
59
|
+
}
|
|
60
|
+
async impersonateWithBalance(address, balance = "1000") {
|
|
61
|
+
await this.anvil.impersonateAccount({ address });
|
|
62
|
+
await this.anvil.setBalance({
|
|
63
|
+
address,
|
|
64
|
+
value: (0, import_viem.parseEther)(balance)
|
|
65
|
+
});
|
|
66
|
+
return async () => {
|
|
67
|
+
await this.anvil.stopImpersonatingAccount({ address });
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
fmt(token, amount) {
|
|
71
|
+
return this.sdk.tokensMeta.formatBN(token, amount, { symbol: true });
|
|
72
|
+
}
|
|
73
|
+
balanceOf(token, dest) {
|
|
74
|
+
return this.anvil.readContract({
|
|
75
|
+
address: token,
|
|
76
|
+
abi: import_iERC20.ierc20Abi,
|
|
77
|
+
functionName: "balanceOf",
|
|
78
|
+
args: [dest]
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var DealMinter_exports = {};
|
|
30
|
+
__export(DealMinter_exports, {
|
|
31
|
+
DealMinter: () => DealMinter
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(DealMinter_exports);
|
|
34
|
+
var import_viem_deal = require("viem-deal");
|
|
35
|
+
var import_AbstractMinter = __toESM(require("./AbstractMinter.js"));
|
|
36
|
+
class DealMinter extends import_AbstractMinter.default {
|
|
37
|
+
constructor(sdk, anvil) {
|
|
38
|
+
super(sdk, anvil, "DealMinter");
|
|
39
|
+
}
|
|
40
|
+
async mint(token, dest, amount) {
|
|
41
|
+
let balance = await this.balanceOf(token, dest);
|
|
42
|
+
balance += amount;
|
|
43
|
+
this.logger?.debug(`set balance of ${dest} to ${this.fmt(token, balance)}`);
|
|
44
|
+
await (0, import_viem_deal.deal)(this.anvil, {
|
|
45
|
+
erc20: token,
|
|
46
|
+
account: dest,
|
|
47
|
+
amount: balance
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
DealMinter
|
|
54
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var DirectMinter_exports = {};
|
|
30
|
+
__export(DirectMinter_exports, {
|
|
31
|
+
DirectMinter: () => DirectMinter
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(DirectMinter_exports);
|
|
34
|
+
var import_viem = require("viem");
|
|
35
|
+
var import_AbstractMinter = __toESM(require("./AbstractMinter.js"));
|
|
36
|
+
class DirectMinter extends import_AbstractMinter.default {
|
|
37
|
+
constructor(sdk, anvil) {
|
|
38
|
+
super(sdk, anvil, "DirectMinter");
|
|
39
|
+
}
|
|
40
|
+
async mint(token, dest, amount) {
|
|
41
|
+
const owner = await this.getOwner(token);
|
|
42
|
+
const stopImpersonating = await this.impersonateWithBalance(owner);
|
|
43
|
+
const hash = await this.anvil.writeContract({
|
|
44
|
+
account: owner,
|
|
45
|
+
address: token,
|
|
46
|
+
abi: (0, import_viem.parseAbi)([
|
|
47
|
+
"function mint(address to, uint256 amount) returns (bool)"
|
|
48
|
+
]),
|
|
49
|
+
functionName: "mint",
|
|
50
|
+
args: [dest, amount],
|
|
51
|
+
chain: this.anvil.chain
|
|
52
|
+
});
|
|
53
|
+
this.logger?.debug(
|
|
54
|
+
`mint ${this.fmt(token, amount)} to ${owner} in tx ${hash}`
|
|
55
|
+
);
|
|
56
|
+
const receipt = await this.anvil.waitForTransactionReceipt({ hash });
|
|
57
|
+
if (receipt.status === "reverted") {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`failed to mint ${this.fmt(token, amount)} to ${owner} in tx ${hash}: reverted`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
await stopImpersonating();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
DirectMinter
|
|
68
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var FallbackMinter_exports = {};
|
|
30
|
+
__export(FallbackMinter_exports, {
|
|
31
|
+
FallbackMinter: () => FallbackMinter
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(FallbackMinter_exports);
|
|
34
|
+
var import_AbstractMinter = __toESM(require("./AbstractMinter.js"));
|
|
35
|
+
class FallbackMinter extends import_AbstractMinter.default {
|
|
36
|
+
#minters;
|
|
37
|
+
constructor(sdk, anvil, minters) {
|
|
38
|
+
super(sdk, anvil, "FallbackMinter");
|
|
39
|
+
this.#minters = minters;
|
|
40
|
+
}
|
|
41
|
+
async mint(token, dest, amount) {
|
|
42
|
+
for (const minter of this.#minters) {
|
|
43
|
+
try {
|
|
44
|
+
await minter.mint(token, dest, amount);
|
|
45
|
+
this.logger?.debug(`${minter.name} succeeded`);
|
|
46
|
+
return;
|
|
47
|
+
} catch (e) {
|
|
48
|
+
this.logger?.warn(`${minter.name} failed: ${e}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
throw new Error("all minters failed");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
FallbackMinter
|
|
57
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var TransferMinter_exports = {};
|
|
30
|
+
__export(TransferMinter_exports, {
|
|
31
|
+
TransferMinter: () => TransferMinter
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(TransferMinter_exports);
|
|
34
|
+
var import_viem = require("viem");
|
|
35
|
+
var import_iERC20 = require("../../abi/iERC20.js");
|
|
36
|
+
var import_AbstractMinter = __toESM(require("./AbstractMinter.js"));
|
|
37
|
+
class TransferMinter extends import_AbstractMinter.default {
|
|
38
|
+
constructor(sdk, anvil) {
|
|
39
|
+
super(sdk, anvil, "TransferMinter");
|
|
40
|
+
}
|
|
41
|
+
async mint(token, dest, amount) {
|
|
42
|
+
const owner = await this.getOwner(token);
|
|
43
|
+
const stopImpersonating = await this.impersonateWithBalance(owner);
|
|
44
|
+
let hash = await this.anvil.writeContract({
|
|
45
|
+
account: owner,
|
|
46
|
+
address: token,
|
|
47
|
+
abi: (0, import_viem.parseAbi)(["function mint(uint256 amount) external returns (bool)"]),
|
|
48
|
+
functionName: "mint",
|
|
49
|
+
args: [amount],
|
|
50
|
+
chain: this.anvil.chain
|
|
51
|
+
});
|
|
52
|
+
this.logger?.debug(
|
|
53
|
+
`mint ${this.fmt(token, amount)} to ${owner} in tx ${hash}`
|
|
54
|
+
);
|
|
55
|
+
let receipt = await this.anvil.waitForTransactionReceipt({ hash });
|
|
56
|
+
if (receipt.status === "reverted") {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`failed to mint ${this.fmt(token, amount)} to ${owner} in tx ${hash}: reverted`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
hash = await this.anvil.writeContract({
|
|
62
|
+
account: owner,
|
|
63
|
+
address: token,
|
|
64
|
+
abi: import_iERC20.ierc20Abi,
|
|
65
|
+
functionName: "transfer",
|
|
66
|
+
args: [dest, amount],
|
|
67
|
+
chain: this.anvil.chain
|
|
68
|
+
});
|
|
69
|
+
this.logger?.debug(
|
|
70
|
+
`transfer ${this.fmt(token, amount)} from ${owner} to ${dest} in tx ${hash}`
|
|
71
|
+
);
|
|
72
|
+
receipt = await this.anvil.waitForTransactionReceipt({ hash });
|
|
73
|
+
if (receipt.status === "reverted") {
|
|
74
|
+
throw new Error(
|
|
75
|
+
`failed to transfer ${this.fmt(token, amount)} from ${owner} to ${dest} in tx ${hash}: reverted`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
await stopImpersonating();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
TransferMinter
|
|
84
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var factory_exports = {};
|
|
20
|
+
__export(factory_exports, {
|
|
21
|
+
createMinter: () => createMinter
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(factory_exports);
|
|
24
|
+
var import_DealMinter = require("./DealMinter.js");
|
|
25
|
+
var import_DirectMinter = require("./DirectMinter.js");
|
|
26
|
+
var import_FallbackMinter = require("./FallbackMinter.js");
|
|
27
|
+
var import_TransferMinter = require("./TransferMinter.js");
|
|
28
|
+
function createMinter(sdk, anvil, token) {
|
|
29
|
+
return new import_FallbackMinter.FallbackMinter(sdk, anvil, [
|
|
30
|
+
new import_DealMinter.DealMinter(sdk, anvil),
|
|
31
|
+
new import_DirectMinter.DirectMinter(sdk, anvil),
|
|
32
|
+
new import_TransferMinter.TransferMinter(sdk, anvil)
|
|
33
|
+
]);
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
createMinter
|
|
38
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var mint_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(mint_exports);
|
|
18
|
+
__reExport(mint_exports, require("./factory.js"), module.exports);
|
|
19
|
+
__reExport(mint_exports, require("./types.js"), module.exports);
|
|
20
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
+
0 && (module.exports = {
|
|
22
|
+
...require("./factory.js"),
|
|
23
|
+
...require("./types.js")
|
|
24
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
BaseError,
|
|
3
3
|
erc20Abi,
|
|
4
4
|
isAddress,
|
|
5
|
-
parseAbi,
|
|
6
5
|
parseEther,
|
|
7
6
|
parseEventLogs
|
|
8
7
|
} from "viem";
|
|
@@ -20,9 +19,10 @@ import {
|
|
|
20
19
|
SDKConstruct,
|
|
21
20
|
sendRawTx
|
|
22
21
|
} from "../sdk/index.js";
|
|
23
|
-
import { iDegenNftv2Abi
|
|
22
|
+
import { iDegenNftv2Abi } from "./abi.js";
|
|
24
23
|
import { claimFromFaucet } from "./claimFromFaucet.js";
|
|
25
24
|
import { createAnvilClient } from "./createAnvilClient.js";
|
|
25
|
+
import { createMinter } from "./mint/index.js";
|
|
26
26
|
const DIRECT_TRANSFERS_QUOTA = 10000n;
|
|
27
27
|
class OpenTxRevertedError extends BaseError {
|
|
28
28
|
txHash;
|
|
@@ -494,106 +494,8 @@ class AccountOpener extends SDKConstruct {
|
|
|
494
494
|
* @param amount
|
|
495
495
|
*/
|
|
496
496
|
async #tryMint(token, dest, amount) {
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
await this.#mint(token, dest, amount);
|
|
500
|
-
} catch (e) {
|
|
501
|
-
this.#logger?.warn(`failed to mint ${amnt} to ${dest.address}: ${e}`);
|
|
502
|
-
}
|
|
503
|
-
return await this.#anvil.readContract({
|
|
504
|
-
address: token,
|
|
505
|
-
abi: ierc20Abi,
|
|
506
|
-
functionName: "balanceOf",
|
|
507
|
-
args: [dest.address]
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
|
-
async #mint(token, dest, amount) {
|
|
511
|
-
const symbol = this.sdk.tokensMeta.symbol(token);
|
|
512
|
-
const amnt = this.sdk.tokensMeta.formatBN(token, amount);
|
|
513
|
-
this.#logger?.warn(`minting ${amnt} ${symbol} to ${dest.address}`);
|
|
514
|
-
const owner = await this.#anvil.readContract({
|
|
515
|
-
address: token,
|
|
516
|
-
abi: iOwnableAbi,
|
|
517
|
-
functionName: "owner"
|
|
518
|
-
});
|
|
519
|
-
this.#logger?.warn(`owner of ${symbol}: ${owner}`);
|
|
520
|
-
await this.#anvil.impersonateAccount({ address: owner });
|
|
521
|
-
await this.#anvil.setBalance({
|
|
522
|
-
address: owner,
|
|
523
|
-
value: parseEther("1000000")
|
|
524
|
-
});
|
|
525
|
-
try {
|
|
526
|
-
await this.#mintDirectly(owner, token, amount, dest.address);
|
|
527
|
-
} catch (e) {
|
|
528
|
-
this.#logger?.warn(
|
|
529
|
-
`failed to mint directly ${amnt} ${symbol} to ${dest.address}: ${e}`
|
|
530
|
-
);
|
|
531
|
-
try {
|
|
532
|
-
await this.#mintAndTransfer(owner, token, amount, dest.address);
|
|
533
|
-
} catch (e2) {
|
|
534
|
-
this.#logger?.warn(
|
|
535
|
-
`failed to mint and transfer ${amnt} ${symbol} to ${dest.address}: ${e2}`
|
|
536
|
-
);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
await this.#anvil.stopImpersonatingAccount({ address: owner });
|
|
540
|
-
}
|
|
541
|
-
async #mintDirectly(owner, token, amount, dest) {
|
|
542
|
-
const hash = await this.#anvil.writeContract({
|
|
543
|
-
account: owner,
|
|
544
|
-
address: token,
|
|
545
|
-
abi: parseAbi([
|
|
546
|
-
"function mint(address to, uint256 amount) returns (bool)"
|
|
547
|
-
]),
|
|
548
|
-
functionName: "mint",
|
|
549
|
-
args: [dest, amount],
|
|
550
|
-
chain: this.#anvil.chain
|
|
551
|
-
});
|
|
552
|
-
this.#logger?.debug(
|
|
553
|
-
`mint ${this.sdk.tokensMeta.formatBN(token, amount, { symbol: true })} to ${owner} in tx ${hash}`
|
|
554
|
-
);
|
|
555
|
-
const receipt = await this.#anvil.waitForTransactionReceipt({ hash });
|
|
556
|
-
if (receipt.status === "reverted") {
|
|
557
|
-
throw new Error(
|
|
558
|
-
`failed to mint ${this.sdk.tokensMeta.formatBN(token, amount, { symbol: true })} to ${owner} in tx ${hash}: reverted`
|
|
559
|
-
);
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
async #mintAndTransfer(owner, token, amount, dest) {
|
|
563
|
-
let hash = await this.#anvil.writeContract({
|
|
564
|
-
account: owner,
|
|
565
|
-
address: token,
|
|
566
|
-
abi: parseAbi(["function mint(uint256 amount) external returns (bool)"]),
|
|
567
|
-
functionName: "mint",
|
|
568
|
-
args: [amount],
|
|
569
|
-
chain: this.#anvil.chain
|
|
570
|
-
});
|
|
571
|
-
this.#logger?.debug(
|
|
572
|
-
`mint ${this.sdk.tokensMeta.formatBN(token, amount, { symbol: true })} to ${owner} in tx ${hash}`
|
|
573
|
-
);
|
|
574
|
-
let receipt = await this.#anvil.waitForTransactionReceipt({ hash });
|
|
575
|
-
if (receipt.status === "reverted") {
|
|
576
|
-
throw new Error(
|
|
577
|
-
`failed to mint ${this.sdk.tokensMeta.formatBN(token, amount, { symbol: true })} to ${owner} in tx ${hash}: reverted`
|
|
578
|
-
);
|
|
579
|
-
}
|
|
580
|
-
hash = await this.#anvil.writeContract({
|
|
581
|
-
account: owner,
|
|
582
|
-
address: token,
|
|
583
|
-
abi: ierc20Abi,
|
|
584
|
-
functionName: "transfer",
|
|
585
|
-
args: [dest, amount],
|
|
586
|
-
chain: this.#anvil.chain
|
|
587
|
-
});
|
|
588
|
-
this.#logger?.debug(
|
|
589
|
-
`transfer ${this.sdk.tokensMeta.formatBN(token, amount, { symbol: true })} from ${owner} to ${dest} in tx ${hash}`
|
|
590
|
-
);
|
|
591
|
-
receipt = await this.#anvil.waitForTransactionReceipt({ hash });
|
|
592
|
-
if (receipt.status === "reverted") {
|
|
593
|
-
throw new Error(
|
|
594
|
-
`failed to transfer ${this.sdk.tokensMeta.formatBN(token, amount, { symbol: true })} from ${owner} to ${dest} in tx ${hash}: reverted`
|
|
595
|
-
);
|
|
596
|
-
}
|
|
497
|
+
const minter = createMinter(this.sdk, this.#anvil, token);
|
|
498
|
+
return minter.tryMint(token, dest.address, amount);
|
|
597
499
|
}
|
|
598
500
|
/**
|
|
599
501
|
* Creates borrower wallet,
|
package/dist/esm/dev/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./detectChain.js";
|
|
|
8
8
|
export * from "./EthCallSpy.js";
|
|
9
9
|
export * from "./ltUtils.js";
|
|
10
10
|
export * from "./migrateFaucet.js";
|
|
11
|
+
export * from "./mint/index.js";
|
|
11
12
|
export * from "./providers.js";
|
|
12
13
|
export * from "./RevolverTransport.js";
|
|
13
14
|
export * from "./types.js";
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { parseEther } from "viem";
|
|
2
|
+
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
3
|
+
import {
|
|
4
|
+
SDKConstruct
|
|
5
|
+
} from "../../sdk/index.js";
|
|
6
|
+
import { iOwnableAbi } from "../abi.js";
|
|
7
|
+
class AbstractMinter extends SDKConstruct {
|
|
8
|
+
anvil;
|
|
9
|
+
logger;
|
|
10
|
+
name;
|
|
11
|
+
constructor(sdk, anvil, name = "Minter") {
|
|
12
|
+
super(sdk);
|
|
13
|
+
this.anvil = anvil;
|
|
14
|
+
this.name = name;
|
|
15
|
+
this.logger = sdk.logger?.child?.({ name }) ?? sdk.logger;
|
|
16
|
+
}
|
|
17
|
+
async tryMint(token, dest, amount) {
|
|
18
|
+
const amnt = this.fmt(token, amount);
|
|
19
|
+
const before = await this.balanceOf(token, dest);
|
|
20
|
+
try {
|
|
21
|
+
await this.mint(token, dest, amount);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
this.logger?.warn(`failed to mint ${amnt} to ${dest}: ${e}`);
|
|
24
|
+
}
|
|
25
|
+
const after = await this.balanceOf(token, dest);
|
|
26
|
+
const minted = after - before;
|
|
27
|
+
this.logger?.debug(`minted ${this.fmt(token, minted)} to ${dest}`);
|
|
28
|
+
return after;
|
|
29
|
+
}
|
|
30
|
+
async getOwner(address) {
|
|
31
|
+
const owner = await this.anvil.readContract({
|
|
32
|
+
address,
|
|
33
|
+
abi: iOwnableAbi,
|
|
34
|
+
functionName: "owner"
|
|
35
|
+
});
|
|
36
|
+
this.logger?.debug(`owner of ${this.sdk.labelAddress(address)}: ${owner}`);
|
|
37
|
+
return owner;
|
|
38
|
+
}
|
|
39
|
+
async impersonateWithBalance(address, balance = "1000") {
|
|
40
|
+
await this.anvil.impersonateAccount({ address });
|
|
41
|
+
await this.anvil.setBalance({
|
|
42
|
+
address,
|
|
43
|
+
value: parseEther(balance)
|
|
44
|
+
});
|
|
45
|
+
return async () => {
|
|
46
|
+
await this.anvil.stopImpersonatingAccount({ address });
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
fmt(token, amount) {
|
|
50
|
+
return this.sdk.tokensMeta.formatBN(token, amount, { symbol: true });
|
|
51
|
+
}
|
|
52
|
+
balanceOf(token, dest) {
|
|
53
|
+
return this.anvil.readContract({
|
|
54
|
+
address: token,
|
|
55
|
+
abi: ierc20Abi,
|
|
56
|
+
functionName: "balanceOf",
|
|
57
|
+
args: [dest]
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
AbstractMinter as default
|
|
63
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { deal } from "viem-deal";
|
|
2
|
+
import AbstractMinter from "./AbstractMinter.js";
|
|
3
|
+
class DealMinter extends AbstractMinter {
|
|
4
|
+
constructor(sdk, anvil) {
|
|
5
|
+
super(sdk, anvil, "DealMinter");
|
|
6
|
+
}
|
|
7
|
+
async mint(token, dest, amount) {
|
|
8
|
+
let balance = await this.balanceOf(token, dest);
|
|
9
|
+
balance += amount;
|
|
10
|
+
this.logger?.debug(`set balance of ${dest} to ${this.fmt(token, balance)}`);
|
|
11
|
+
await deal(this.anvil, {
|
|
12
|
+
erc20: token,
|
|
13
|
+
account: dest,
|
|
14
|
+
amount: balance
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
DealMinter
|
|
20
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { parseAbi } from "viem";
|
|
2
|
+
import AbstractMinter from "./AbstractMinter.js";
|
|
3
|
+
class DirectMinter extends AbstractMinter {
|
|
4
|
+
constructor(sdk, anvil) {
|
|
5
|
+
super(sdk, anvil, "DirectMinter");
|
|
6
|
+
}
|
|
7
|
+
async mint(token, dest, amount) {
|
|
8
|
+
const owner = await this.getOwner(token);
|
|
9
|
+
const stopImpersonating = await this.impersonateWithBalance(owner);
|
|
10
|
+
const hash = await this.anvil.writeContract({
|
|
11
|
+
account: owner,
|
|
12
|
+
address: token,
|
|
13
|
+
abi: parseAbi([
|
|
14
|
+
"function mint(address to, uint256 amount) returns (bool)"
|
|
15
|
+
]),
|
|
16
|
+
functionName: "mint",
|
|
17
|
+
args: [dest, amount],
|
|
18
|
+
chain: this.anvil.chain
|
|
19
|
+
});
|
|
20
|
+
this.logger?.debug(
|
|
21
|
+
`mint ${this.fmt(token, amount)} to ${owner} in tx ${hash}`
|
|
22
|
+
);
|
|
23
|
+
const receipt = await this.anvil.waitForTransactionReceipt({ hash });
|
|
24
|
+
if (receipt.status === "reverted") {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`failed to mint ${this.fmt(token, amount)} to ${owner} in tx ${hash}: reverted`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
await stopImpersonating();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
DirectMinter
|
|
34
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import AbstractMinter from "./AbstractMinter.js";
|
|
2
|
+
class FallbackMinter extends AbstractMinter {
|
|
3
|
+
#minters;
|
|
4
|
+
constructor(sdk, anvil, minters) {
|
|
5
|
+
super(sdk, anvil, "FallbackMinter");
|
|
6
|
+
this.#minters = minters;
|
|
7
|
+
}
|
|
8
|
+
async mint(token, dest, amount) {
|
|
9
|
+
for (const minter of this.#minters) {
|
|
10
|
+
try {
|
|
11
|
+
await minter.mint(token, dest, amount);
|
|
12
|
+
this.logger?.debug(`${minter.name} succeeded`);
|
|
13
|
+
return;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
this.logger?.warn(`${minter.name} failed: ${e}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
throw new Error("all minters failed");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
FallbackMinter
|
|
23
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { parseAbi } from "viem";
|
|
2
|
+
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
3
|
+
import AbstractMinter from "./AbstractMinter.js";
|
|
4
|
+
class TransferMinter extends AbstractMinter {
|
|
5
|
+
constructor(sdk, anvil) {
|
|
6
|
+
super(sdk, anvil, "TransferMinter");
|
|
7
|
+
}
|
|
8
|
+
async mint(token, dest, amount) {
|
|
9
|
+
const owner = await this.getOwner(token);
|
|
10
|
+
const stopImpersonating = await this.impersonateWithBalance(owner);
|
|
11
|
+
let hash = await this.anvil.writeContract({
|
|
12
|
+
account: owner,
|
|
13
|
+
address: token,
|
|
14
|
+
abi: parseAbi(["function mint(uint256 amount) external returns (bool)"]),
|
|
15
|
+
functionName: "mint",
|
|
16
|
+
args: [amount],
|
|
17
|
+
chain: this.anvil.chain
|
|
18
|
+
});
|
|
19
|
+
this.logger?.debug(
|
|
20
|
+
`mint ${this.fmt(token, amount)} to ${owner} in tx ${hash}`
|
|
21
|
+
);
|
|
22
|
+
let receipt = await this.anvil.waitForTransactionReceipt({ hash });
|
|
23
|
+
if (receipt.status === "reverted") {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`failed to mint ${this.fmt(token, amount)} to ${owner} in tx ${hash}: reverted`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
hash = await this.anvil.writeContract({
|
|
29
|
+
account: owner,
|
|
30
|
+
address: token,
|
|
31
|
+
abi: ierc20Abi,
|
|
32
|
+
functionName: "transfer",
|
|
33
|
+
args: [dest, amount],
|
|
34
|
+
chain: this.anvil.chain
|
|
35
|
+
});
|
|
36
|
+
this.logger?.debug(
|
|
37
|
+
`transfer ${this.fmt(token, amount)} from ${owner} to ${dest} in tx ${hash}`
|
|
38
|
+
);
|
|
39
|
+
receipt = await this.anvil.waitForTransactionReceipt({ hash });
|
|
40
|
+
if (receipt.status === "reverted") {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`failed to transfer ${this.fmt(token, amount)} from ${owner} to ${dest} in tx ${hash}: reverted`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
await stopImpersonating();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
TransferMinter
|
|
50
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DealMinter } from "./DealMinter.js";
|
|
2
|
+
import { DirectMinter } from "./DirectMinter.js";
|
|
3
|
+
import { FallbackMinter } from "./FallbackMinter.js";
|
|
4
|
+
import { TransferMinter } from "./TransferMinter.js";
|
|
5
|
+
function createMinter(sdk, anvil, token) {
|
|
6
|
+
return new FallbackMinter(sdk, anvil, [
|
|
7
|
+
new DealMinter(sdk, anvil),
|
|
8
|
+
new DirectMinter(sdk, anvil),
|
|
9
|
+
new TransferMinter(sdk, anvil)
|
|
10
|
+
]);
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
createMinter
|
|
14
|
+
};
|
|
File without changes
|
|
@@ -8,6 +8,7 @@ export * from "./detectChain.js";
|
|
|
8
8
|
export * from "./EthCallSpy.js";
|
|
9
9
|
export * from "./ltUtils.js";
|
|
10
10
|
export * from "./migrateFaucet.js";
|
|
11
|
+
export * from "./mint/index.js";
|
|
11
12
|
export * from "./providers.js";
|
|
12
13
|
export * from "./RevolverTransport.js";
|
|
13
14
|
export * from "./types.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import { type GearboxSDK, type ILogger, SDKConstruct } from "../../sdk/index.js";
|
|
3
|
+
import type { AnvilClient } from "../createAnvilClient.js";
|
|
4
|
+
import type { IMinter } from "./types.js";
|
|
5
|
+
export default abstract class AbstractMinter extends SDKConstruct implements IMinter {
|
|
6
|
+
protected readonly anvil: AnvilClient;
|
|
7
|
+
protected readonly logger?: ILogger;
|
|
8
|
+
readonly name: string;
|
|
9
|
+
constructor(sdk: GearboxSDK, anvil: AnvilClient, name?: string);
|
|
10
|
+
tryMint(token: Address, dest: Address, amount: bigint): Promise<bigint>;
|
|
11
|
+
abstract mint(token: Address, dest: Address, amount: bigint): Promise<void>;
|
|
12
|
+
protected getOwner(address: Address): Promise<Address>;
|
|
13
|
+
protected impersonateWithBalance(address: Address, balance?: string): Promise<() => Promise<void>>;
|
|
14
|
+
protected fmt(token: Address, amount: bigint): string;
|
|
15
|
+
protected balanceOf(token: Address, dest: Address): Promise<bigint>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { GearboxSDK } from "../../sdk/index.js";
|
|
3
|
+
import type { AnvilClient } from "../createAnvilClient.js";
|
|
4
|
+
import AbstractMinter from "./AbstractMinter.js";
|
|
5
|
+
import type { IMinter } from "./types.js";
|
|
6
|
+
export declare class DealMinter extends AbstractMinter implements IMinter {
|
|
7
|
+
constructor(sdk: GearboxSDK, anvil: AnvilClient);
|
|
8
|
+
mint(token: Address, dest: Address, amount: bigint): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import type { GearboxSDK } from "../../sdk/index.js";
|
|
3
|
+
import type { AnvilClient } from "../createAnvilClient.js";
|
|
4
|
+
import AbstractMinter from "./AbstractMinter.js";
|
|
5
|
+
import type { IMinter } from "./types.js";
|
|
6
|
+
export declare class DirectMinter extends AbstractMinter implements IMinter {
|
|
7
|
+
constructor(sdk: GearboxSDK, anvil: AnvilClient);
|
|
8
|
+
mint(token: Address, dest: Address, amount: bigint): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { GearboxSDK } from "../../sdk/index.js";
|
|
3
|
+
import type { AnvilClient } from "../createAnvilClient.js";
|
|
4
|
+
import AbstractMinter from "./AbstractMinter.js";
|
|
5
|
+
import type { IMinter } from "./types.js";
|
|
6
|
+
export declare class FallbackMinter extends AbstractMinter implements IMinter {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(sdk: GearboxSDK, anvil: AnvilClient, minters: IMinter[]);
|
|
9
|
+
mint(token: Address, dest: Address, amount: bigint): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import type { GearboxSDK } from "../../sdk/index.js";
|
|
3
|
+
import type { AnvilClient } from "../createAnvilClient.js";
|
|
4
|
+
import AbstractMinter from "./AbstractMinter.js";
|
|
5
|
+
import type { IMinter } from "./types.js";
|
|
6
|
+
export declare class TransferMinter extends AbstractMinter implements IMinter {
|
|
7
|
+
constructor(sdk: GearboxSDK, anvil: AnvilClient);
|
|
8
|
+
mint(token: Address, dest: Address, amount: bigint): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { GearboxSDK } from "../../sdk/index.js";
|
|
3
|
+
import type { AnvilClient } from "../createAnvilClient";
|
|
4
|
+
import type { IMinter } from "./types.js";
|
|
5
|
+
export declare function createMinter(sdk: GearboxSDK, anvil: AnvilClient, token: Address): IMinter;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
export interface IMinter {
|
|
3
|
+
/**
|
|
4
|
+
* Tries to mint tokens, returns the balance after attempt (success or not)
|
|
5
|
+
* If mint failed, does not throw
|
|
6
|
+
* @param token
|
|
7
|
+
* @param dest
|
|
8
|
+
* @param amount
|
|
9
|
+
*/
|
|
10
|
+
tryMint: (token: Address, dest: Address, amount: bigint) => Promise<bigint>;
|
|
11
|
+
/**
|
|
12
|
+
* Tries to mint tokens, throws if failed
|
|
13
|
+
* @param token
|
|
14
|
+
* @param dest
|
|
15
|
+
* @param amount
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
mint: (token: Address, dest: Address, amount: bigint) => Promise<void>;
|
|
19
|
+
name: string;
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/sdk",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.10.1",
|
|
4
4
|
"description": "Gearbox SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/cjs/sdk/index.js",
|
|
@@ -65,23 +65,25 @@
|
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@biomejs/biome": "^2.2.4",
|
|
68
|
-
"@commitlint/cli": "^20.
|
|
68
|
+
"@commitlint/cli": "^20.1.0",
|
|
69
69
|
"@commitlint/config-conventional": "^20.0.0",
|
|
70
70
|
"@gearbox-protocol/biome-config": "^1.0.2",
|
|
71
71
|
"@types/cross-spawn": "^6.0.6",
|
|
72
72
|
"axios": "^1.12.2",
|
|
73
73
|
"cross-spawn": "^7.0.6",
|
|
74
74
|
"husky": "^9.1.7",
|
|
75
|
-
"lint-staged": "^16.2.
|
|
76
|
-
"pino": "^9.
|
|
75
|
+
"lint-staged": "^16.2.3",
|
|
76
|
+
"pino": "^9.12.0",
|
|
77
77
|
"pino-pretty": "^13.1.1",
|
|
78
78
|
"tsup": "^8.5.0",
|
|
79
79
|
"tsx": "^4.20.6",
|
|
80
80
|
"typescript": "^5.9.2",
|
|
81
|
+
"viem-deal": "^2.0.4",
|
|
81
82
|
"vitest": "^3.2.4"
|
|
82
83
|
},
|
|
83
84
|
"peerDependencies": {
|
|
84
|
-
"axios": "^1.0.0"
|
|
85
|
+
"axios": "^1.0.0",
|
|
86
|
+
"viem-deal": "^2.0.4"
|
|
85
87
|
},
|
|
86
88
|
"commitlint": {
|
|
87
89
|
"extends": [
|