@gearbox-protocol/sdk 3.0.0-vfour.132 → 3.0.0-vfour.134
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/index.cjs +90 -0
- package/dist/cjs/dev/index.d.ts +16 -1
- package/dist/cjs/sdk/index.cjs +1 -1
- package/dist/esm/dev/index.d.mts +17 -2
- package/dist/esm/dev/index.mjs +92 -3
- package/dist/esm/sdk/index.mjs +1 -1
- package/package.json +1 -1
package/dist/cjs/dev/index.cjs
CHANGED
|
@@ -4,6 +4,7 @@ var sdkGov = require('@gearbox-protocol/sdk-gov');
|
|
|
4
4
|
var viem = require('viem');
|
|
5
5
|
var accounts = require('viem/accounts');
|
|
6
6
|
var sdk = require('../sdk');
|
|
7
|
+
var promises = require('fs/promises');
|
|
7
8
|
|
|
8
9
|
// src/dev/AccountOpener.ts
|
|
9
10
|
function createAnvilClient({
|
|
@@ -366,6 +367,94 @@ async function calcLiquidatableLTs(sdk$1, ca, factor = 9990n, logger) {
|
|
|
366
367
|
}
|
|
367
368
|
return result;
|
|
368
369
|
}
|
|
370
|
+
var SDKExample = class {
|
|
371
|
+
#sdk;
|
|
372
|
+
#logger;
|
|
373
|
+
constructor(logger) {
|
|
374
|
+
this.#logger = logger;
|
|
375
|
+
}
|
|
376
|
+
async run(opts) {
|
|
377
|
+
const {
|
|
378
|
+
addressProvider: ap,
|
|
379
|
+
addressProviderJson,
|
|
380
|
+
marketConfigurator: mc,
|
|
381
|
+
marketConfiguratorJson,
|
|
382
|
+
anvilUrl = "http://127.0.0.1:8545",
|
|
383
|
+
outFile
|
|
384
|
+
} = opts;
|
|
385
|
+
const addressProvider = await this.#readConfigAddress(
|
|
386
|
+
"addressProvider",
|
|
387
|
+
ap,
|
|
388
|
+
addressProviderJson
|
|
389
|
+
);
|
|
390
|
+
const marketConfigurator = await this.#readConfigAddress(
|
|
391
|
+
"marketConfigurator",
|
|
392
|
+
mc,
|
|
393
|
+
marketConfiguratorJson
|
|
394
|
+
);
|
|
395
|
+
this.#sdk = await sdk.GearboxSDK.attach({
|
|
396
|
+
rpcURLs: [anvilUrl],
|
|
397
|
+
timeout: 48e4,
|
|
398
|
+
addressProvider,
|
|
399
|
+
logger: this.#logger,
|
|
400
|
+
ignoreUpdateablePrices: true,
|
|
401
|
+
marketConfigurators: [marketConfigurator]
|
|
402
|
+
});
|
|
403
|
+
const puTx = await this.#sdk.priceFeeds.getUpdatePriceFeedsTx([
|
|
404
|
+
marketConfigurator
|
|
405
|
+
]);
|
|
406
|
+
const updater = viem.createWalletClient({
|
|
407
|
+
account: accounts.privateKeyToAccount(
|
|
408
|
+
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
|
|
409
|
+
// well-known anvil private key
|
|
410
|
+
),
|
|
411
|
+
transport: viem.http(anvilUrl)
|
|
412
|
+
});
|
|
413
|
+
const publicClient = viem.createPublicClient({
|
|
414
|
+
transport: viem.http(anvilUrl)
|
|
415
|
+
});
|
|
416
|
+
const hash = await sdk.sendRawTx(updater, { tx: puTx });
|
|
417
|
+
await publicClient.waitForTransactionReceipt({ hash });
|
|
418
|
+
await this.#sdk.marketRegister.loadMarkets([marketConfigurator], true);
|
|
419
|
+
this.#logger?.info("attached sdk");
|
|
420
|
+
if (outFile) {
|
|
421
|
+
try {
|
|
422
|
+
await promises.writeFile(
|
|
423
|
+
outFile,
|
|
424
|
+
sdk.json_stringify(this.#sdk.stateHuman()),
|
|
425
|
+
"utf-8"
|
|
426
|
+
);
|
|
427
|
+
} catch (e) {
|
|
428
|
+
this.#logger?.error(`failed to write to ${outFile}: ${e}`);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
async #readConfigAddress(name, value, file) {
|
|
433
|
+
let result = value;
|
|
434
|
+
if (!result) {
|
|
435
|
+
if (!file) {
|
|
436
|
+
throw new Error(`${name} is not specified`);
|
|
437
|
+
}
|
|
438
|
+
this.#logger?.debug(`reading ${name} json ${file}`);
|
|
439
|
+
const apFile = await promises.readFile(file, "utf-8").then(JSON.parse);
|
|
440
|
+
result = apFile[name];
|
|
441
|
+
}
|
|
442
|
+
if (!result) {
|
|
443
|
+
throw new Error(`${name} is not specified`);
|
|
444
|
+
}
|
|
445
|
+
if (!viem.isAddress(result)) {
|
|
446
|
+
throw new Error(`${name} is not a valid address: ${result}`);
|
|
447
|
+
}
|
|
448
|
+
this.#logger?.info(`using ${name} ${result}`);
|
|
449
|
+
return result;
|
|
450
|
+
}
|
|
451
|
+
get sdk() {
|
|
452
|
+
if (!this.#sdk) {
|
|
453
|
+
throw new Error("sdk is not attached");
|
|
454
|
+
}
|
|
455
|
+
return this.#sdk;
|
|
456
|
+
}
|
|
457
|
+
};
|
|
369
458
|
|
|
370
459
|
// src/dev/abi/v3.ts
|
|
371
460
|
var iaclAbi = [
|
|
@@ -1875,6 +1964,7 @@ async function setLTZero(anvil, cm, logger) {
|
|
|
1875
1964
|
}
|
|
1876
1965
|
|
|
1877
1966
|
exports.AccountOpener = AccountOpener;
|
|
1967
|
+
exports.SDKExample = SDKExample;
|
|
1878
1968
|
exports.anvilNodeInfo = anvilNodeInfo;
|
|
1879
1969
|
exports.calcLiquidatableLTs = calcLiquidatableLTs;
|
|
1880
1970
|
exports.createAnvilClient = createAnvilClient;
|
package/dist/cjs/dev/index.d.ts
CHANGED
|
@@ -96,6 +96,21 @@ declare function anvilNodeInfo(client: Client<any, any, any, AnvilRPCSchema, any
|
|
|
96
96
|
*/
|
|
97
97
|
declare function evmMineDetailed(client: Client<any, any, any, AnvilRPCSchema, any>, timestamp: bigint | number): Promise<Block<Hex> | undefined>;
|
|
98
98
|
|
|
99
|
+
interface SDKExampleOptions {
|
|
100
|
+
addressProvider?: string;
|
|
101
|
+
addressProviderJson?: string;
|
|
102
|
+
marketConfigurator?: string;
|
|
103
|
+
marketConfiguratorJson?: string;
|
|
104
|
+
anvilUrl?: string;
|
|
105
|
+
outFile?: string;
|
|
106
|
+
}
|
|
107
|
+
declare class SDKExample {
|
|
108
|
+
#private;
|
|
109
|
+
constructor(logger?: ILogger);
|
|
110
|
+
run(opts: SDKExampleOptions): Promise<void>;
|
|
111
|
+
get sdk(): GearboxSDK;
|
|
112
|
+
}
|
|
113
|
+
|
|
99
114
|
/**
|
|
100
115
|
* Helper function to set liquidation thresholds on credit manager via anvil impersonation
|
|
101
116
|
* @param sdk
|
|
@@ -107,4 +122,4 @@ declare function setLTs(anvil: AnvilClient, cm: CreditManagerState, newLTs: Reco
|
|
|
107
122
|
type ZeroLTCMSlice = Pick<CreditManagerState, "creditConfigurator" | "feeInterest" | "liquidationDiscount" | "feeLiquidationExpired" | "liquidationDiscountExpired" | "feeLiquidation" | "name" | "underlying" | "baseParams">;
|
|
108
123
|
declare function setLTZero(anvil: AnvilClient, cm: ZeroLTCMSlice, logger?: ILogger): Promise<void>;
|
|
109
124
|
|
|
110
|
-
export { AccountOpener, type AccountOpenerOptions, type AnvilActions, type AnvilClient, type AnvilClientConfig, type AnvilNodeInfo, type AnvilRPCSchema, type TargetAccount, anvilNodeInfo, calcLiquidatableLTs, createAnvilClient, evmMineDetailed, isAnvil, setLTZero, setLTs };
|
|
125
|
+
export { AccountOpener, type AccountOpenerOptions, type AnvilActions, type AnvilClient, type AnvilClientConfig, type AnvilNodeInfo, type AnvilRPCSchema, SDKExample, type SDKExampleOptions, type TargetAccount, anvilNodeInfo, calcLiquidatableLTs, createAnvilClient, evmMineDetailed, isAnvil, setLTZero, setLTs };
|
package/dist/cjs/sdk/index.cjs
CHANGED
|
@@ -61617,7 +61617,7 @@ var GearboxSDK = class _GearboxSDK {
|
|
|
61617
61617
|
networkType
|
|
61618
61618
|
});
|
|
61619
61619
|
logger?.debug(
|
|
61620
|
-
{ networkType, chainId, addressProvider },
|
|
61620
|
+
{ networkType, chainId, addressProvider, marketConfigurators },
|
|
61621
61621
|
"attaching gearbox sdk"
|
|
61622
61622
|
);
|
|
61623
61623
|
return new _GearboxSDK({
|
package/dist/esm/dev/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Address, TestRpcSchema, Hex, Block, Prettify, Client, Transport, Chain, TestActions, PublicClient, WalletClient } from 'viem';
|
|
2
|
-
import { CreditAccountsService, CreditAccountData, GearboxSDK, ILogger, CreditManagerState } from '../sdk';
|
|
2
|
+
import { CreditAccountsService, CreditAccountData, GearboxSDK, ILogger, CreditManagerState } from '../sdk/index.d.mts';
|
|
3
3
|
|
|
4
4
|
interface AccountOpenerOptions {
|
|
5
5
|
faucet?: Address;
|
|
@@ -96,6 +96,21 @@ declare function anvilNodeInfo(client: Client<any, any, any, AnvilRPCSchema, any
|
|
|
96
96
|
*/
|
|
97
97
|
declare function evmMineDetailed(client: Client<any, any, any, AnvilRPCSchema, any>, timestamp: bigint | number): Promise<Block<Hex> | undefined>;
|
|
98
98
|
|
|
99
|
+
interface SDKExampleOptions {
|
|
100
|
+
addressProvider?: string;
|
|
101
|
+
addressProviderJson?: string;
|
|
102
|
+
marketConfigurator?: string;
|
|
103
|
+
marketConfiguratorJson?: string;
|
|
104
|
+
anvilUrl?: string;
|
|
105
|
+
outFile?: string;
|
|
106
|
+
}
|
|
107
|
+
declare class SDKExample {
|
|
108
|
+
#private;
|
|
109
|
+
constructor(logger?: ILogger);
|
|
110
|
+
run(opts: SDKExampleOptions): Promise<void>;
|
|
111
|
+
get sdk(): GearboxSDK;
|
|
112
|
+
}
|
|
113
|
+
|
|
99
114
|
/**
|
|
100
115
|
* Helper function to set liquidation thresholds on credit manager via anvil impersonation
|
|
101
116
|
* @param sdk
|
|
@@ -107,4 +122,4 @@ declare function setLTs(anvil: AnvilClient, cm: CreditManagerState, newLTs: Reco
|
|
|
107
122
|
type ZeroLTCMSlice = Pick<CreditManagerState, "creditConfigurator" | "feeInterest" | "liquidationDiscount" | "feeLiquidationExpired" | "liquidationDiscountExpired" | "feeLiquidation" | "name" | "underlying" | "baseParams">;
|
|
108
123
|
declare function setLTZero(anvil: AnvilClient, cm: ZeroLTCMSlice, logger?: ILogger): Promise<void>;
|
|
109
124
|
|
|
110
|
-
export { AccountOpener, type AccountOpenerOptions, type AnvilActions, type AnvilClient, type AnvilClientConfig, type AnvilNodeInfo, type AnvilRPCSchema, type TargetAccount, anvilNodeInfo, calcLiquidatableLTs, createAnvilClient, evmMineDetailed, isAnvil, setLTZero, setLTs };
|
|
125
|
+
export { AccountOpener, type AccountOpenerOptions, type AnvilActions, type AnvilClient, type AnvilClientConfig, type AnvilNodeInfo, type AnvilRPCSchema, SDKExample, type SDKExampleOptions, type TargetAccount, anvilNodeInfo, calcLiquidatableLTs, createAnvilClient, evmMineDetailed, isAnvil, setLTZero, setLTs };
|
package/dist/esm/dev/index.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ADDRESS_0X0, formatBN } from '@gearbox-protocol/sdk-gov';
|
|
2
|
-
import { createTestClient, publicActions, walletActions, toHex, isAddress, parseEther } from 'viem';
|
|
2
|
+
import { createTestClient, publicActions, walletActions, toHex, isAddress, parseEther, createWalletClient, http, createPublicClient } from 'viem';
|
|
3
3
|
import { privateKeyToAccount, generatePrivateKey } from 'viem/accounts';
|
|
4
|
-
import { childLogger, sendRawTx, ierc20Abi, MAX_UINT256, iDegenNftv2Abi, PERCENTAGE_FACTOR, WAD } from '../sdk/index.mjs';
|
|
4
|
+
import { childLogger, sendRawTx, ierc20Abi, MAX_UINT256, iDegenNftv2Abi, PERCENTAGE_FACTOR, GearboxSDK, json_stringify, WAD } from '../sdk/index.mjs';
|
|
5
|
+
import { writeFile, readFile } from 'node:fs/promises';
|
|
5
6
|
|
|
6
7
|
// src/dev/AccountOpener.ts
|
|
7
8
|
function createAnvilClient({
|
|
@@ -364,6 +365,94 @@ async function calcLiquidatableLTs(sdk, ca, factor = 9990n, logger) {
|
|
|
364
365
|
}
|
|
365
366
|
return result;
|
|
366
367
|
}
|
|
368
|
+
var SDKExample = class {
|
|
369
|
+
#sdk;
|
|
370
|
+
#logger;
|
|
371
|
+
constructor(logger) {
|
|
372
|
+
this.#logger = logger;
|
|
373
|
+
}
|
|
374
|
+
async run(opts) {
|
|
375
|
+
const {
|
|
376
|
+
addressProvider: ap,
|
|
377
|
+
addressProviderJson,
|
|
378
|
+
marketConfigurator: mc,
|
|
379
|
+
marketConfiguratorJson,
|
|
380
|
+
anvilUrl = "http://127.0.0.1:8545",
|
|
381
|
+
outFile
|
|
382
|
+
} = opts;
|
|
383
|
+
const addressProvider = await this.#readConfigAddress(
|
|
384
|
+
"addressProvider",
|
|
385
|
+
ap,
|
|
386
|
+
addressProviderJson
|
|
387
|
+
);
|
|
388
|
+
const marketConfigurator = await this.#readConfigAddress(
|
|
389
|
+
"marketConfigurator",
|
|
390
|
+
mc,
|
|
391
|
+
marketConfiguratorJson
|
|
392
|
+
);
|
|
393
|
+
this.#sdk = await GearboxSDK.attach({
|
|
394
|
+
rpcURLs: [anvilUrl],
|
|
395
|
+
timeout: 48e4,
|
|
396
|
+
addressProvider,
|
|
397
|
+
logger: this.#logger,
|
|
398
|
+
ignoreUpdateablePrices: true,
|
|
399
|
+
marketConfigurators: [marketConfigurator]
|
|
400
|
+
});
|
|
401
|
+
const puTx = await this.#sdk.priceFeeds.getUpdatePriceFeedsTx([
|
|
402
|
+
marketConfigurator
|
|
403
|
+
]);
|
|
404
|
+
const updater = createWalletClient({
|
|
405
|
+
account: privateKeyToAccount(
|
|
406
|
+
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
|
|
407
|
+
// well-known anvil private key
|
|
408
|
+
),
|
|
409
|
+
transport: http(anvilUrl)
|
|
410
|
+
});
|
|
411
|
+
const publicClient = createPublicClient({
|
|
412
|
+
transport: http(anvilUrl)
|
|
413
|
+
});
|
|
414
|
+
const hash = await sendRawTx(updater, { tx: puTx });
|
|
415
|
+
await publicClient.waitForTransactionReceipt({ hash });
|
|
416
|
+
await this.#sdk.marketRegister.loadMarkets([marketConfigurator], true);
|
|
417
|
+
this.#logger?.info("attached sdk");
|
|
418
|
+
if (outFile) {
|
|
419
|
+
try {
|
|
420
|
+
await writeFile(
|
|
421
|
+
outFile,
|
|
422
|
+
json_stringify(this.#sdk.stateHuman()),
|
|
423
|
+
"utf-8"
|
|
424
|
+
);
|
|
425
|
+
} catch (e) {
|
|
426
|
+
this.#logger?.error(`failed to write to ${outFile}: ${e}`);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
async #readConfigAddress(name, value, file) {
|
|
431
|
+
let result = value;
|
|
432
|
+
if (!result) {
|
|
433
|
+
if (!file) {
|
|
434
|
+
throw new Error(`${name} is not specified`);
|
|
435
|
+
}
|
|
436
|
+
this.#logger?.debug(`reading ${name} json ${file}`);
|
|
437
|
+
const apFile = await readFile(file, "utf-8").then(JSON.parse);
|
|
438
|
+
result = apFile[name];
|
|
439
|
+
}
|
|
440
|
+
if (!result) {
|
|
441
|
+
throw new Error(`${name} is not specified`);
|
|
442
|
+
}
|
|
443
|
+
if (!isAddress(result)) {
|
|
444
|
+
throw new Error(`${name} is not a valid address: ${result}`);
|
|
445
|
+
}
|
|
446
|
+
this.#logger?.info(`using ${name} ${result}`);
|
|
447
|
+
return result;
|
|
448
|
+
}
|
|
449
|
+
get sdk() {
|
|
450
|
+
if (!this.#sdk) {
|
|
451
|
+
throw new Error("sdk is not attached");
|
|
452
|
+
}
|
|
453
|
+
return this.#sdk;
|
|
454
|
+
}
|
|
455
|
+
};
|
|
367
456
|
|
|
368
457
|
// src/dev/abi/v3.ts
|
|
369
458
|
var iaclAbi = [
|
|
@@ -1872,4 +1961,4 @@ async function setLTZero(anvil, cm, logger) {
|
|
|
1872
1961
|
await anvil.stopImpersonatingAccount({ address: configuratorAddr });
|
|
1873
1962
|
}
|
|
1874
1963
|
|
|
1875
|
-
export { AccountOpener, anvilNodeInfo, calcLiquidatableLTs, createAnvilClient, evmMineDetailed, isAnvil, setLTZero, setLTs };
|
|
1964
|
+
export { AccountOpener, SDKExample, anvilNodeInfo, calcLiquidatableLTs, createAnvilClient, evmMineDetailed, isAnvil, setLTZero, setLTs };
|
package/dist/esm/sdk/index.mjs
CHANGED
|
@@ -61615,7 +61615,7 @@ var GearboxSDK = class _GearboxSDK {
|
|
|
61615
61615
|
networkType
|
|
61616
61616
|
});
|
|
61617
61617
|
logger?.debug(
|
|
61618
|
-
{ networkType, chainId, addressProvider },
|
|
61618
|
+
{ networkType, chainId, addressProvider, marketConfigurators },
|
|
61619
61619
|
"attaching gearbox sdk"
|
|
61620
61620
|
);
|
|
61621
61621
|
return new _GearboxSDK({
|