@imtbl/sdk 0.28.0 → 0.28.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.
@@ -10931,6 +10931,12 @@ declare class Passport {
10931
10931
  private readonly passportImxProviderFactory;
10932
10932
  private readonly passportEventEmitter;
10933
10933
  constructor(passportModuleConfiguration: PassportModuleConfiguration);
10934
+ signIn(options?: {
10935
+ useCachedSession: boolean;
10936
+ }): Promise<UserProfile | null>;
10937
+ /**
10938
+ * @deprecated The method connectImx(useCachedSession) should be used instead
10939
+ */
10934
10940
  connectImxSilent(): Promise<IMXProvider | null>;
10935
10941
  connectImx(): Promise<IMXProvider>;
10936
10942
  loginWithDeviceFlow(): Promise<DeviceConnectResponse>;
@@ -12482,15 +12482,6 @@ class ApproveError extends ExchangeError {
12482
12482
  super(message, ExchangeErrorCode.APPROVE_ERROR);
12483
12483
  }
12484
12484
  }
12485
- class AlreadyApprovedError extends ExchangeError {
12486
- tokenAddress;
12487
- spenderAddress;
12488
- constructor(amountApproved, tokenAddress, spenderAddress) {
12489
- super(`already approved ${amountApproved} tokens`, ExchangeErrorCode.ALREADY_APPROVED_ERROR);
12490
- this.tokenAddress = tokenAddress;
12491
- this.spenderAddress = spenderAddress;
12492
- }
12493
- }
12494
12485
 
12495
12486
  /* Autogenerated file. Do not edit manually. */
12496
12487
  /* tslint:disable */
@@ -15124,8 +15115,7 @@ const calculateGasFee = (gasPrice, gasEstimate) =>
15124
15115
  newAmount(gasEstimate.mul(gasPrice.value), gasPrice.token);
15125
15116
 
15126
15117
  /**
15127
- * Get the amount of an ERC20 token that needs to be approved by
15128
- * checking the existing allowance for the spender
15118
+ * Check if the spender needs approval for the token
15129
15119
  *
15130
15120
  * @param provider - The provider to use for the call
15131
15121
  * @param ownerAddress - The address of the owner of the token
@@ -15133,11 +15123,11 @@ newAmount(gasEstimate.mul(gasPrice.value), gasPrice.token);
15133
15123
  * @param spenderAddress - The address of the spender
15134
15124
  * @returns - The amount of the token that needs to be approved
15135
15125
  */
15136
- const getERC20AmountToApprove = async (provider, ownerAddress, tokenAmount, spenderAddress) => {
15126
+ const doesSpenderNeedApproval = async (provider, ownerAddress, tokenAmount, spenderAddress) => {
15137
15127
  // create an instance of the ERC20 token contract
15138
15128
  const erc20Contract = ERC20__factory.connect(tokenAmount.token.address, provider);
15139
15129
  // get the allowance for the token spender
15140
- // minimum is 0 - no allowance
15130
+ // the minimum allowance is 0 - no allowance
15141
15131
  let allowance;
15142
15132
  try {
15143
15133
  allowance = await erc20Contract.allowance(ownerAddress, spenderAddress);
@@ -15146,12 +15136,12 @@ const getERC20AmountToApprove = async (provider, ownerAddress, tokenAmount, spen
15146
15136
  const message = e instanceof Error ? e.message : 'Unknown Error';
15147
15137
  throw new ApproveError(`failed to get allowance: ${message}`);
15148
15138
  }
15149
- // get the amount that needs to be approved
15139
+ // check if approval is needed
15150
15140
  const requiredAmount = tokenAmount.value.sub(allowance);
15151
15141
  if (requiredAmount.isNegative() || requiredAmount.isZero()) {
15152
- throw new AlreadyApprovedError(tokenAmount.toString(), tokenAmount.token.address, spenderAddress);
15142
+ return false;
15153
15143
  }
15154
- return newAmount(requiredAmount, tokenAmount.token);
15144
+ return true;
15155
15145
  };
15156
15146
  /**
15157
15147
  * Get an unsigned ERC20 approve transaction
@@ -15193,18 +15183,9 @@ const prepareApproval = (tradeType, userSpecifiedAmount, quotedAmountWithSlippag
15193
15183
  * @returns The unsigned ERC20 approve transaction, or null if no approval is needed
15194
15184
  */
15195
15185
  const getApproveTransaction = async (provider, ownerAddress, tokenAmount, spenderAddress) => {
15196
- let amountToApprove;
15197
- try {
15198
- amountToApprove = await getERC20AmountToApprove(provider, ownerAddress, tokenAmount, spenderAddress);
15199
- }
15200
- catch (e) {
15201
- if (e instanceof AlreadyApprovedError) {
15202
- // already approved for the required amount, nothing to do
15203
- return null;
15204
- }
15205
- throw e;
15206
- }
15207
- return getUnsignedERC20ApproveTransaction(ownerAddress, amountToApprove, spenderAddress);
15186
+ const needsApproval = await doesSpenderNeedApproval(provider, ownerAddress, tokenAmount, spenderAddress);
15187
+ // @dev approvals are not additive, so we need to approve the full amount
15188
+ return needsApproval ? getUnsignedERC20ApproveTransaction(ownerAddress, tokenAmount, spenderAddress) : null;
15208
15189
  };
15209
15190
  async function getApproveGasEstimate(provider, ownerAddress, spenderAddress, tokenAddress) {
15210
15191
  const erc20Contract = ERC20__factory.connect(tokenAddress, provider);
@@ -20787,7 +20768,7 @@ class APIError extends Error {
20787
20768
 
20788
20769
  /* eslint-disable implicit-arrow-linebreak */
20789
20770
  const defaultHeaders = {
20790
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.28.0',
20771
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.28.2',
20791
20772
  };
20792
20773
  /**
20793
20774
  * createAPIConfiguration to create a custom Configuration
@@ -22157,7 +22138,7 @@ class $fd8a8472dcc3ec2b$export$ef140a6b05dfc786 {
22157
22138
 
22158
22139
  const $458d407830d66110$export$e6a390ea6399b7d8 = (config, debugString, seconds)=>{
22159
22140
  // eslint-disable-next-line no-console
22160
- if (!config.isProduction) console.debug(debugString, seconds);
22141
+ if (!config.isProduction) console.info(debugString, seconds);
22161
22142
  };
22162
22143
  const $458d407830d66110$export$5280dbcb91c8b391 = async (config, debugString, promise)=>{
22163
22144
  const startTime = performance.now();
@@ -10869,6 +10869,12 @@ declare class Passport {
10869
10869
  private readonly passportImxProviderFactory;
10870
10870
  private readonly passportEventEmitter;
10871
10871
  constructor(passportModuleConfiguration: PassportModuleConfiguration);
10872
+ signIn(options?: {
10873
+ useCachedSession: boolean;
10874
+ }): Promise<UserProfile | null>;
10875
+ /**
10876
+ * @deprecated The method connectImx(useCachedSession) should be used instead
10877
+ */
10872
10878
  connectImxSilent(): Promise<IMXProvider | null>;
10873
10879
  connectImx(): Promise<IMXProvider>;
10874
10880
  loginWithDeviceFlow(): Promise<DeviceConnectResponse>;
@@ -25,7 +25,7 @@ var $045213b18e9f1f94$export$75be0f6af9650f2c;
25
25
  })($045213b18e9f1f94$export$75be0f6af9650f2c || ($045213b18e9f1f94$export$75be0f6af9650f2c = {}));
26
26
 
27
27
 
28
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.28.0";
28
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.28.2";
29
29
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
30
30
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
31
31
 
@@ -16,7 +16,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
16
16
  chainID,
17
17
  coreContractAddress,
18
18
  registrationContractAddress,
19
- sdkVersion: 'ts-immutable-sdk-0.28.0',
19
+ sdkVersion: 'ts-immutable-sdk-0.28.2',
20
20
  });
21
21
  /**
22
22
  * Sets `sdkVersion` at the time of build