atfi 1.1.1 → 1.1.3

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
@@ -541,6 +541,10 @@ declare class ATFiSDK {
541
541
  * Claim rewards after event settlement
542
542
  */
543
543
  claim(params: ClaimParams): Promise<ClaimAction>;
544
+ /**
545
+ * Approve token spending
546
+ */
547
+ approve(token: Address, spender: Address, amount: bigint): Promise<Hash>;
544
548
  /**
545
549
  * Get detailed event information
546
550
  */
@@ -619,7 +623,8 @@ declare enum ATFiErrorCode {
619
623
  INSUFFICIENT_ALLOWANCE = "INSUFFICIENT_ALLOWANCE",
620
624
  TRANSACTION_FAILED = "TRANSACTION_FAILED",
621
625
  CONTRACT_ERROR = "CONTRACT_ERROR",
622
- VAULT_NOT_FOUND = "VAULT_NOT_FOUND"
626
+ VAULT_NOT_FOUND = "VAULT_NOT_FOUND",
627
+ NETWORK_ERROR = "NETWORK_ERROR"
623
628
  }
624
629
  declare class ATFiError extends Error {
625
630
  code: ATFiErrorCode;
package/dist/index.d.ts CHANGED
@@ -541,6 +541,10 @@ declare class ATFiSDK {
541
541
  * Claim rewards after event settlement
542
542
  */
543
543
  claim(params: ClaimParams): Promise<ClaimAction>;
544
+ /**
545
+ * Approve token spending
546
+ */
547
+ approve(token: Address, spender: Address, amount: bigint): Promise<Hash>;
544
548
  /**
545
549
  * Get detailed event information
546
550
  */
@@ -619,7 +623,8 @@ declare enum ATFiErrorCode {
619
623
  INSUFFICIENT_ALLOWANCE = "INSUFFICIENT_ALLOWANCE",
620
624
  TRANSACTION_FAILED = "TRANSACTION_FAILED",
621
625
  CONTRACT_ERROR = "CONTRACT_ERROR",
622
- VAULT_NOT_FOUND = "VAULT_NOT_FOUND"
626
+ VAULT_NOT_FOUND = "VAULT_NOT_FOUND",
627
+ NETWORK_ERROR = "NETWORK_ERROR"
623
628
  }
624
629
  declare class ATFiError extends Error {
625
630
  code: ATFiErrorCode;
package/dist/index.js CHANGED
@@ -224,6 +224,7 @@ var ATFiErrorCode = /* @__PURE__ */ ((ATFiErrorCode2) => {
224
224
  ATFiErrorCode2["TRANSACTION_FAILED"] = "TRANSACTION_FAILED";
225
225
  ATFiErrorCode2["CONTRACT_ERROR"] = "CONTRACT_ERROR";
226
226
  ATFiErrorCode2["VAULT_NOT_FOUND"] = "VAULT_NOT_FOUND";
227
+ ATFiErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
227
228
  return ATFiErrorCode2;
228
229
  })(ATFiErrorCode || {});
229
230
  var ATFiError = class extends Error {
@@ -253,7 +254,8 @@ var CONTRACT_ERROR_MAP = {
253
254
  VaultAlreadySettled: "VAULT_ALREADY_SETTLED" /* VAULT_ALREADY_SETTLED */,
254
255
  VaultNotSettled: "VAULT_NOT_SETTLED" /* VAULT_NOT_SETTLED */,
255
256
  YieldOnlySupportsUSDC: "YIELD_ONLY_USDC" /* YIELD_ONLY_USDC */,
256
- OwnableUnauthorizedAccount: "NOT_OWNER" /* NOT_OWNER */
257
+ OwnableUnauthorizedAccount: "NOT_OWNER" /* NOT_OWNER */,
258
+ NetworkError: "NETWORK_ERROR" /* NETWORK_ERROR */
257
259
  };
258
260
  function parseContractError(error) {
259
261
  if (error instanceof ATFiError) {
@@ -632,6 +634,16 @@ var ATFiSDK = class _ATFiSDK {
632
634
  */
633
635
  async createEvent(params) {
634
636
  this.ensureWallet();
637
+ if (this.walletClient && this.publicClient.chain) {
638
+ const walletChainId = await this.walletClient.getChainId();
639
+ const publicChainId = this.publicClient.chain.id;
640
+ if (walletChainId !== publicChainId) {
641
+ throw new ATFiError(
642
+ `Wrong network. Please switch to ${this.publicClient.chain.name} (Chain ID: ${publicChainId})`,
643
+ "NETWORK_ERROR" /* NETWORK_ERROR */
644
+ );
645
+ }
646
+ }
635
647
  const simulation = await this._simulateCreateEvent(params);
636
648
  return {
637
649
  simulation,
@@ -723,6 +735,20 @@ var ATFiSDK = class _ATFiSDK {
723
735
  }
724
736
  };
725
737
  }
738
+ /**
739
+ * Approve token spending
740
+ */
741
+ async approve(token, spender, amount) {
742
+ const wallet = this.ensureWallet();
743
+ return wallet.writeContract({
744
+ address: token,
745
+ abi: ERC20ABI,
746
+ functionName: "approve",
747
+ account: wallet.account,
748
+ args: [spender, amount],
749
+ chain: null
750
+ });
751
+ }
726
752
  // ============ Read Functions ============
727
753
  /**
728
754
  * Get detailed event information
@@ -1046,6 +1072,17 @@ var ATFiSDK = class _ATFiSDK {
1046
1072
  needsApproval
1047
1073
  };
1048
1074
  }
1075
+ if (needsApproval) {
1076
+ return {
1077
+ success: true,
1078
+ needsApproval: true,
1079
+ gasEstimate: 0n,
1080
+ // Cannot estimate register gas yet
1081
+ ...baseResult,
1082
+ userBalance: fromTokenUnits(balance, decimals),
1083
+ currentAllowance: fromTokenUnits(allowance, decimals)
1084
+ };
1085
+ }
1049
1086
  await this.publicClient.simulateContract({ address: vaultAddress, abi: VaultATFiABI, functionName: "stake", account });
1050
1087
  const gasEstimate = await this.publicClient.estimateContractGas({ address: vaultAddress, abi: VaultATFiABI, functionName: "stake", account });
1051
1088
  return {
@@ -1053,7 +1090,7 @@ var ATFiSDK = class _ATFiSDK {
1053
1090
  ...baseResult,
1054
1091
  userBalance: fromTokenUnits(balance, decimals),
1055
1092
  currentAllowance: fromTokenUnits(allowance, decimals),
1056
- needsApproval,
1093
+ needsApproval: false,
1057
1094
  gasEstimate
1058
1095
  };
1059
1096
  } catch (error) {
package/dist/index.mjs CHANGED
@@ -173,6 +173,7 @@ var ATFiErrorCode = /* @__PURE__ */ ((ATFiErrorCode2) => {
173
173
  ATFiErrorCode2["TRANSACTION_FAILED"] = "TRANSACTION_FAILED";
174
174
  ATFiErrorCode2["CONTRACT_ERROR"] = "CONTRACT_ERROR";
175
175
  ATFiErrorCode2["VAULT_NOT_FOUND"] = "VAULT_NOT_FOUND";
176
+ ATFiErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
176
177
  return ATFiErrorCode2;
177
178
  })(ATFiErrorCode || {});
178
179
  var ATFiError = class extends Error {
@@ -202,7 +203,8 @@ var CONTRACT_ERROR_MAP = {
202
203
  VaultAlreadySettled: "VAULT_ALREADY_SETTLED" /* VAULT_ALREADY_SETTLED */,
203
204
  VaultNotSettled: "VAULT_NOT_SETTLED" /* VAULT_NOT_SETTLED */,
204
205
  YieldOnlySupportsUSDC: "YIELD_ONLY_USDC" /* YIELD_ONLY_USDC */,
205
- OwnableUnauthorizedAccount: "NOT_OWNER" /* NOT_OWNER */
206
+ OwnableUnauthorizedAccount: "NOT_OWNER" /* NOT_OWNER */,
207
+ NetworkError: "NETWORK_ERROR" /* NETWORK_ERROR */
206
208
  };
207
209
  function parseContractError(error) {
208
210
  if (error instanceof ATFiError) {
@@ -581,6 +583,16 @@ var ATFiSDK = class _ATFiSDK {
581
583
  */
582
584
  async createEvent(params) {
583
585
  this.ensureWallet();
586
+ if (this.walletClient && this.publicClient.chain) {
587
+ const walletChainId = await this.walletClient.getChainId();
588
+ const publicChainId = this.publicClient.chain.id;
589
+ if (walletChainId !== publicChainId) {
590
+ throw new ATFiError(
591
+ `Wrong network. Please switch to ${this.publicClient.chain.name} (Chain ID: ${publicChainId})`,
592
+ "NETWORK_ERROR" /* NETWORK_ERROR */
593
+ );
594
+ }
595
+ }
584
596
  const simulation = await this._simulateCreateEvent(params);
585
597
  return {
586
598
  simulation,
@@ -672,6 +684,20 @@ var ATFiSDK = class _ATFiSDK {
672
684
  }
673
685
  };
674
686
  }
687
+ /**
688
+ * Approve token spending
689
+ */
690
+ async approve(token, spender, amount) {
691
+ const wallet = this.ensureWallet();
692
+ return wallet.writeContract({
693
+ address: token,
694
+ abi: ERC20ABI,
695
+ functionName: "approve",
696
+ account: wallet.account,
697
+ args: [spender, amount],
698
+ chain: null
699
+ });
700
+ }
675
701
  // ============ Read Functions ============
676
702
  /**
677
703
  * Get detailed event information
@@ -995,6 +1021,17 @@ var ATFiSDK = class _ATFiSDK {
995
1021
  needsApproval
996
1022
  };
997
1023
  }
1024
+ if (needsApproval) {
1025
+ return {
1026
+ success: true,
1027
+ needsApproval: true,
1028
+ gasEstimate: 0n,
1029
+ // Cannot estimate register gas yet
1030
+ ...baseResult,
1031
+ userBalance: fromTokenUnits(balance, decimals),
1032
+ currentAllowance: fromTokenUnits(allowance, decimals)
1033
+ };
1034
+ }
998
1035
  await this.publicClient.simulateContract({ address: vaultAddress, abi: VaultATFiABI, functionName: "stake", account });
999
1036
  const gasEstimate = await this.publicClient.estimateContractGas({ address: vaultAddress, abi: VaultATFiABI, functionName: "stake", account });
1000
1037
  return {
@@ -1002,7 +1039,7 @@ var ATFiSDK = class _ATFiSDK {
1002
1039
  ...baseResult,
1003
1040
  userBalance: fromTokenUnits(balance, decimals),
1004
1041
  currentAllowance: fromTokenUnits(allowance, decimals),
1005
- needsApproval,
1042
+ needsApproval: false,
1006
1043
  gasEstimate
1007
1044
  };
1008
1045
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atfi",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "TypeScript SDK for ATFi commitment vaults on Base",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",