@gearbox-protocol/sdk 13.7.0-kyc.3 → 14.0.0-next.10
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 +5 -45
- package/dist/cjs/dev/RevolverTransport.js +10 -4
- package/dist/cjs/dev/index.js +0 -2
- package/dist/cjs/dev/logSplitterTransport.js +10 -1
- package/dist/cjs/permissionless/utils/create2.js +2 -2
- package/dist/cjs/permissionless/utils/price-update/get-price-feeds.js +11 -5
- package/dist/cjs/permissionless/utils/price-update/get-price-update-tx.js +11 -5
- package/dist/cjs/permissionless/utils/price-update/get-prices.js +12 -6
- package/dist/cjs/sdk/MultichainSDK.js +232 -0
- package/dist/cjs/sdk/OnchainSDK.js +478 -0
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +16 -324
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +1 -7
- package/dist/cjs/sdk/base/TokensMeta.js +42 -22
- package/dist/cjs/sdk/base/token-types.js +0 -9
- package/dist/cjs/sdk/chain/chains.js +1 -2
- package/dist/cjs/sdk/constants/address-provider.js +0 -3
- package/dist/cjs/sdk/core/errors.js +77 -0
- package/dist/cjs/sdk/core/index.js +2 -0
- package/dist/cjs/sdk/index.js +4 -2
- package/dist/cjs/sdk/market/MarketRegister.js +116 -70
- package/dist/cjs/sdk/market/MarketSuite.js +0 -3
- package/dist/cjs/sdk/market/index.js +0 -2
- package/dist/cjs/sdk/market/pool/PoolSuite.js +0 -3
- package/dist/cjs/sdk/market/pool/PoolV310Contract.js +2 -11
- package/dist/cjs/sdk/market/pool/index.js +0 -2
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +10 -3
- package/dist/cjs/sdk/market/pricefeeds/updates/PythAccumulatorUpdateData.js +20 -23
- package/dist/cjs/sdk/market/pricefeeds/updates/PythUpdater.js +7 -4
- package/dist/cjs/sdk/market/pricefeeds/updates/RedstoneUpdater.js +4 -4
- package/dist/cjs/sdk/market/pricefeeds/updates/fetchPythPayloads.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/updates/index.js +3 -0
- package/dist/cjs/sdk/options.js +24 -52
- package/dist/cjs/sdk/plugins/BasePlugin.js +11 -4
- package/dist/cjs/sdk/pools/PoolService.js +12 -104
- package/dist/cjs/sdk/utils/formatter.js +99 -20
- package/dist/cjs/sdk/utils/viem/index.js +3 -3
- package/dist/cjs/sdk/utils/viem/watchBlocksAsync.js +76 -0
- package/dist/esm/dev/AccountOpener.js +6 -47
- package/dist/esm/dev/RevolverTransport.js +10 -4
- package/dist/esm/dev/index.js +0 -1
- package/dist/esm/dev/logSplitterTransport.js +10 -1
- package/dist/esm/permissionless/utils/create2.js +1 -1
- package/dist/esm/permissionless/utils/price-update/get-price-feeds.js +12 -6
- package/dist/esm/permissionless/utils/price-update/get-price-update-tx.js +13 -7
- package/dist/esm/permissionless/utils/price-update/get-prices.js +13 -7
- package/dist/esm/sdk/MultichainSDK.js +217 -0
- package/dist/esm/sdk/OnchainSDK.js +472 -0
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +17 -328
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +1 -7
- package/dist/esm/sdk/base/TokensMeta.js +44 -22
- package/dist/esm/sdk/base/token-types.js +0 -6
- package/dist/esm/sdk/chain/chains.js +1 -2
- package/dist/esm/sdk/constants/address-provider.js +0 -2
- package/dist/esm/sdk/core/errors.js +48 -0
- package/dist/esm/sdk/core/index.js +1 -0
- package/dist/esm/sdk/index.js +2 -1
- package/dist/esm/sdk/market/MarketRegister.js +118 -74
- package/dist/esm/sdk/market/MarketSuite.js +0 -3
- package/dist/esm/sdk/market/index.js +0 -1
- package/dist/esm/sdk/market/pool/PoolSuite.js +0 -3
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +2 -11
- package/dist/esm/sdk/market/pool/index.js +0 -1
- package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +10 -3
- package/dist/esm/sdk/market/pricefeeds/updates/PythAccumulatorUpdateData.js +20 -13
- package/dist/esm/sdk/market/pricefeeds/updates/PythUpdater.js +7 -4
- package/dist/esm/sdk/market/pricefeeds/updates/RedstoneUpdater.js +4 -4
- package/dist/esm/sdk/market/pricefeeds/updates/fetchPythPayloads.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/updates/index.js +2 -0
- package/dist/esm/sdk/options.js +22 -51
- package/dist/esm/sdk/plugins/BasePlugin.js +11 -4
- package/dist/esm/sdk/pools/PoolService.js +13 -109
- package/dist/esm/sdk/utils/formatter.js +99 -10
- package/dist/esm/sdk/utils/viem/index.js +1 -1
- package/dist/esm/sdk/utils/viem/watchBlocksAsync.js +52 -0
- package/dist/types/dev/RevolverTransport.d.ts +2 -1
- package/dist/types/dev/calcLiquidatableLTs.d.ts +2 -2
- package/dist/types/dev/claimFromFaucet.d.ts +2 -2
- package/dist/types/dev/create2.d.ts +3 -4
- package/dist/types/dev/index.d.ts +0 -1
- package/dist/types/dev/logSplitterTransport.d.ts +3 -1
- package/dist/types/dev/migrateFaucet.d.ts +2 -2
- package/dist/types/dev/mint/AbstractMinter.d.ts +2 -2
- package/dist/types/dev/mint/FallbackMinter.d.ts +2 -2
- package/dist/types/dev/mint/factory.d.ts +2 -2
- package/dist/types/dev/replaceStorage.d.ts +1 -1
- package/dist/types/permissionless/utils/price-update/get-updatable-feeds.d.ts +2 -2
- package/dist/types/plugins/accounts/AccountsPlugin.d.ts +2 -2
- package/dist/types/plugins/accounts-counter/AccountsCounterPlugin.d.ts +2 -2
- package/dist/types/plugins/adapters/AdaptersPlugin.d.ts +2 -2
- package/dist/types/plugins/apy/ApyPlugin.d.ts +2 -2
- package/dist/types/plugins/bots/BotsPlugin.d.ts +2 -2
- package/dist/types/plugins/bots/PartialLiquidationBotV310Contract.d.ts +2 -2
- package/dist/types/plugins/degen-distributors/DegenDistributorsPlugin.d.ts +2 -2
- package/dist/types/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.d.ts +2 -2
- package/dist/types/sdk/MultichainSDK.d.ts +144 -0
- package/dist/types/sdk/OnchainSDK.d.ts +257 -0
- package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +4 -54
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
- package/dist/types/sdk/accounts/createCreditAccountService.d.ts +2 -2
- package/dist/types/sdk/accounts/types.d.ts +15 -95
- package/dist/types/sdk/base/SDKConstruct.d.ts +4 -4
- package/dist/types/sdk/base/TokensMeta.d.ts +3 -14
- package/dist/types/sdk/base/token-types.d.ts +4 -44
- package/dist/types/sdk/base/types.d.ts +2 -116
- package/dist/types/sdk/chain/chains.d.ts +1 -5
- package/dist/types/sdk/constants/address-provider.d.ts +0 -1
- package/dist/types/sdk/core/createAddressProvider.d.ts +3 -3
- package/dist/types/sdk/core/errors.d.ts +51 -0
- package/dist/types/sdk/core/index.d.ts +1 -0
- package/dist/types/sdk/index.d.ts +2 -1
- package/dist/types/sdk/market/MarketRegister.d.ts +11 -8
- package/dist/types/sdk/market/MarketSuite.d.ts +2 -4
- package/dist/types/sdk/market/adapters/createAdapter.d.ts +2 -2
- package/dist/types/sdk/market/credit/CreditConfiguratorV310Contract.d.ts +3 -3
- package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +2 -2
- package/dist/types/sdk/market/credit/CreditSuite.d.ts +2 -2
- package/dist/types/sdk/market/credit/createCreditConfigurator.d.ts +2 -2
- package/dist/types/sdk/market/credit/createCreditFacade.d.ts +2 -2
- package/dist/types/sdk/market/credit/createCreditManager.d.ts +2 -2
- package/dist/types/sdk/market/credit/types.d.ts +1 -1
- package/dist/types/sdk/market/index.d.ts +0 -1
- package/dist/types/sdk/market/loss-policy/AliasLossPolicyV310Contract.d.ts +3 -3
- package/dist/types/sdk/market/loss-policy/createLossPolicy.d.ts +2 -2
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +5 -6
- package/dist/types/sdk/market/oracle/PriceOracleV310Contract.d.ts +2 -2
- package/dist/types/sdk/market/oracle/createPriceOracle.d.ts +2 -2
- package/dist/types/sdk/market/oracle/types.d.ts +10 -3
- package/dist/types/sdk/market/pool/PoolSuite.d.ts +2 -4
- package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +2 -6
- package/dist/types/sdk/market/pool/createInterestRateModel.d.ts +2 -2
- package/dist/types/sdk/market/pool/createPool.d.ts +2 -2
- package/dist/types/sdk/market/pool/createPoolQuotaKeeper.d.ts +2 -2
- package/dist/types/sdk/market/pool/createRateKeeper.d.ts +2 -2
- package/dist/types/sdk/market/pool/index.d.ts +0 -1
- package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +8 -3
- package/dist/types/sdk/market/pricefeeds/updates/PythAccumulatorUpdateData.d.ts +12 -13
- package/dist/types/sdk/market/pricefeeds/updates/PythUpdater.d.ts +8 -3
- package/dist/types/sdk/market/pricefeeds/updates/RedstoneUpdater.d.ts +8 -3
- package/dist/types/sdk/market/pricefeeds/updates/index.d.ts +1 -0
- package/dist/types/sdk/market/pricefeeds/updates/types.d.ts +4 -0
- package/dist/types/sdk/market/types.d.ts +1 -1
- package/dist/types/sdk/options.d.ts +15 -16
- package/dist/types/sdk/plugins/BasePlugin.d.ts +12 -6
- package/dist/types/sdk/plugins/errors.d.ts +2 -2
- package/dist/types/sdk/plugins/types.d.ts +16 -6
- package/dist/types/sdk/pools/PoolService.d.ts +8 -8
- package/dist/types/sdk/pools/types.d.ts +2 -3
- package/dist/types/sdk/router/AbstractRouterContract.d.ts +3 -3
- package/dist/types/sdk/router/RouterV310Contract.d.ts +2 -2
- package/dist/types/sdk/router/createRouter.d.ts +2 -2
- package/dist/types/sdk/router/helpers.d.ts +1 -1
- package/dist/types/sdk/types/state-human.d.ts +10 -2
- package/dist/types/sdk/types/state.d.ts +14 -8
- package/dist/types/sdk/utils/filterDust.d.ts +2 -2
- package/dist/types/sdk/utils/formatter.d.ts +1 -1
- package/dist/types/sdk/utils/isDust.d.ts +2 -2
- package/dist/types/sdk/utils/toAddress.d.ts +1 -1
- package/dist/types/sdk/utils/viem/getLogsPaginated.d.ts +1 -2
- package/dist/types/sdk/utils/viem/getLogsSafe.d.ts +1 -1
- package/dist/types/sdk/utils/viem/index.d.ts +1 -1
- package/dist/types/sdk/utils/viem/simulateWithPriceUpdates.d.ts +1 -2
- package/dist/types/sdk/utils/viem/watchBlocksAsync.d.ts +74 -0
- package/package.json +3 -6
- package/dist/cjs/abi/kyc/iDSRegistryService.js +0 -70
- package/dist/cjs/abi/kyc/iDSToken.js +0 -71
- package/dist/cjs/abi/kyc/iKYCCompressor.js +0 -196
- package/dist/cjs/abi/kyc/iKYCFactory.js +0 -122
- package/dist/cjs/abi/kyc/iKYCUnderlying.js +0 -401
- package/dist/cjs/abi/kyc/iSecuritizeDegenNFT.js +0 -326
- package/dist/cjs/abi/kyc/iSecuritizeKYCFactory.js +0 -319
- package/dist/cjs/dev/CachedStateSubscriber.js +0 -78
- package/dist/cjs/sdk/GearboxSDK.js +0 -696
- package/dist/cjs/sdk/market/kyc/KYCRegistry.js +0 -269
- package/dist/cjs/sdk/market/kyc/index.js +0 -26
- package/dist/cjs/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +0 -244
- package/dist/cjs/sdk/market/kyc/securitize/constants.js +0 -28
- package/dist/cjs/sdk/market/kyc/securitize/index.js +0 -26
- package/dist/cjs/sdk/market/kyc/securitize/types.js +0 -16
- package/dist/cjs/sdk/market/kyc/types.js +0 -34
- package/dist/cjs/sdk/utils/viem/executeDelegatedMulticalls.js +0 -38
- package/dist/esm/abi/kyc/iDSRegistryService.js +0 -46
- package/dist/esm/abi/kyc/iDSToken.js +0 -47
- package/dist/esm/abi/kyc/iKYCCompressor.js +0 -172
- package/dist/esm/abi/kyc/iKYCFactory.js +0 -98
- package/dist/esm/abi/kyc/iKYCUnderlying.js +0 -377
- package/dist/esm/abi/kyc/iSecuritizeDegenNFT.js +0 -302
- package/dist/esm/abi/kyc/iSecuritizeKYCFactory.js +0 -295
- package/dist/esm/dev/CachedStateSubscriber.js +0 -54
- package/dist/esm/sdk/GearboxSDK.js +0 -689
- package/dist/esm/sdk/market/kyc/KYCRegistry.js +0 -253
- package/dist/esm/sdk/market/kyc/index.js +0 -3
- package/dist/esm/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +0 -220
- package/dist/esm/sdk/market/kyc/securitize/constants.js +0 -4
- package/dist/esm/sdk/market/kyc/securitize/index.js +0 -3
- package/dist/esm/sdk/market/kyc/securitize/types.js +0 -0
- package/dist/esm/sdk/market/kyc/types.js +0 -9
- package/dist/esm/sdk/utils/viem/executeDelegatedMulticalls.js +0 -14
- package/dist/types/abi/kyc/iDSRegistryService.d.ts +0 -71
- package/dist/types/abi/kyc/iDSToken.d.ts +0 -67
- package/dist/types/abi/kyc/iKYCCompressor.d.ts +0 -228
- package/dist/types/abi/kyc/iKYCFactory.d.ts +0 -139
- package/dist/types/abi/kyc/iKYCUnderlying.d.ts +0 -548
- package/dist/types/abi/kyc/iSecuritizeDegenNFT.d.ts +0 -404
- package/dist/types/abi/kyc/iSecuritizeKYCFactory.d.ts +0 -376
- package/dist/types/dev/CachedStateSubscriber.d.ts +0 -21
- package/dist/types/sdk/GearboxSDK.d.ts +0 -324
- package/dist/types/sdk/market/kyc/KYCRegistry.d.ts +0 -52
- package/dist/types/sdk/market/kyc/index.d.ts +0 -3
- package/dist/types/sdk/market/kyc/securitize/SecuritizeKYCFactory.d.ts +0 -428
- package/dist/types/sdk/market/kyc/securitize/constants.d.ts +0 -1
- package/dist/types/sdk/market/kyc/securitize/index.d.ts +0 -3
- package/dist/types/sdk/market/kyc/securitize/types.d.ts +0 -127
- package/dist/types/sdk/market/kyc/types.d.ts +0 -170
- package/dist/types/sdk/utils/viem/executeDelegatedMulticalls.d.ts +0 -28
package/dist/cjs/sdk/options.js
CHANGED
|
@@ -18,65 +18,20 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var options_exports = {};
|
|
20
20
|
__export(options_exports, {
|
|
21
|
-
|
|
21
|
+
AttachOptionsSchema: () => AttachOptionsSchema,
|
|
22
|
+
OnchainSDKOptionsSchema: () => OnchainSDKOptionsSchema
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(options_exports);
|
|
24
25
|
var import_v4 = require("zod/v4");
|
|
25
26
|
var import_updates = require("./market/pricefeeds/updates/index.js");
|
|
26
27
|
var import_utils = require("./utils/index.js");
|
|
27
|
-
const
|
|
28
|
-
/**
|
|
29
|
-
* Override address of the Gearbox AddressProvider contract.
|
|
30
|
-
* If not set, uses default universal address provider address {@link ADDRESS_PROVIDER_V310}
|
|
31
|
-
**/
|
|
32
|
-
addressProvider: (0, import_utils.ZodAddress)().optional(),
|
|
33
|
-
/**
|
|
34
|
-
* Addresses of market configurator contracts to load.
|
|
35
|
-
* If not set, all default market configurators for the chain are loaded
|
|
36
|
-
* (from {@link GearboxChain.defaultMarketConfigurators})
|
|
37
|
-
**/
|
|
38
|
-
marketConfigurators: import_v4.z.array((0, import_utils.ZodAddress)()).optional(),
|
|
39
|
-
/**
|
|
40
|
-
* Addresses of KYC factory contracts to load.
|
|
41
|
-
* If not set, all default KYC factories for the chain are loaded
|
|
42
|
-
* (from {@link GearboxChain.kycFactories})
|
|
43
|
-
**/
|
|
44
|
-
kycFactories: import_v4.z.array((0, import_utils.ZodAddress)()).optional(),
|
|
45
|
-
/**
|
|
46
|
-
* Pin SDK to a specific block number during attach.
|
|
47
|
-
* When set, all on-chain reads use this block instead of `latest`.
|
|
48
|
-
**/
|
|
49
|
-
blockNumber: import_v4.z.union([import_v4.z.bigint().nonnegative(), import_v4.z.number().int().nonnegative()]).optional(),
|
|
50
|
-
/**
|
|
51
|
-
* Skip fetching updatable price feeds on attach and sync.
|
|
52
|
-
* Speeds up initialisation when prices are not needed.
|
|
53
|
-
**/
|
|
54
|
-
ignoreUpdateablePrices: import_v4.z.boolean().optional(),
|
|
55
|
-
/**
|
|
56
|
-
* Pool addresses whose markets should be skipped during attach/hydrate/sync.
|
|
57
|
-
**/
|
|
58
|
-
ignoreMarkets: import_v4.z.array((0, import_utils.ZodAddress)()).optional(),
|
|
59
|
-
/**
|
|
60
|
-
* When `true`, throw on unrecognised contract types instead of falling
|
|
61
|
-
* back to a generic contract wrapper.
|
|
62
|
-
**/
|
|
28
|
+
const OnchainSDKOptionsSchema = import_v4.z.object({
|
|
29
|
+
/** When `true`, throw on unrecognised contract types. */
|
|
63
30
|
strictContractTypes: import_v4.z.boolean().optional(),
|
|
64
|
-
/**
|
|
65
|
-
* Plugins that extend SDK functionality.
|
|
66
|
-
**/
|
|
31
|
+
/** Plugins that extend SDK functionality. */
|
|
67
32
|
plugins: import_v4.z.record(import_v4.z.string(), import_v4.z.any()).optional(),
|
|
68
|
-
/**
|
|
69
|
-
* Custom logger implementation.
|
|
70
|
-
**/
|
|
33
|
+
/** Custom logger implementation. */
|
|
71
34
|
logger: import_v4.z.any(),
|
|
72
|
-
/**
|
|
73
|
-
* Options for Redstone price-feed updates.
|
|
74
|
-
**/
|
|
75
|
-
redstone: import_updates.RedstoneOptions.optional(),
|
|
76
|
-
/**
|
|
77
|
-
* Options for Pyth price-feed updates.
|
|
78
|
-
**/
|
|
79
|
-
pyth: import_updates.PythOptions.optional(),
|
|
80
35
|
/**
|
|
81
36
|
* Explicit gas limit for read-only `eth_call` requests.
|
|
82
37
|
* `null` disables the gas limit entirely; `undefined` uses the SDK default.
|
|
@@ -84,7 +39,24 @@ const SDKOptions = import_v4.z.object({
|
|
|
84
39
|
**/
|
|
85
40
|
gasLimit: import_v4.z.bigint().nonnegative().nullable().optional()
|
|
86
41
|
});
|
|
42
|
+
const AttachOptionsSchema = import_v4.z.object({
|
|
43
|
+
/** Override address of the Gearbox AddressProvider contract. */
|
|
44
|
+
addressProvider: (0, import_utils.ZodAddress)().optional(),
|
|
45
|
+
/** Addresses of market configurator contracts to load. */
|
|
46
|
+
marketConfigurators: import_v4.z.array((0, import_utils.ZodAddress)()).optional(),
|
|
47
|
+
/** Pin SDK to a specific block number during attach. */
|
|
48
|
+
blockNumber: import_v4.z.union([import_v4.z.bigint().nonnegative(), import_v4.z.number().int().nonnegative()]).optional(),
|
|
49
|
+
/** Skip fetching updatable price feeds on attach and sync. */
|
|
50
|
+
ignoreUpdateablePrices: import_v4.z.boolean().optional(),
|
|
51
|
+
/** Pool addresses whose markets should be skipped. */
|
|
52
|
+
ignoreMarkets: import_v4.z.array((0, import_utils.ZodAddress)()).optional(),
|
|
53
|
+
/** Options for Redstone price-feed updates. */
|
|
54
|
+
redstone: import_updates.RedstoneOptions.optional(),
|
|
55
|
+
/** Options for Pyth price-feed updates. */
|
|
56
|
+
pyth: import_updates.PythOptions.optional()
|
|
57
|
+
});
|
|
87
58
|
// Annotate the CommonJS export names for ESM import in node:
|
|
88
59
|
0 && (module.exports = {
|
|
89
|
-
|
|
60
|
+
AttachOptionsSchema,
|
|
61
|
+
OnchainSDKOptionsSchema
|
|
90
62
|
});
|
|
@@ -21,6 +21,7 @@ __export(BasePlugin_exports, {
|
|
|
21
21
|
BasePlugin: () => BasePlugin
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(BasePlugin_exports);
|
|
24
|
+
var import_core = require("../core/index.js");
|
|
24
25
|
class BasePlugin {
|
|
25
26
|
#sdk;
|
|
26
27
|
logger;
|
|
@@ -43,19 +44,25 @@ class BasePlugin {
|
|
|
43
44
|
**/
|
|
44
45
|
get sdk() {
|
|
45
46
|
if (!this.#sdk) {
|
|
46
|
-
throw new
|
|
47
|
+
throw new import_core.SdkNotAttachedError();
|
|
47
48
|
}
|
|
48
49
|
return this.#sdk;
|
|
49
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* @internal
|
|
53
|
+
* Set the SDK instance. Called by the SDK constructor.
|
|
54
|
+
* @param sdk - The SDK instance.
|
|
55
|
+
* @throws Error if the SDK is already attached.
|
|
56
|
+
*/
|
|
50
57
|
set sdk(sdk) {
|
|
51
58
|
if (this.#sdk) {
|
|
52
|
-
throw new
|
|
59
|
+
throw new import_core.SdkAlreadyAttachedError();
|
|
53
60
|
}
|
|
54
61
|
this.#sdk = sdk;
|
|
55
62
|
this.logger = sdk.logger?.child?.({ name: this.constructor.name }) ?? sdk.logger;
|
|
56
63
|
}
|
|
57
64
|
/**
|
|
58
|
-
* {@inheritDoc
|
|
65
|
+
* {@inheritDoc IOnchainSDKPlugin.attach}
|
|
59
66
|
**/
|
|
60
67
|
async attach() {
|
|
61
68
|
if (this.loadOnAttach) {
|
|
@@ -63,7 +70,7 @@ class BasePlugin {
|
|
|
63
70
|
}
|
|
64
71
|
}
|
|
65
72
|
/**
|
|
66
|
-
* {@inheritDoc
|
|
73
|
+
* {@inheritDoc IOnchainSDKPlugin.syncState}
|
|
67
74
|
**/
|
|
68
75
|
async syncState() {
|
|
69
76
|
await this.load(false);
|
|
@@ -22,7 +22,6 @@ __export(PoolService_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(PoolService_exports);
|
|
24
24
|
var import_generated = require("../../abi/310/generated.js");
|
|
25
|
-
var import_iERC20 = require("../../abi/iERC20.js");
|
|
26
25
|
var import_iERC20ZapperDeposits = require("../../abi/iERC20ZapperDeposits.js");
|
|
27
26
|
var import_iETHZapperDeposits = require("../../abi/iETHZapperDeposits.js");
|
|
28
27
|
var import_iZapper = require("../../abi/iZapper.js");
|
|
@@ -31,73 +30,28 @@ var import_constants = require("../constants/index.js");
|
|
|
31
30
|
var import_utils = require("../utils/index.js");
|
|
32
31
|
class PoolService extends import_base.SDKConstruct {
|
|
33
32
|
/**
|
|
34
|
-
*
|
|
33
|
+
* @inheritdoc IPoolsService.getDepositTokensIn
|
|
35
34
|
*/
|
|
36
35
|
getDepositTokensIn(pool) {
|
|
37
|
-
const underlying = this.#describeUnderlying(pool);
|
|
38
|
-
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
39
|
-
switch (underlying.contractType) {
|
|
40
|
-
case import_base.KYC_UNDERLYING_DEFAULT:
|
|
41
|
-
return this.#depositTokensIn(pool, false);
|
|
42
|
-
case import_base.KYC_UNDERLYING_ON_DEMAND:
|
|
43
|
-
return [underlying.asset];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
36
|
return this.#depositTokensIn(pool, true);
|
|
47
37
|
}
|
|
48
38
|
/**
|
|
49
|
-
*
|
|
39
|
+
* @inheritdoc IPoolsService.getDepositTokensOut
|
|
50
40
|
*/
|
|
51
41
|
getDepositTokensOut(pool, tokenIn) {
|
|
52
|
-
const underlying = this.#describeUnderlying(pool);
|
|
53
|
-
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
54
|
-
switch (underlying.contractType) {
|
|
55
|
-
case import_base.KYC_UNDERLYING_DEFAULT:
|
|
56
|
-
return this.#depositTokensOut(pool, tokenIn, false);
|
|
57
|
-
case import_base.KYC_UNDERLYING_ON_DEMAND:
|
|
58
|
-
return [];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
42
|
return this.#depositTokensOut(pool, tokenIn, true);
|
|
62
43
|
}
|
|
63
44
|
/**
|
|
64
|
-
*
|
|
45
|
+
* @inheritdoc IPoolsService.getDepositMetadata
|
|
65
46
|
*/
|
|
66
47
|
getDepositMetadata(pool, tokenIn, tokenOut) {
|
|
67
|
-
const underlying = this.#describeUnderlying(pool);
|
|
68
|
-
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
69
|
-
switch (underlying.contractType) {
|
|
70
|
-
case import_base.KYC_UNDERLYING_DEFAULT: {
|
|
71
|
-
return this.#depositMetadata(
|
|
72
|
-
"kyc-default",
|
|
73
|
-
pool,
|
|
74
|
-
tokenIn,
|
|
75
|
-
tokenOut,
|
|
76
|
-
false
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
case import_base.KYC_UNDERLYING_ON_DEMAND:
|
|
80
|
-
return {
|
|
81
|
-
zapper: void 0,
|
|
82
|
-
approveTarget: underlying.liquidityProvider.addr,
|
|
83
|
-
permissible: false,
|
|
84
|
-
type: "kyc-on-demand"
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
48
|
return this.#depositMetadata("classic", pool, tokenIn, tokenOut, true);
|
|
89
49
|
}
|
|
90
50
|
/**
|
|
91
|
-
*
|
|
51
|
+
* @inheritdoc IPoolsService.addLiquidity
|
|
92
52
|
*/
|
|
93
53
|
addLiquidity(props) {
|
|
94
54
|
const { collateral, meta, permit, referralCode, pool, wallet } = props;
|
|
95
|
-
const underlying = this.#describeUnderlying(pool);
|
|
96
|
-
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
97
|
-
if (underlying.contractType === import_base.KYC_UNDERLYING_ON_DEMAND) {
|
|
98
|
-
return void 0;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
55
|
const { zapper } = meta;
|
|
102
56
|
if (zapper && (0, import_utils.hexEq)(zapper.tokenIn.addr, import_constants.NATIVE_ADDRESS)) {
|
|
103
57
|
return {
|
|
@@ -137,51 +91,22 @@ class PoolService extends import_base.SDKConstruct {
|
|
|
137
91
|
}
|
|
138
92
|
}
|
|
139
93
|
/**
|
|
140
|
-
*
|
|
94
|
+
* @inheritdoc IPoolsService.getWithdrawalTokensIn
|
|
141
95
|
*/
|
|
142
96
|
getWithdrawalTokensIn(pool) {
|
|
143
|
-
const underlying = this.#describeUnderlying(pool);
|
|
144
|
-
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
145
|
-
switch (underlying.contractType) {
|
|
146
|
-
case import_base.KYC_UNDERLYING_DEFAULT:
|
|
147
|
-
return this.#withdrawalTokensIn(pool, false);
|
|
148
|
-
case import_base.KYC_UNDERLYING_ON_DEMAND:
|
|
149
|
-
return [];
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
97
|
return this.#withdrawalTokensIn(pool, true);
|
|
153
98
|
}
|
|
154
99
|
/**
|
|
155
|
-
*
|
|
100
|
+
* @inheritdoc IPoolsService.getWithdrawalTokensOut
|
|
156
101
|
*/
|
|
157
102
|
getWithdrawalTokensOut(pool, tokenIn) {
|
|
158
|
-
const underlying = this.#describeUnderlying(pool);
|
|
159
|
-
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
160
|
-
switch (underlying.contractType) {
|
|
161
|
-
case import_base.KYC_UNDERLYING_DEFAULT:
|
|
162
|
-
return this.#withdrawalTokensOut(pool, tokenIn, false);
|
|
163
|
-
case import_base.KYC_UNDERLYING_ON_DEMAND:
|
|
164
|
-
return [underlying.asset];
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
103
|
return this.#withdrawalTokensOut(pool, tokenIn, true);
|
|
168
104
|
}
|
|
169
105
|
/**
|
|
170
|
-
*
|
|
106
|
+
* @inheritdoc IPoolsService.removeLiquidity
|
|
171
107
|
*/
|
|
172
108
|
removeLiquidity(props) {
|
|
173
109
|
const { pool, amount, meta, wallet, permit } = props;
|
|
174
|
-
const underlying = this.#describeUnderlying(pool);
|
|
175
|
-
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
176
|
-
if (underlying.contractType === import_base.KYC_UNDERLYING_ON_DEMAND) {
|
|
177
|
-
return {
|
|
178
|
-
abi: import_iERC20.ierc20Abi,
|
|
179
|
-
functionName: "approve",
|
|
180
|
-
args: [underlying.liquidityProvider, 0n],
|
|
181
|
-
target: underlying.asset
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
110
|
if (meta.zapper) {
|
|
186
111
|
return permit ? {
|
|
187
112
|
target: meta.zapper.baseParams.addr,
|
|
@@ -210,30 +135,9 @@ class PoolService extends import_base.SDKConstruct {
|
|
|
210
135
|
};
|
|
211
136
|
}
|
|
212
137
|
/**
|
|
213
|
-
*
|
|
138
|
+
* @inheritdoc IPoolsService.getWithdrawalMetadata
|
|
214
139
|
*/
|
|
215
140
|
getWithdrawalMetadata(pool, tokenIn, tokenOut) {
|
|
216
|
-
const underlying = this.#describeUnderlying(pool);
|
|
217
|
-
if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
|
|
218
|
-
switch (underlying.contractType) {
|
|
219
|
-
case import_base.KYC_UNDERLYING_DEFAULT: {
|
|
220
|
-
return this.#withdrawalMetadata(
|
|
221
|
-
"kyc-default",
|
|
222
|
-
pool,
|
|
223
|
-
tokenIn,
|
|
224
|
-
tokenOut,
|
|
225
|
-
false
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
case import_base.KYC_UNDERLYING_ON_DEMAND:
|
|
229
|
-
return {
|
|
230
|
-
zapper: void 0,
|
|
231
|
-
approveTarget: void 0,
|
|
232
|
-
permissible: false,
|
|
233
|
-
type: "kyc-on-demand"
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
141
|
return this.#withdrawalMetadata("classic", pool, tokenIn, tokenOut, true);
|
|
238
142
|
}
|
|
239
143
|
/**
|
|
@@ -393,6 +297,8 @@ class PoolService extends import_base.SDKConstruct {
|
|
|
393
297
|
zapper,
|
|
394
298
|
// Approval target is zapper when routed, otherwise the pool contract.
|
|
395
299
|
approveTarget: zapper?.baseParams.addr ?? pool.pool.address,
|
|
300
|
+
// TODO: instead of permissible, return permitType depending on tokenIn
|
|
301
|
+
// "none" | "eip2612" | "dai_like";
|
|
396
302
|
permissible: !!zapper && !(0, import_utils.hexEq)(tokenIn, import_constants.NATIVE_ADDRESS),
|
|
397
303
|
type
|
|
398
304
|
};
|
|
@@ -420,6 +326,8 @@ class PoolService extends import_base.SDKConstruct {
|
|
|
420
326
|
zapper,
|
|
421
327
|
// Approval target exists only for zapper-based withdrawals.
|
|
422
328
|
approveTarget: zapper?.baseParams.addr,
|
|
329
|
+
// TODO: instead of permissible, return permitType depending on tokenIn
|
|
330
|
+
// "none" | "eip2612" | "dai_like";
|
|
423
331
|
permissible: !!zapper,
|
|
424
332
|
type
|
|
425
333
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
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
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var formatter_exports = {};
|
|
30
20
|
__export(formatter_exports, {
|
|
@@ -47,7 +37,6 @@ __export(formatter_exports, {
|
|
|
47
37
|
});
|
|
48
38
|
module.exports = __toCommonJS(formatter_exports);
|
|
49
39
|
var import_date_fns = require("date-fns");
|
|
50
|
-
var import_decimal = __toESM(require("decimal.js-light"));
|
|
51
40
|
var import_constants = require("../constants/index.js");
|
|
52
41
|
const toBigInt = (v) => {
|
|
53
42
|
const value = typeof v === "object" && v.type === "BigNumber" ? v.hex : v.toString();
|
|
@@ -151,17 +140,22 @@ function formatTimestamp(timestamp, raw = true) {
|
|
|
151
140
|
function rayToNumber(num) {
|
|
152
141
|
return Number(toBigInt(num) / 10n ** 21n) / 1e6;
|
|
153
142
|
}
|
|
154
|
-
function toSignificant(num, decimals, precision = 6) {
|
|
155
|
-
if (num === 1n) return "0";
|
|
156
|
-
const divider = new import_decimal.default(10).toPower(decimals);
|
|
157
|
-
const number = new import_decimal.default(num.toString()).div(divider);
|
|
158
|
-
return number.toSignificantDigits(precision, 4).toString();
|
|
159
|
-
}
|
|
160
143
|
function toBN(num, decimals) {
|
|
161
144
|
if (num === "") return 0n;
|
|
162
|
-
const
|
|
163
|
-
const
|
|
164
|
-
|
|
145
|
+
const negative = num.startsWith("-");
|
|
146
|
+
const abs = negative ? num.slice(1) : num;
|
|
147
|
+
const [intPart = "0", fracPart = ""] = abs.split(".");
|
|
148
|
+
let frac = fracPart;
|
|
149
|
+
let roundUp = false;
|
|
150
|
+
if (frac.length > decimals) {
|
|
151
|
+
roundUp = frac.charCodeAt(decimals) >= 53;
|
|
152
|
+
frac = frac.slice(0, decimals);
|
|
153
|
+
} else {
|
|
154
|
+
frac = frac.padEnd(decimals, "0");
|
|
155
|
+
}
|
|
156
|
+
let result = BigInt(intPart + frac);
|
|
157
|
+
if (roundUp) result += 1n;
|
|
158
|
+
return negative ? -result : result;
|
|
165
159
|
}
|
|
166
160
|
function shortAddress(address) {
|
|
167
161
|
return address === void 0 ? "" : `${address.slice(0, 6)}...${address.slice(address.length - 4)}`;
|
|
@@ -175,6 +169,91 @@ function formatPercentage(healthFactor, decimals = 2) {
|
|
|
175
169
|
function formatLeverage(leverage, decimals = 2) {
|
|
176
170
|
return (leverage / Number(import_constants.LEVERAGE_DECIMALS)).toFixed(decimals);
|
|
177
171
|
}
|
|
172
|
+
function formatDecimalJsLikeToString(digits, base10exp) {
|
|
173
|
+
const len = digits.length;
|
|
174
|
+
const isExp = base10exp <= -7 || base10exp >= 21;
|
|
175
|
+
if (isExp) {
|
|
176
|
+
let coeff = digits;
|
|
177
|
+
if (len > 1) {
|
|
178
|
+
coeff = `${digits[0]}.${digits.slice(1)}`;
|
|
179
|
+
}
|
|
180
|
+
const exp = base10exp;
|
|
181
|
+
const expStr = exp < 0 ? `e${exp}` : `e+${exp}`;
|
|
182
|
+
return `${coeff}${expStr}`;
|
|
183
|
+
}
|
|
184
|
+
if (base10exp < 0) {
|
|
185
|
+
return `0.${"0".repeat(-base10exp - 1)}${digits}`;
|
|
186
|
+
}
|
|
187
|
+
if (base10exp >= len) {
|
|
188
|
+
return `${digits}${"0".repeat(base10exp + 1 - len)}`;
|
|
189
|
+
}
|
|
190
|
+
const k = base10exp + 1;
|
|
191
|
+
if (k === len) return digits;
|
|
192
|
+
return `${digits.slice(0, k)}.${digits.slice(k)}`;
|
|
193
|
+
}
|
|
194
|
+
function roundToSignificantDigitsHalfUp(digits, base10exp, precision) {
|
|
195
|
+
if (precision < 1) {
|
|
196
|
+
throw new Error(`Invalid precision: ${precision}`);
|
|
197
|
+
}
|
|
198
|
+
if (digits === "0") return { digits: "0", base10exp: 0 };
|
|
199
|
+
let norm = digits;
|
|
200
|
+
while (norm.length > 1 && norm.endsWith("0")) {
|
|
201
|
+
norm = norm.slice(0, -1);
|
|
202
|
+
}
|
|
203
|
+
digits = norm;
|
|
204
|
+
if (digits.length <= precision) {
|
|
205
|
+
return { digits, base10exp };
|
|
206
|
+
}
|
|
207
|
+
const cut = digits.slice(0, precision).split("");
|
|
208
|
+
const next = digits.charCodeAt(precision) - 48;
|
|
209
|
+
if (next >= 5) {
|
|
210
|
+
let i = cut.length - 1;
|
|
211
|
+
while (i >= 0) {
|
|
212
|
+
const cur = cut[i];
|
|
213
|
+
if (cur === void 0) {
|
|
214
|
+
throw new Error("roundToSignificantDigitsHalfUp: invalid state");
|
|
215
|
+
}
|
|
216
|
+
const d = cur.charCodeAt(0) - 48;
|
|
217
|
+
if (d !== 9) {
|
|
218
|
+
cut[i] = String.fromCharCode(48 + d + 1);
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
cut[i] = "0";
|
|
222
|
+
i -= 1;
|
|
223
|
+
}
|
|
224
|
+
if (i < 0) {
|
|
225
|
+
cut.unshift("1");
|
|
226
|
+
base10exp += 1;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
let rounded = cut.join("");
|
|
230
|
+
let tz = 0;
|
|
231
|
+
for (let i = rounded.length - 1; i >= 0 && rounded[i] === "0"; i -= 1) {
|
|
232
|
+
tz += 1;
|
|
233
|
+
}
|
|
234
|
+
if (tz > 0) {
|
|
235
|
+
rounded = rounded.slice(0, -tz);
|
|
236
|
+
}
|
|
237
|
+
if (rounded === "") {
|
|
238
|
+
return { digits: "0", base10exp: 0 };
|
|
239
|
+
}
|
|
240
|
+
return { digits: rounded, base10exp };
|
|
241
|
+
}
|
|
242
|
+
function toSignificant(num, decimals, precision = 6) {
|
|
243
|
+
if (num === 1n) return "0";
|
|
244
|
+
if (num === 0n) return "0";
|
|
245
|
+
const negative = num < 0n;
|
|
246
|
+
const abs = negative ? -num : num;
|
|
247
|
+
const rawDigits = abs.toString();
|
|
248
|
+
const base10exp = rawDigits.length - decimals - 1;
|
|
249
|
+
const rounded = roundToSignificantDigitsHalfUp(
|
|
250
|
+
rawDigits,
|
|
251
|
+
base10exp,
|
|
252
|
+
precision
|
|
253
|
+
);
|
|
254
|
+
const body = formatDecimalJsLikeToString(rounded.digits, rounded.base10exp);
|
|
255
|
+
return negative ? `-${body}` : body;
|
|
256
|
+
}
|
|
178
257
|
// Annotate the CommonJS export names for ESM import in node:
|
|
179
258
|
0 && (module.exports = {
|
|
180
259
|
fmtBinaryMask,
|
|
@@ -16,19 +16,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var viem_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(viem_exports);
|
|
18
18
|
__reExport(viem_exports, require("./cast.js"), module.exports);
|
|
19
|
-
__reExport(viem_exports, require("./executeDelegatedMulticalls.js"), module.exports);
|
|
20
19
|
__reExport(viem_exports, require("./getLogsPaginated.js"), module.exports);
|
|
21
20
|
__reExport(viem_exports, require("./getLogsSafe.js"), module.exports);
|
|
22
21
|
__reExport(viem_exports, require("./sendRawTx.js"), module.exports);
|
|
23
22
|
__reExport(viem_exports, require("./simulateMulticall.js"), module.exports);
|
|
24
23
|
__reExport(viem_exports, require("./simulateWithPriceUpdates.js"), module.exports);
|
|
24
|
+
__reExport(viem_exports, require("./watchBlocksAsync.js"), module.exports);
|
|
25
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26
26
|
0 && (module.exports = {
|
|
27
27
|
...require("./cast.js"),
|
|
28
|
-
...require("./executeDelegatedMulticalls.js"),
|
|
29
28
|
...require("./getLogsPaginated.js"),
|
|
30
29
|
...require("./getLogsSafe.js"),
|
|
31
30
|
...require("./sendRawTx.js"),
|
|
32
31
|
...require("./simulateMulticall.js"),
|
|
33
|
-
...require("./simulateWithPriceUpdates.js")
|
|
32
|
+
...require("./simulateWithPriceUpdates.js"),
|
|
33
|
+
...require("./watchBlocksAsync.js")
|
|
34
34
|
});
|
|
@@ -0,0 +1,76 @@
|
|
|
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 watchBlocksAsync_exports = {};
|
|
20
|
+
__export(watchBlocksAsync_exports, {
|
|
21
|
+
watchBlocksAsync: () => watchBlocksAsync
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(watchBlocksAsync_exports);
|
|
24
|
+
var import_actions = require("viem/actions");
|
|
25
|
+
var import_utils = require("viem/utils");
|
|
26
|
+
function watchBlocksAsync(client, parameters) {
|
|
27
|
+
const {
|
|
28
|
+
onBlock,
|
|
29
|
+
onError,
|
|
30
|
+
onDrop,
|
|
31
|
+
pollingInterval = client.pollingInterval
|
|
32
|
+
} = parameters;
|
|
33
|
+
let active = true;
|
|
34
|
+
let busy = false;
|
|
35
|
+
let prevBlock;
|
|
36
|
+
const poll = async () => {
|
|
37
|
+
if (!active) return;
|
|
38
|
+
let block;
|
|
39
|
+
try {
|
|
40
|
+
block = await (0, import_utils.getAction)(
|
|
41
|
+
client,
|
|
42
|
+
import_actions.getBlock,
|
|
43
|
+
"getBlock"
|
|
44
|
+
)({});
|
|
45
|
+
} catch (err) {
|
|
46
|
+
onError?.(err);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!active) return;
|
|
50
|
+
if (block.number !== null && prevBlock?.number != null && block.number <= prevBlock.number) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (busy) {
|
|
54
|
+
onDrop?.(block);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
busy = true;
|
|
58
|
+
try {
|
|
59
|
+
await onBlock(block, prevBlock);
|
|
60
|
+
prevBlock = block;
|
|
61
|
+
} catch (err) {
|
|
62
|
+
onError?.(err);
|
|
63
|
+
} finally {
|
|
64
|
+
busy = false;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const timer = setInterval(poll, pollingInterval);
|
|
68
|
+
return () => {
|
|
69
|
+
active = false;
|
|
70
|
+
clearInterval(timer);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
watchBlocksAsync
|
|
76
|
+
});
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
parseEventLogs
|
|
7
7
|
} from "viem";
|
|
8
8
|
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
|
|
9
|
-
import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
|
|
9
|
+
import { iCreditFacadeV310Abi, iPoolV310Abi } from "../abi/310/generated.js";
|
|
10
10
|
import { ierc20Abi } from "../abi/iERC20.js";
|
|
11
11
|
import {
|
|
12
12
|
ADDRESS_0X0,
|
|
@@ -15,7 +15,6 @@ import {
|
|
|
15
15
|
childLogger,
|
|
16
16
|
MAX_UINT256,
|
|
17
17
|
PERCENTAGE_FACTOR,
|
|
18
|
-
PoolService,
|
|
19
18
|
SDKConstruct,
|
|
20
19
|
sendRawTx
|
|
21
20
|
} from "../sdk/index.js";
|
|
@@ -44,7 +43,6 @@ class AccountOpener extends SDKConstruct {
|
|
|
44
43
|
#minDebtMultiplier;
|
|
45
44
|
#allowMint;
|
|
46
45
|
#leverageDelta;
|
|
47
|
-
#poolService;
|
|
48
46
|
constructor(service, options_ = {}) {
|
|
49
47
|
super(service.sdk);
|
|
50
48
|
const {
|
|
@@ -70,7 +68,6 @@ class AccountOpener extends SDKConstruct {
|
|
|
70
68
|
this.#poolDepositMultiplier = BigInt(poolDepositMultiplier);
|
|
71
69
|
this.#minDebtMultiplier = BigInt(minDebtMultiplier);
|
|
72
70
|
this.#leverageDelta = BigInt(leverageDelta);
|
|
73
|
-
this.#poolService = new PoolService(service.sdk);
|
|
74
71
|
this.#logger?.info(
|
|
75
72
|
{
|
|
76
73
|
borrower: privateKeyToAccount(this.borrowerKey).address,
|
|
@@ -108,10 +105,6 @@ class AccountOpener extends SDKConstruct {
|
|
|
108
105
|
},
|
|
109
106
|
"opening credit accounts"
|
|
110
107
|
);
|
|
111
|
-
await Promise.all([
|
|
112
|
-
this.sdk.tokensMeta.loadTokenData(),
|
|
113
|
-
this.sdk.marketRegister.loadZappers()
|
|
114
|
-
]);
|
|
115
108
|
let deposits = [];
|
|
116
109
|
if (depositIntoPools) {
|
|
117
110
|
try {
|
|
@@ -463,34 +456,9 @@ class AccountOpener extends SDKConstruct {
|
|
|
463
456
|
this.#logger?.debug(
|
|
464
457
|
`depositor balance in underlying: ${this.sdk.tokensMeta.formatBN(pool.underlying, allowance, { symbol: true })}`
|
|
465
458
|
);
|
|
466
|
-
const tokensOut = this.#poolService.getDepositTokensOut(
|
|
467
|
-
address,
|
|
468
|
-
underlying
|
|
469
|
-
);
|
|
470
|
-
this.#logger?.debug(
|
|
471
|
-
{ tokensOut: tokensOut.map((t) => this.labelAddress(t)) },
|
|
472
|
-
"deposit tokens out"
|
|
473
|
-
);
|
|
474
|
-
if (tokensOut.length === 0) {
|
|
475
|
-
throw new Error(`no tokens out found for pool ${poolName}`);
|
|
476
|
-
}
|
|
477
|
-
const tokenOut = tokensOut[0];
|
|
478
|
-
const metadata = this.#poolService.getDepositMetadata(
|
|
479
|
-
address,
|
|
480
|
-
underlying,
|
|
481
|
-
tokenOut
|
|
482
|
-
);
|
|
483
|
-
this.logger?.debug(
|
|
484
|
-
{
|
|
485
|
-
underlying: this.labelAddress(underlying),
|
|
486
|
-
tokenOut: this.labelAddress(tokenOut),
|
|
487
|
-
...metadata
|
|
488
|
-
},
|
|
489
|
-
"pool deposit metadata"
|
|
490
|
-
);
|
|
491
459
|
txHash = await this.#anvil.writeContract({
|
|
492
460
|
account: depositor,
|
|
493
|
-
address:
|
|
461
|
+
address: underlying,
|
|
494
462
|
abi: ierc20Abi,
|
|
495
463
|
functionName: "approve",
|
|
496
464
|
args: [address, allowance],
|
|
@@ -507,21 +475,12 @@ class AccountOpener extends SDKConstruct {
|
|
|
507
475
|
this.#logger?.debug(
|
|
508
476
|
`depositor approved underlying for pool ${poolName}: ${txHash}`
|
|
509
477
|
);
|
|
510
|
-
const depositCall = this.#poolService.addLiquidity({
|
|
511
|
-
collateral: { token: underlying, balance: amount },
|
|
512
|
-
pool: address,
|
|
513
|
-
wallet: depositor.address,
|
|
514
|
-
meta: metadata
|
|
515
|
-
});
|
|
516
|
-
if (!depositCall) {
|
|
517
|
-
throw new Error(`no deposit call could be created for ${poolName}`);
|
|
518
|
-
}
|
|
519
478
|
txHash = await this.#anvil.writeContract({
|
|
520
479
|
account: depositor,
|
|
521
|
-
address
|
|
522
|
-
abi:
|
|
523
|
-
functionName:
|
|
524
|
-
args:
|
|
480
|
+
address,
|
|
481
|
+
abi: iPoolV310Abi,
|
|
482
|
+
functionName: "deposit",
|
|
483
|
+
args: [amount, depositor.address],
|
|
525
484
|
chain: this.#anvil.chain
|
|
526
485
|
});
|
|
527
486
|
receipt = await this.#anvil.waitForTransactionReceipt({ hash: txHash });
|