@myx-trade/sdk 0.1.239-beta.1 → 0.1.239-beta.2

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.d.mts CHANGED
@@ -1360,7 +1360,7 @@ declare class Utils {
1360
1360
  constructor(configManager: ConfigManager, logger: Logger);
1361
1361
  getOrderIdFromTransaction(receipt: any): string | null;
1362
1362
  private getApproveQuoteAmount;
1363
- needsApproval(address: string, chainId: number, quoteAddress: string, requiredAmount: string, spenderAddress?: string): Promise<boolean>;
1363
+ needsApproval(account: string, chainId: number, tokenAddress: string, requiredAmount: string, spenderAddress?: string): Promise<boolean>;
1364
1364
  approveAuthorization({ chainId, quoteAddress, amount, spenderAddress, signer, }: {
1365
1365
  chainId: number;
1366
1366
  quoteAddress: string;
@@ -1393,13 +1393,14 @@ declare class Utils {
1393
1393
  publishTime: number;
1394
1394
  oracleType: OracleType;
1395
1395
  vaa: string;
1396
- } | {
1397
- price: string;
1398
- vaa: string;
1399
- publishTime: number;
1400
- poolId: string;
1401
- value: number;
1402
1396
  }>;
1397
+ buildUpdatePriceParams(poolId: string, chainId: number): Promise<{
1398
+ poolId: string;
1399
+ referencePrice: bigint;
1400
+ oracleUpdateData: string;
1401
+ publishTime: number;
1402
+ oracleType: OracleType;
1403
+ }[]>;
1403
1404
  transferKlineResolutionToInterval(resolution: KlineResolution): HttpKlineIntervalEnum;
1404
1405
  getErrorMessage(error: any, fallbackErrorMessage?: string): Promise<any>;
1405
1406
  checkSeamlessGas(userAddress: string, chainId: number): Promise<boolean>;
@@ -3373,7 +3374,7 @@ declare class Appeal extends BaseMyxClient {
3373
3374
  * @param poolToken - the pool token
3374
3375
  * @returns the transaction receipt
3375
3376
  */
3376
- submitAppeal(poolId: string, poolToken: string): Promise<ethers.ContractTransactionReceipt | null>;
3377
+ submitAppeal(poolId: string, lpToken: Address$2, lpAmount: string): Promise<ethers.ContractTransactionReceipt | null>;
3377
3378
  /**
3378
3379
  * vote for appeal
3379
3380
  * @param caseId - the case id
package/dist/index.d.ts CHANGED
@@ -1360,7 +1360,7 @@ declare class Utils {
1360
1360
  constructor(configManager: ConfigManager, logger: Logger);
1361
1361
  getOrderIdFromTransaction(receipt: any): string | null;
1362
1362
  private getApproveQuoteAmount;
1363
- needsApproval(address: string, chainId: number, quoteAddress: string, requiredAmount: string, spenderAddress?: string): Promise<boolean>;
1363
+ needsApproval(account: string, chainId: number, tokenAddress: string, requiredAmount: string, spenderAddress?: string): Promise<boolean>;
1364
1364
  approveAuthorization({ chainId, quoteAddress, amount, spenderAddress, signer, }: {
1365
1365
  chainId: number;
1366
1366
  quoteAddress: string;
@@ -1393,13 +1393,14 @@ declare class Utils {
1393
1393
  publishTime: number;
1394
1394
  oracleType: OracleType;
1395
1395
  vaa: string;
1396
- } | {
1397
- price: string;
1398
- vaa: string;
1399
- publishTime: number;
1400
- poolId: string;
1401
- value: number;
1402
1396
  }>;
1397
+ buildUpdatePriceParams(poolId: string, chainId: number): Promise<{
1398
+ poolId: string;
1399
+ referencePrice: bigint;
1400
+ oracleUpdateData: string;
1401
+ publishTime: number;
1402
+ oracleType: OracleType;
1403
+ }[]>;
1403
1404
  transferKlineResolutionToInterval(resolution: KlineResolution): HttpKlineIntervalEnum;
1404
1405
  getErrorMessage(error: any, fallbackErrorMessage?: string): Promise<any>;
1405
1406
  checkSeamlessGas(userAddress: string, chainId: number): Promise<boolean>;
@@ -3373,7 +3374,7 @@ declare class Appeal extends BaseMyxClient {
3373
3374
  * @param poolToken - the pool token
3374
3375
  * @returns the transaction receipt
3375
3376
  */
3376
- submitAppeal(poolId: string, poolToken: string): Promise<ethers.ContractTransactionReceipt | null>;
3377
+ submitAppeal(poolId: string, lpToken: Address$2, lpAmount: string): Promise<ethers.ContractTransactionReceipt | null>;
3377
3378
  /**
3378
3379
  * vote for appeal
3379
3380
  * @param caseId - the case id
package/dist/index.js CHANGED
@@ -1834,7 +1834,7 @@ var RotationProvider = class extends import_providers.BaseProvider {
1834
1834
  // package.json
1835
1835
  var package_default = {
1836
1836
  name: "@myx-trade/sdk",
1837
- version: "0.1.239-beta.1",
1837
+ version: "0.1.239-beta.2",
1838
1838
  private: false,
1839
1839
  publishConfig: {
1840
1840
  access: "public"
@@ -12898,8 +12898,35 @@ var DisputeCourt_default = [
12898
12898
  type: "function",
12899
12899
  name: "fileDispute",
12900
12900
  constant: false,
12901
- payable: false,
12901
+ stateMutability: "payable",
12902
+ payable: true,
12902
12903
  inputs: [
12904
+ {
12905
+ type: "tuple[]",
12906
+ name: "prices",
12907
+ components: [
12908
+ {
12909
+ type: "bytes32",
12910
+ name: "poolId"
12911
+ },
12912
+ {
12913
+ type: "uint8",
12914
+ name: "oracleType"
12915
+ },
12916
+ {
12917
+ type: "uint256",
12918
+ name: "referencePrice"
12919
+ },
12920
+ {
12921
+ type: "bytes",
12922
+ name: "oracleUpdateData"
12923
+ },
12924
+ {
12925
+ type: "uint64",
12926
+ name: "publishTime"
12927
+ }
12928
+ ]
12929
+ },
12903
12930
  {
12904
12931
  type: "bytes32",
12905
12932
  name: "poolId"
@@ -13127,6 +13154,10 @@ var DisputeCourt_default = [
13127
13154
  name: "expireTime"
13128
13155
  }
13129
13156
  ]
13157
+ },
13158
+ {
13159
+ type: "bytes32[]",
13160
+ name: "zeroMerkleProof"
13130
13161
  }
13131
13162
  ],
13132
13163
  outputs: []
@@ -22019,7 +22050,7 @@ var Utils = class {
22019
22050
  }
22020
22051
  return null;
22021
22052
  }
22022
- async getApproveQuoteAmount(address, chainId, quoteAddress, spenderAddress) {
22053
+ async getApproveQuoteAmount(account, chainId, tokenAddress, spenderAddress) {
22023
22054
  try {
22024
22055
  const erc20Abi = [
22025
22056
  "function allowance(address owner, address spender) external view returns (uint256)"
@@ -22027,11 +22058,11 @@ var Utils = class {
22027
22058
  const spender = spenderAddress ?? getContractAddressByChainId(chainId).Account;
22028
22059
  const provider = await getJSONProvider(chainId);
22029
22060
  const tokenContract = new import_ethers25.ethers.Contract(
22030
- quoteAddress,
22061
+ tokenAddress,
22031
22062
  erc20Abi,
22032
22063
  provider
22033
22064
  );
22034
- const allowance = await tokenContract.allowance(address, spender);
22065
+ const allowance = await tokenContract.allowance(account, spender);
22035
22066
  return {
22036
22067
  code: 0,
22037
22068
  data: allowance.toString()
@@ -22041,12 +22072,12 @@ var Utils = class {
22041
22072
  throw typeof error === "string" ? error : await getErrorTextFormError(error);
22042
22073
  }
22043
22074
  }
22044
- async needsApproval(address, chainId, quoteAddress, requiredAmount, spenderAddress) {
22075
+ async needsApproval(account, chainId, tokenAddress, requiredAmount, spenderAddress) {
22045
22076
  try {
22046
22077
  const currentAllowanceRes = await this.getApproveQuoteAmount(
22047
- address,
22078
+ account,
22048
22079
  chainId,
22049
- quoteAddress,
22080
+ tokenAddress,
22050
22081
  spenderAddress
22051
22082
  );
22052
22083
  const currentAllowance = currentAllowanceRes.data;
@@ -22080,7 +22111,16 @@ var Utils = class {
22080
22111
  console.log("approveAuthorization: usdcContract-->", usdcContract);
22081
22112
  const approveAmount = amount ?? import_ethers25.ethers.MaxUint256;
22082
22113
  const spender = spenderAddress ?? getContractAddressByChainId(chainId).Account;
22083
- const tx = await usdcContract.approve(spender, approveAmount);
22114
+ const gasPrice = await this.getGasPriceByRatio();
22115
+ const _gasLimit = await usdcContract.approve.estimateGas(
22116
+ spender,
22117
+ approveAmount
22118
+ );
22119
+ const gasLimit = await this.getGasLimitByRatio(_gasLimit);
22120
+ const tx = await usdcContract.approve(spender, approveAmount, {
22121
+ gasLimit,
22122
+ gasPrice
22123
+ });
22084
22124
  await tx.wait();
22085
22125
  return {
22086
22126
  code: 0,
@@ -22154,15 +22194,22 @@ var Utils = class {
22154
22194
  return priceData;
22155
22195
  } catch (error) {
22156
22196
  this.logger.error("Error getting oracle price:", error);
22157
- return {
22158
- price: "0",
22159
- vaa: "",
22160
- publishTime: 0,
22161
- poolId: "",
22162
- value: 0
22163
- };
22197
+ throw error;
22164
22198
  }
22165
22199
  }
22200
+ async buildUpdatePriceParams(poolId, chainId) {
22201
+ const priceData = await this.getOraclePrice(poolId, chainId);
22202
+ if (!priceData) throw new Error("Failed to get price data");
22203
+ return [
22204
+ {
22205
+ poolId,
22206
+ referencePrice: import_ethers25.ethers.parseUnits(priceData.price, 30),
22207
+ oracleUpdateData: priceData.vaa,
22208
+ publishTime: priceData.publishTime,
22209
+ oracleType: priceData.oracleType
22210
+ }
22211
+ ];
22212
+ }
22166
22213
  transferKlineResolutionToInterval(resolution) {
22167
22214
  switch (resolution) {
22168
22215
  case "1m":
@@ -24165,11 +24212,11 @@ var Appeal = class extends BaseMyxClient {
24165
24212
  super(client2);
24166
24213
  }
24167
24214
  async getDisputeCourtContract() {
24168
- const contract = await getDisputeCourtContract(this.getConfig()?.chainId);
24215
+ const contract = await getDisputeCourtContract(this.config.chainId);
24169
24216
  return this.connectContract(contract);
24170
24217
  }
24171
24218
  async getReimbursementContract() {
24172
- const contract = await getReimbursementContract(this.getConfig()?.chainId);
24219
+ const contract = await getReimbursementContract(this.config.chainId);
24173
24220
  return this.connectContract(contract);
24174
24221
  }
24175
24222
  /**
@@ -24178,12 +24225,35 @@ var Appeal = class extends BaseMyxClient {
24178
24225
  * @param poolToken - the pool token
24179
24226
  * @returns the transaction receipt
24180
24227
  */
24181
- async submitAppeal(poolId, poolToken) {
24228
+ async submitAppeal(poolId, lpToken, lpAmount) {
24229
+ const account = await this.config.signer?.getAddress() ?? "";
24230
+ const needApprove = await this.client.utils.needsApproval(
24231
+ account,
24232
+ this.config.chainId,
24233
+ lpToken,
24234
+ lpAmount,
24235
+ this.getAddressConfig().DISPUTE_COURT
24236
+ );
24237
+ if (needApprove) {
24238
+ await this.client.utils.approveAuthorization({
24239
+ chainId: this.config.chainId,
24240
+ quoteAddress: lpToken,
24241
+ spenderAddress: this.getAddressConfig().DISPUTE_COURT
24242
+ });
24243
+ }
24182
24244
  const contract = await this.getDisputeCourtContract();
24183
- const _gasLimit = await contract.fileDispute.estimateGas(poolId, poolToken);
24245
+ const prices = await this.client.utils.buildUpdatePriceParams(
24246
+ poolId,
24247
+ this.config.chainId
24248
+ );
24249
+ const _gasLimit = await contract.fileDispute.estimateGas(
24250
+ prices,
24251
+ poolId,
24252
+ lpToken
24253
+ );
24184
24254
  const gasLimit = await this.client.utils.getGasLimitByRatio(_gasLimit);
24185
24255
  const gasPrice = await this.client.utils.getGasPriceByRatio();
24186
- const tx = await contract.fileDispute(poolId, poolToken, {
24256
+ const tx = await contract.fileDispute(prices, poolId, lpToken, {
24187
24257
  gasLimit,
24188
24258
  gasPrice
24189
24259
  });
package/dist/index.mjs CHANGED
@@ -1758,7 +1758,7 @@ var RotationProvider = class extends BaseProvider {
1758
1758
  // package.json
1759
1759
  var package_default = {
1760
1760
  name: "@myx-trade/sdk",
1761
- version: "0.1.239-beta.1",
1761
+ version: "0.1.239-beta.2",
1762
1762
  private: false,
1763
1763
  publishConfig: {
1764
1764
  access: "public"
@@ -12822,8 +12822,35 @@ var DisputeCourt_default = [
12822
12822
  type: "function",
12823
12823
  name: "fileDispute",
12824
12824
  constant: false,
12825
- payable: false,
12825
+ stateMutability: "payable",
12826
+ payable: true,
12826
12827
  inputs: [
12828
+ {
12829
+ type: "tuple[]",
12830
+ name: "prices",
12831
+ components: [
12832
+ {
12833
+ type: "bytes32",
12834
+ name: "poolId"
12835
+ },
12836
+ {
12837
+ type: "uint8",
12838
+ name: "oracleType"
12839
+ },
12840
+ {
12841
+ type: "uint256",
12842
+ name: "referencePrice"
12843
+ },
12844
+ {
12845
+ type: "bytes",
12846
+ name: "oracleUpdateData"
12847
+ },
12848
+ {
12849
+ type: "uint64",
12850
+ name: "publishTime"
12851
+ }
12852
+ ]
12853
+ },
12827
12854
  {
12828
12855
  type: "bytes32",
12829
12856
  name: "poolId"
@@ -13051,6 +13078,10 @@ var DisputeCourt_default = [
13051
13078
  name: "expireTime"
13052
13079
  }
13053
13080
  ]
13081
+ },
13082
+ {
13083
+ type: "bytes32[]",
13084
+ name: "zeroMerkleProof"
13054
13085
  }
13055
13086
  ],
13056
13087
  outputs: []
@@ -21943,7 +21974,7 @@ var Utils = class {
21943
21974
  }
21944
21975
  return null;
21945
21976
  }
21946
- async getApproveQuoteAmount(address, chainId, quoteAddress, spenderAddress) {
21977
+ async getApproveQuoteAmount(account, chainId, tokenAddress, spenderAddress) {
21947
21978
  try {
21948
21979
  const erc20Abi = [
21949
21980
  "function allowance(address owner, address spender) external view returns (uint256)"
@@ -21951,11 +21982,11 @@ var Utils = class {
21951
21982
  const spender = spenderAddress ?? getContractAddressByChainId(chainId).Account;
21952
21983
  const provider = await getJSONProvider(chainId);
21953
21984
  const tokenContract = new ethers7.Contract(
21954
- quoteAddress,
21985
+ tokenAddress,
21955
21986
  erc20Abi,
21956
21987
  provider
21957
21988
  );
21958
- const allowance = await tokenContract.allowance(address, spender);
21989
+ const allowance = await tokenContract.allowance(account, spender);
21959
21990
  return {
21960
21991
  code: 0,
21961
21992
  data: allowance.toString()
@@ -21965,12 +21996,12 @@ var Utils = class {
21965
21996
  throw typeof error === "string" ? error : await getErrorTextFormError(error);
21966
21997
  }
21967
21998
  }
21968
- async needsApproval(address, chainId, quoteAddress, requiredAmount, spenderAddress) {
21999
+ async needsApproval(account, chainId, tokenAddress, requiredAmount, spenderAddress) {
21969
22000
  try {
21970
22001
  const currentAllowanceRes = await this.getApproveQuoteAmount(
21971
- address,
22002
+ account,
21972
22003
  chainId,
21973
- quoteAddress,
22004
+ tokenAddress,
21974
22005
  spenderAddress
21975
22006
  );
21976
22007
  const currentAllowance = currentAllowanceRes.data;
@@ -22004,7 +22035,16 @@ var Utils = class {
22004
22035
  console.log("approveAuthorization: usdcContract-->", usdcContract);
22005
22036
  const approveAmount = amount ?? ethers7.MaxUint256;
22006
22037
  const spender = spenderAddress ?? getContractAddressByChainId(chainId).Account;
22007
- const tx = await usdcContract.approve(spender, approveAmount);
22038
+ const gasPrice = await this.getGasPriceByRatio();
22039
+ const _gasLimit = await usdcContract.approve.estimateGas(
22040
+ spender,
22041
+ approveAmount
22042
+ );
22043
+ const gasLimit = await this.getGasLimitByRatio(_gasLimit);
22044
+ const tx = await usdcContract.approve(spender, approveAmount, {
22045
+ gasLimit,
22046
+ gasPrice
22047
+ });
22008
22048
  await tx.wait();
22009
22049
  return {
22010
22050
  code: 0,
@@ -22078,15 +22118,22 @@ var Utils = class {
22078
22118
  return priceData;
22079
22119
  } catch (error) {
22080
22120
  this.logger.error("Error getting oracle price:", error);
22081
- return {
22082
- price: "0",
22083
- vaa: "",
22084
- publishTime: 0,
22085
- poolId: "",
22086
- value: 0
22087
- };
22121
+ throw error;
22088
22122
  }
22089
22123
  }
22124
+ async buildUpdatePriceParams(poolId, chainId) {
22125
+ const priceData = await this.getOraclePrice(poolId, chainId);
22126
+ if (!priceData) throw new Error("Failed to get price data");
22127
+ return [
22128
+ {
22129
+ poolId,
22130
+ referencePrice: ethers7.parseUnits(priceData.price, 30),
22131
+ oracleUpdateData: priceData.vaa,
22132
+ publishTime: priceData.publishTime,
22133
+ oracleType: priceData.oracleType
22134
+ }
22135
+ ];
22136
+ }
22090
22137
  transferKlineResolutionToInterval(resolution) {
22091
22138
  switch (resolution) {
22092
22139
  case "1m":
@@ -24089,11 +24136,11 @@ var Appeal = class extends BaseMyxClient {
24089
24136
  super(client2);
24090
24137
  }
24091
24138
  async getDisputeCourtContract() {
24092
- const contract = await getDisputeCourtContract(this.getConfig()?.chainId);
24139
+ const contract = await getDisputeCourtContract(this.config.chainId);
24093
24140
  return this.connectContract(contract);
24094
24141
  }
24095
24142
  async getReimbursementContract() {
24096
- const contract = await getReimbursementContract(this.getConfig()?.chainId);
24143
+ const contract = await getReimbursementContract(this.config.chainId);
24097
24144
  return this.connectContract(contract);
24098
24145
  }
24099
24146
  /**
@@ -24102,12 +24149,35 @@ var Appeal = class extends BaseMyxClient {
24102
24149
  * @param poolToken - the pool token
24103
24150
  * @returns the transaction receipt
24104
24151
  */
24105
- async submitAppeal(poolId, poolToken) {
24152
+ async submitAppeal(poolId, lpToken, lpAmount) {
24153
+ const account = await this.config.signer?.getAddress() ?? "";
24154
+ const needApprove = await this.client.utils.needsApproval(
24155
+ account,
24156
+ this.config.chainId,
24157
+ lpToken,
24158
+ lpAmount,
24159
+ this.getAddressConfig().DISPUTE_COURT
24160
+ );
24161
+ if (needApprove) {
24162
+ await this.client.utils.approveAuthorization({
24163
+ chainId: this.config.chainId,
24164
+ quoteAddress: lpToken,
24165
+ spenderAddress: this.getAddressConfig().DISPUTE_COURT
24166
+ });
24167
+ }
24106
24168
  const contract = await this.getDisputeCourtContract();
24107
- const _gasLimit = await contract.fileDispute.estimateGas(poolId, poolToken);
24169
+ const prices = await this.client.utils.buildUpdatePriceParams(
24170
+ poolId,
24171
+ this.config.chainId
24172
+ );
24173
+ const _gasLimit = await contract.fileDispute.estimateGas(
24174
+ prices,
24175
+ poolId,
24176
+ lpToken
24177
+ );
24108
24178
  const gasLimit = await this.client.utils.getGasLimitByRatio(_gasLimit);
24109
24179
  const gasPrice = await this.client.utils.getGasPriceByRatio();
24110
- const tx = await contract.fileDispute(poolId, poolToken, {
24180
+ const tx = await contract.fileDispute(prices, poolId, lpToken, {
24111
24181
  gasLimit,
24112
24182
  gasPrice
24113
24183
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myx-trade/sdk",
3
- "version": "0.1.239-beta.1",
3
+ "version": "0.1.239-beta.2",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"