@gearbox-protocol/sdk 14.1.1 → 14.2.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.
Files changed (40) hide show
  1. package/dist/cjs/dev/claimDSToken.js +208 -0
  2. package/dist/cjs/plugins/accounts/AccountsPlugin.js +1 -2
  3. package/dist/cjs/sdk/OnchainSDK.js +12 -0
  4. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +1448 -23
  5. package/dist/cjs/sdk/accounts/index.js +0 -4
  6. package/dist/cjs/sdk/market/credit/CreditFacadeV310Contract.js +6 -0
  7. package/dist/cjs/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +19 -2
  8. package/dist/cjs/sdk/market/kyc/securitize/types.js +20 -0
  9. package/dist/cjs/sdk/market/oracle/PriceOracleV310Contract.js +26 -0
  10. package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -0
  11. package/dist/esm/dev/claimDSToken.js +187 -0
  12. package/dist/esm/plugins/accounts/AccountsPlugin.js +2 -7
  13. package/dist/esm/sdk/OnchainSDK.js +14 -0
  14. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +1466 -23
  15. package/dist/esm/sdk/accounts/index.js +0 -2
  16. package/dist/esm/sdk/accounts/multicall-utils.js +1 -5
  17. package/dist/esm/sdk/market/credit/CreditFacadeV310Contract.js +6 -0
  18. package/dist/esm/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +21 -2
  19. package/dist/esm/sdk/market/kyc/securitize/types.js +12 -0
  20. package/dist/esm/sdk/market/oracle/PriceOracleV310Contract.js +26 -0
  21. package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -0
  22. package/dist/types/dev/claimDSToken.d.ts +34 -0
  23. package/dist/types/sdk/OnchainSDK.d.ts +10 -0
  24. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +181 -3
  25. package/dist/types/sdk/accounts/index.d.ts +0 -2
  26. package/dist/types/sdk/accounts/types.d.ts +56 -0
  27. package/dist/types/sdk/market/credit/CreditFacadeV310Contract.d.ts +2 -0
  28. package/dist/types/sdk/market/kyc/securitize/SecuritizeKYCFactory.d.ts +1 -1
  29. package/dist/types/sdk/market/kyc/securitize/types.d.ts +37 -22
  30. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +5 -0
  31. package/dist/types/sdk/market/oracle/PriceOracleV310Contract.d.ts +4 -0
  32. package/dist/types/sdk/market/oracle/types.d.ts +9 -0
  33. package/dist/types/sdk/pools/types.d.ts +19 -0
  34. package/package.json +1 -1
  35. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +0 -1411
  36. package/dist/cjs/sdk/accounts/createCreditAccountService.js +0 -35
  37. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +0 -1405
  38. package/dist/esm/sdk/accounts/createCreditAccountService.js +0 -11
  39. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +0 -226
  40. package/dist/types/sdk/accounts/createCreditAccountService.d.ts +0 -9
@@ -0,0 +1,208 @@
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 claimDSToken_exports = {};
20
+ __export(claimDSToken_exports, {
21
+ claimDSToken: () => claimDSToken,
22
+ claimDSTokens: () => claimDSTokens,
23
+ registerInvestor: () => registerInvestor
24
+ });
25
+ module.exports = __toCommonJS(claimDSToken_exports);
26
+ var import_viem = require("viem");
27
+ var import_accounts = require("viem/accounts");
28
+ var import_iDSRegistryService = require("../abi/kyc/iDSRegistryService.js");
29
+ var import_iDSToken = require("../abi/kyc/iDSToken.js");
30
+ var import_sdk = require("../sdk/index.js");
31
+ async function writeAndWait(anvil, params) {
32
+ const hash = await anvil.writeContract(params);
33
+ await anvil.mine({ blocks: 1 });
34
+ await anvil.waitForTransactionReceipt({
35
+ hash,
36
+ pollingInterval: 100
37
+ });
38
+ return hash;
39
+ }
40
+ async function registerInvestor(props) {
41
+ const { claimer, anvil, token, adminPrivateKey, logger } = props;
42
+ const account = (0, import_accounts.privateKeyToAccount)(adminPrivateKey);
43
+ const registryServiceId = await anvil.readContract({
44
+ address: token,
45
+ abi: import_iDSToken.iDSTokenAbi,
46
+ functionName: "REGISTRY_SERVICE"
47
+ });
48
+ const registryService = await anvil.readContract({
49
+ address: token,
50
+ abi: import_iDSToken.iDSTokenAbi,
51
+ functionName: "getDSService",
52
+ args: [registryServiceId]
53
+ });
54
+ logger?.debug(`Registry service: ${registryService} (${registryServiceId})`);
55
+ const [isRegistered, ACCREDITED, APPROVED] = await anvil.multicall({
56
+ contracts: [
57
+ {
58
+ address: registryService,
59
+ abi: import_iDSRegistryService.iDSRegistryServiceAbi,
60
+ functionName: "isWallet",
61
+ args: [claimer]
62
+ },
63
+ {
64
+ address: registryService,
65
+ abi: import_iDSRegistryService.iDSRegistryServiceAbi,
66
+ functionName: "ACCREDITED",
67
+ args: []
68
+ },
69
+ {
70
+ address: registryService,
71
+ abi: import_iDSRegistryService.iDSRegistryServiceAbi,
72
+ functionName: "APPROVED",
73
+ args: []
74
+ }
75
+ ],
76
+ allowFailure: false
77
+ });
78
+ if (!isRegistered) {
79
+ logger?.debug(
80
+ `Claimer ${claimer} is not a registered wallet, registering...`
81
+ );
82
+ const investorId = `investor-${claimer.toLowerCase()}`;
83
+ const investorExists = await anvil.readContract({
84
+ address: registryService,
85
+ abi: import_iDSRegistryService.iDSRegistryServiceAbi,
86
+ functionName: "isInvestor",
87
+ args: [investorId]
88
+ });
89
+ if (!investorExists) {
90
+ await writeAndWait(anvil, {
91
+ account,
92
+ chain: anvil.chain,
93
+ address: registryService,
94
+ abi: import_iDSRegistryService.iDSRegistryServiceAbi,
95
+ functionName: "registerInvestor",
96
+ args: [investorId, investorId]
97
+ });
98
+ logger?.debug(`Registered investor "${investorId}"`);
99
+ }
100
+ await writeAndWait(anvil, {
101
+ account,
102
+ chain: anvil.chain,
103
+ address: registryService,
104
+ abi: import_iDSRegistryService.iDSRegistryServiceAbi,
105
+ functionName: "addWallet",
106
+ args: [claimer, investorId]
107
+ });
108
+ logger?.debug(`Added wallet ${claimer} for investor "${investorId}"`);
109
+ try {
110
+ await writeAndWait(anvil, {
111
+ account,
112
+ chain: anvil.chain,
113
+ address: registryService,
114
+ abi: import_iDSRegistryService.iDSRegistryServiceAbi,
115
+ functionName: "setCountry",
116
+ args: [investorId, "US"]
117
+ });
118
+ logger?.debug(`Set country for investor "${investorId}" to "US"`);
119
+ await writeAndWait(anvil, {
120
+ account,
121
+ chain: anvil.chain,
122
+ address: registryService,
123
+ abi: import_iDSRegistryService.iDSRegistryServiceAbi,
124
+ functionName: "setAttribute",
125
+ args: [
126
+ investorId,
127
+ ACCREDITED,
128
+ BigInt(APPROVED),
129
+ import_sdk.MAX_UINT256,
130
+ "fake proof"
131
+ ]
132
+ });
133
+ logger?.debug(`Set attributes for investor "${investorId}"`);
134
+ } catch (e) {
135
+ logger?.error(e);
136
+ }
137
+ } else {
138
+ logger?.debug(`Claimer ${claimer} is already a registered wallet`);
139
+ }
140
+ }
141
+ async function claimDSToken(props) {
142
+ const {
143
+ anvil,
144
+ claimer,
145
+ adminPrivateKey,
146
+ token,
147
+ marketConfigurators,
148
+ kycFactories,
149
+ usdAmount: usdAmountProp = "100000"
150
+ } = props;
151
+ const account = (0, import_accounts.privateKeyToAccount)(adminPrivateKey);
152
+ const symbol = await anvil.readContract({
153
+ address: token,
154
+ abi: import_viem.erc20Abi,
155
+ functionName: "symbol",
156
+ args: []
157
+ });
158
+ const logger = props.logger?.child?.({ symbol });
159
+ const usdAmount = BigInt(usdAmountProp) * 10n ** 8n;
160
+ const sdk = new import_sdk.OnchainSDK(anvil.chain.network, {
161
+ client: anvil,
162
+ timeout: 12e4
163
+ });
164
+ await sdk.attach({ marketConfigurators, kycFactories });
165
+ let amount = 0n;
166
+ for (const market of sdk.marketRegister.markets) {
167
+ try {
168
+ amount = market.priceOracle.convertFromUSD(token, usdAmount);
169
+ } catch {
170
+ }
171
+ }
172
+ if (amount === 0n) {
173
+ throw new Error(`No market found for token ${token}`);
174
+ }
175
+ logger?.debug(`${usdAmountProp} USD === ${amount} ${symbol}`);
176
+ await registerInvestor({ ...props, logger });
177
+ logger?.debug(`Issuing ${amount} tokens to ${claimer}...`);
178
+ const mintHash = await writeAndWait(anvil, {
179
+ account,
180
+ chain: anvil.chain,
181
+ address: token,
182
+ abi: import_iDSToken.iDSTokenAbi,
183
+ functionName: "issueTokens",
184
+ args: [claimer, amount]
185
+ });
186
+ logger?.debug(`Done! tx: ${mintHash}`);
187
+ const balance = await anvil.readContract({
188
+ address: token,
189
+ abi: import_viem.erc20Abi,
190
+ functionName: "balanceOf",
191
+ args: [claimer]
192
+ });
193
+ logger?.debug(
194
+ `Balance of ${claimer}: ${sdk.tokensMeta.formatBN(token, balance)}`
195
+ );
196
+ }
197
+ async function claimDSTokens(props) {
198
+ const { tokens, ...rest } = props;
199
+ for (const token of tokens) {
200
+ await claimDSToken({ ...rest, token });
201
+ }
202
+ }
203
+ // Annotate the CommonJS export names for ESM import in node:
204
+ 0 && (module.exports = {
205
+ claimDSToken,
206
+ claimDSTokens,
207
+ registerInvestor
208
+ });
@@ -50,8 +50,7 @@ class AccountsPlugin extends import_sdk.BasePlugin {
50
50
  if (!force && this.loaded) {
51
51
  return this.state;
52
52
  }
53
- const service = (0, import_sdk.createCreditAccountService)(this.sdk, 310);
54
- const accounts = await service.getCreditAccounts(
53
+ const accounts = await this.sdk.accounts.getCreditAccounts(
55
54
  this.#options,
56
55
  this.sdk.currentBlock
57
56
  );
@@ -23,6 +23,7 @@ __export(OnchainSDK_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(OnchainSDK_exports);
25
25
  var import_viem = require("viem");
26
+ var import_accounts = require("./accounts/index.js");
26
27
  var import_base = require("./base/index.js");
27
28
  var import_chain = require("./chain/index.js");
28
29
  var import_constants = require("./constants/index.js");
@@ -31,6 +32,7 @@ var import_market = require("./market/index.js");
31
32
  var import_MarketRegister = require("./market/MarketRegister.js");
32
33
  var import_pricefeeds = require("./market/pricefeeds/index.js");
33
34
  var import_plugins = require("./plugins/index.js");
35
+ var import_pools = require("./pools/index.js");
34
36
  var import_router = require("./router/index.js");
35
37
  var import_utils = require("./utils/index.js");
36
38
  var import_viem2 = require("./utils/viem/index.js");
@@ -73,6 +75,14 @@ class OnchainSDK extends import_base.ChainContractsRegister {
73
75
  * When `true`, the SDK throws on unrecognised contract types.
74
76
  **/
75
77
  strictContractTypes;
78
+ /**
79
+ * Namespace for credit accounts operations.
80
+ */
81
+ accounts;
82
+ /**
83
+ * Namespace for pool operations.
84
+ */
85
+ pools;
76
86
  /**
77
87
  * @param network - Gearbox network type (e.g. `"Mainnet"`, `"Monad"`).
78
88
  * @param clientOptions - Connection options (RPC URLs, transport, or client).
@@ -97,6 +107,8 @@ class OnchainSDK extends import_base.ChainContractsRegister {
97
107
  if (options?.gasLimit !== null) {
98
108
  this.gasLimit = options?.gasLimit ?? (0, import_chain.getChain)(this.networkType).gasLimit;
99
109
  }
110
+ this.accounts = new import_accounts.CreditAccountsServiceV310(this);
111
+ this.pools = new import_pools.PoolService(this);
100
112
  }
101
113
  /**
102
114
  * Initialises the SDK by reading live on-chain state.