@myx-trade/sdk 0.1.213 → 0.1.216

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/index.js CHANGED
@@ -1807,7 +1807,7 @@ var RotationProvider = class extends import_providers.BaseProvider {
1807
1807
  // package.json
1808
1808
  var package_default = {
1809
1809
  name: "@myx-trade/sdk",
1810
- version: "0.1.213",
1810
+ version: "0.1.216",
1811
1811
  private: false,
1812
1812
  publishConfig: {
1813
1813
  access: "public"
@@ -11474,6 +11474,11 @@ var getBrokerSingerContract = async (chainId, brokerAddress) => {
11474
11474
  var getSeamlessBrokerContract = async (brokerAddress, singer) => {
11475
11475
  return getContract(brokerAddress, Broker_default, singer);
11476
11476
  };
11477
+ var getBrokerContract = async (chainId, brokerAddress) => {
11478
+ const address = brokerAddress;
11479
+ const provider = getJSONProvider(chainId);
11480
+ return getContract(address, Broker_default, provider);
11481
+ };
11477
11482
  var getPythContract = async (chainId, type = 0 /* JSON */) => {
11478
11483
  const addresses = address_default[chainId];
11479
11484
  const address = addresses.PYTH;
@@ -20291,8 +20296,14 @@ var Utils = class {
20291
20296
  if (error?.code === "ACTION_REJECTED" || error?.code === 4001 || error?.info?.error?.code === 4001 || typeof error?.message === "string" && (error.message.toLowerCase().includes("user rejected") || error.message.toLowerCase().includes("denied"))) {
20292
20297
  return "User Rejected";
20293
20298
  }
20294
- if (error?.data) {
20295
- const errorData = error.data;
20299
+ let errorData = error?.data;
20300
+ if (!errorData && error?.message && typeof error.message === "string") {
20301
+ const dataMatch = error.message.match(/data=["'](0x[0-9a-fA-F]+)["']/i);
20302
+ if (dataMatch && dataMatch[1]) {
20303
+ errorData = dataMatch[1];
20304
+ }
20305
+ }
20306
+ if (errorData) {
20296
20307
  const selector = typeof errorData === "string" && errorData.startsWith("0x") ? errorData.slice(0, 10).toLowerCase() : null;
20297
20308
  if (selector) {
20298
20309
  const errorKey = Object.keys(customErrorMapping).find(
@@ -22208,6 +22219,60 @@ var Seamless = class {
22208
22219
  }
22209
22220
  };
22210
22221
 
22222
+ // src/manager/base/BaseMyxClient.ts
22223
+ var BaseMyxClient = class {
22224
+ constructor(client2) {
22225
+ this.client = client2;
22226
+ }
22227
+ getConfig() {
22228
+ return this.client.getConfigManager()?.getConfig();
22229
+ }
22230
+ async getSigner() {
22231
+ const config = this.getConfig();
22232
+ if (!config?.signer) {
22233
+ throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
22234
+ }
22235
+ return config.signer;
22236
+ }
22237
+ getAddressConfig() {
22238
+ const config = this.getConfig();
22239
+ const chainId = config?.chainId;
22240
+ if (!chainId || isSupportedChainFn(chainId)) {
22241
+ throw new MyxSDKError("INVALID_CHAIN_ID" /* InvalidChainId */, "Invalid chain id");
22242
+ }
22243
+ return address_default[chainId];
22244
+ }
22245
+ async connectContract(contract) {
22246
+ return contract.connect(await this.getSigner());
22247
+ }
22248
+ async getBrokerContract() {
22249
+ const config = this.getConfig();
22250
+ if (!config?.brokerAddress) {
22251
+ throw new MyxSDKError(
22252
+ "INVALID_BROKER_ADDRESS" /* InvalidBrokerAddress */,
22253
+ "Invalid broker address"
22254
+ );
22255
+ }
22256
+ return getBrokerContract(config.chainId, config.brokerAddress);
22257
+ }
22258
+ };
22259
+
22260
+ // src/manager/referrals/index.tsx
22261
+ var Referrals = class extends BaseMyxClient {
22262
+ constructor(client2) {
22263
+ super(client2);
22264
+ }
22265
+ async claimRebate() {
22266
+ const usdcAddress = this.getAddressConfig().USDC;
22267
+ const brokerContract = await this.connectContract(
22268
+ await this.getBrokerContract()
22269
+ );
22270
+ const tx = await brokerContract.claimRebate(usdcAddress);
22271
+ const receipt = await tx.wait();
22272
+ return receipt;
22273
+ }
22274
+ };
22275
+
22211
22276
  // src/manager/index.ts
22212
22277
  var MyxClient = class {
22213
22278
  /**
@@ -22226,12 +22291,38 @@ var MyxClient = class {
22226
22291
  lp.getMarkets().then();
22227
22292
  this.utils = new Utils(this.configManager, this.logger);
22228
22293
  this.api = new Api(this.configManager, this.logger);
22229
- this.account = new Account(this.configManager, this.logger, this.utils, this);
22230
- this.seamless = new Seamless(this.configManager, this.logger, this.utils, this.account, this.api);
22294
+ this.account = new Account(
22295
+ this.configManager,
22296
+ this.logger,
22297
+ this.utils,
22298
+ this
22299
+ );
22300
+ this.seamless = new Seamless(
22301
+ this.configManager,
22302
+ this.logger,
22303
+ this.utils,
22304
+ this.account,
22305
+ this.api
22306
+ );
22231
22307
  this.markets = new Markets(this.configManager, this.utils, this.api);
22232
- this.position = new Position(this.configManager, this.logger, this.utils, this.seamless, this.account, this.api);
22233
- this.order = new Order(this.configManager, this.logger, this.utils, this.seamless, this.account, this.api);
22308
+ this.position = new Position(
22309
+ this.configManager,
22310
+ this.logger,
22311
+ this.utils,
22312
+ this.seamless,
22313
+ this.account,
22314
+ this.api
22315
+ );
22316
+ this.order = new Order(
22317
+ this.configManager,
22318
+ this.logger,
22319
+ this.utils,
22320
+ this.seamless,
22321
+ this.account,
22322
+ this.api
22323
+ );
22234
22324
  this.subscription = new SubScription(this.configManager, this.logger);
22325
+ this.referrals = new Referrals(this);
22235
22326
  }
22236
22327
  /**
22237
22328
  * auth the client
package/dist/index.mjs CHANGED
@@ -1731,7 +1731,7 @@ var RotationProvider = class extends BaseProvider {
1731
1731
  // package.json
1732
1732
  var package_default = {
1733
1733
  name: "@myx-trade/sdk",
1734
- version: "0.1.213",
1734
+ version: "0.1.216",
1735
1735
  private: false,
1736
1736
  publishConfig: {
1737
1737
  access: "public"
@@ -11398,6 +11398,11 @@ var getBrokerSingerContract = async (chainId, brokerAddress) => {
11398
11398
  var getSeamlessBrokerContract = async (brokerAddress, singer) => {
11399
11399
  return getContract(brokerAddress, Broker_default, singer);
11400
11400
  };
11401
+ var getBrokerContract = async (chainId, brokerAddress) => {
11402
+ const address = brokerAddress;
11403
+ const provider = getJSONProvider(chainId);
11404
+ return getContract(address, Broker_default, provider);
11405
+ };
11401
11406
  var getPythContract = async (chainId, type = 0 /* JSON */) => {
11402
11407
  const addresses = address_default[chainId];
11403
11408
  const address = addresses.PYTH;
@@ -20215,8 +20220,14 @@ var Utils = class {
20215
20220
  if (error?.code === "ACTION_REJECTED" || error?.code === 4001 || error?.info?.error?.code === 4001 || typeof error?.message === "string" && (error.message.toLowerCase().includes("user rejected") || error.message.toLowerCase().includes("denied"))) {
20216
20221
  return "User Rejected";
20217
20222
  }
20218
- if (error?.data) {
20219
- const errorData = error.data;
20223
+ let errorData = error?.data;
20224
+ if (!errorData && error?.message && typeof error.message === "string") {
20225
+ const dataMatch = error.message.match(/data=["'](0x[0-9a-fA-F]+)["']/i);
20226
+ if (dataMatch && dataMatch[1]) {
20227
+ errorData = dataMatch[1];
20228
+ }
20229
+ }
20230
+ if (errorData) {
20220
20231
  const selector = typeof errorData === "string" && errorData.startsWith("0x") ? errorData.slice(0, 10).toLowerCase() : null;
20221
20232
  if (selector) {
20222
20233
  const errorKey = Object.keys(customErrorMapping).find(
@@ -22132,6 +22143,60 @@ var Seamless = class {
22132
22143
  }
22133
22144
  };
22134
22145
 
22146
+ // src/manager/base/BaseMyxClient.ts
22147
+ var BaseMyxClient = class {
22148
+ constructor(client2) {
22149
+ this.client = client2;
22150
+ }
22151
+ getConfig() {
22152
+ return this.client.getConfigManager()?.getConfig();
22153
+ }
22154
+ async getSigner() {
22155
+ const config = this.getConfig();
22156
+ if (!config?.signer) {
22157
+ throw new MyxSDKError("INVALID_SIGNER" /* InvalidSigner */, "Invalid signer");
22158
+ }
22159
+ return config.signer;
22160
+ }
22161
+ getAddressConfig() {
22162
+ const config = this.getConfig();
22163
+ const chainId = config?.chainId;
22164
+ if (!chainId || isSupportedChainFn(chainId)) {
22165
+ throw new MyxSDKError("INVALID_CHAIN_ID" /* InvalidChainId */, "Invalid chain id");
22166
+ }
22167
+ return address_default[chainId];
22168
+ }
22169
+ async connectContract(contract) {
22170
+ return contract.connect(await this.getSigner());
22171
+ }
22172
+ async getBrokerContract() {
22173
+ const config = this.getConfig();
22174
+ if (!config?.brokerAddress) {
22175
+ throw new MyxSDKError(
22176
+ "INVALID_BROKER_ADDRESS" /* InvalidBrokerAddress */,
22177
+ "Invalid broker address"
22178
+ );
22179
+ }
22180
+ return getBrokerContract(config.chainId, config.brokerAddress);
22181
+ }
22182
+ };
22183
+
22184
+ // src/manager/referrals/index.tsx
22185
+ var Referrals = class extends BaseMyxClient {
22186
+ constructor(client2) {
22187
+ super(client2);
22188
+ }
22189
+ async claimRebate() {
22190
+ const usdcAddress = this.getAddressConfig().USDC;
22191
+ const brokerContract = await this.connectContract(
22192
+ await this.getBrokerContract()
22193
+ );
22194
+ const tx = await brokerContract.claimRebate(usdcAddress);
22195
+ const receipt = await tx.wait();
22196
+ return receipt;
22197
+ }
22198
+ };
22199
+
22135
22200
  // src/manager/index.ts
22136
22201
  var MyxClient = class {
22137
22202
  /**
@@ -22150,12 +22215,38 @@ var MyxClient = class {
22150
22215
  lp.getMarkets().then();
22151
22216
  this.utils = new Utils(this.configManager, this.logger);
22152
22217
  this.api = new Api(this.configManager, this.logger);
22153
- this.account = new Account(this.configManager, this.logger, this.utils, this);
22154
- this.seamless = new Seamless(this.configManager, this.logger, this.utils, this.account, this.api);
22218
+ this.account = new Account(
22219
+ this.configManager,
22220
+ this.logger,
22221
+ this.utils,
22222
+ this
22223
+ );
22224
+ this.seamless = new Seamless(
22225
+ this.configManager,
22226
+ this.logger,
22227
+ this.utils,
22228
+ this.account,
22229
+ this.api
22230
+ );
22155
22231
  this.markets = new Markets(this.configManager, this.utils, this.api);
22156
- this.position = new Position(this.configManager, this.logger, this.utils, this.seamless, this.account, this.api);
22157
- this.order = new Order(this.configManager, this.logger, this.utils, this.seamless, this.account, this.api);
22232
+ this.position = new Position(
22233
+ this.configManager,
22234
+ this.logger,
22235
+ this.utils,
22236
+ this.seamless,
22237
+ this.account,
22238
+ this.api
22239
+ );
22240
+ this.order = new Order(
22241
+ this.configManager,
22242
+ this.logger,
22243
+ this.utils,
22244
+ this.seamless,
22245
+ this.account,
22246
+ this.api
22247
+ );
22158
22248
  this.subscription = new SubScription(this.configManager, this.logger);
22249
+ this.referrals = new Referrals(this);
22159
22250
  }
22160
22251
  /**
22161
22252
  * auth the client
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myx-trade/sdk",
3
- "version": "0.1.213",
3
+ "version": "0.1.216",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"