@agether/sdk 2.3.0 → 2.3.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.
package/dist/cli.js CHANGED
@@ -887,9 +887,20 @@ var init_MorphoClient = __esm({
887
887
  const weiAmount = import_ethers.ethers.parseUnits(amount, colInfo.decimals);
888
888
  const morphoAddr = this.config.contracts.morphoBlue;
889
889
  const colToken = new import_ethers.Contract(colInfo.address, ERC20_ABI, this._signer);
890
- const transferTx = await colToken.transfer(acctAddr, weiAmount);
891
- await transferTx.wait();
892
- this._refreshSigner();
890
+ const acctBalance = await colToken.balanceOf(acctAddr);
891
+ if (acctBalance < weiAmount) {
892
+ const shortfall = weiAmount - acctBalance;
893
+ const eoaBalance = await colToken.balanceOf(await this.getSignerAddress());
894
+ if (eoaBalance < shortfall) {
895
+ throw new AgetherError(
896
+ `Insufficient ${tokenSymbol}. Need ${amount}, AgentAccount has ${import_ethers.ethers.formatUnits(acctBalance, colInfo.decimals)}, EOA has ${import_ethers.ethers.formatUnits(eoaBalance, colInfo.decimals)}.`,
897
+ "INSUFFICIENT_BALANCE"
898
+ );
899
+ }
900
+ const transferTx = await colToken.transfer(acctAddr, shortfall);
901
+ await transferTx.wait();
902
+ this._refreshSigner();
903
+ }
893
904
  const targets = [colInfo.address, morphoAddr];
894
905
  const values = [0n, 0n];
895
906
  const datas = [
@@ -964,9 +975,20 @@ var init_MorphoClient = __esm({
964
975
  const borrowWei = import_ethers.ethers.parseUnits(borrowUsdcAmount, 6);
965
976
  const morphoAddr = this.config.contracts.morphoBlue;
966
977
  const colToken = new import_ethers.Contract(colInfo.address, ERC20_ABI, this._signer);
967
- const transferTx = await colToken.transfer(acctAddr, colWei);
968
- await transferTx.wait();
969
- this._refreshSigner();
978
+ const acctBalance = await colToken.balanceOf(acctAddr);
979
+ if (acctBalance < colWei) {
980
+ const shortfall = colWei - acctBalance;
981
+ const eoaBalance = await colToken.balanceOf(await this.getSignerAddress());
982
+ if (eoaBalance < shortfall) {
983
+ throw new AgetherError(
984
+ `Insufficient ${tokenSymbol}. Need ${collateralAmount}, AgentAccount has ${import_ethers.ethers.formatUnits(acctBalance, colInfo.decimals)}, EOA has ${import_ethers.ethers.formatUnits(eoaBalance, colInfo.decimals)}.`,
985
+ "INSUFFICIENT_BALANCE"
986
+ );
987
+ }
988
+ const transferTx = await colToken.transfer(acctAddr, shortfall);
989
+ await transferTx.wait();
990
+ this._refreshSigner();
991
+ }
970
992
  const targets = [colInfo.address, morphoAddr, morphoAddr];
971
993
  const values = [0n, 0n, 0n];
972
994
  const datas = [
package/dist/index.js CHANGED
@@ -1136,9 +1136,20 @@ var MorphoClient = class {
1136
1136
  const weiAmount = import_ethers2.ethers.parseUnits(amount, colInfo.decimals);
1137
1137
  const morphoAddr = this.config.contracts.morphoBlue;
1138
1138
  const colToken = new import_ethers2.Contract(colInfo.address, ERC20_ABI, this._signer);
1139
- const transferTx = await colToken.transfer(acctAddr, weiAmount);
1140
- await transferTx.wait();
1141
- this._refreshSigner();
1139
+ const acctBalance = await colToken.balanceOf(acctAddr);
1140
+ if (acctBalance < weiAmount) {
1141
+ const shortfall = weiAmount - acctBalance;
1142
+ const eoaBalance = await colToken.balanceOf(await this.getSignerAddress());
1143
+ if (eoaBalance < shortfall) {
1144
+ throw new AgetherError(
1145
+ `Insufficient ${tokenSymbol}. Need ${amount}, AgentAccount has ${import_ethers2.ethers.formatUnits(acctBalance, colInfo.decimals)}, EOA has ${import_ethers2.ethers.formatUnits(eoaBalance, colInfo.decimals)}.`,
1146
+ "INSUFFICIENT_BALANCE"
1147
+ );
1148
+ }
1149
+ const transferTx = await colToken.transfer(acctAddr, shortfall);
1150
+ await transferTx.wait();
1151
+ this._refreshSigner();
1152
+ }
1142
1153
  const targets = [colInfo.address, morphoAddr];
1143
1154
  const values = [0n, 0n];
1144
1155
  const datas = [
@@ -1213,9 +1224,20 @@ var MorphoClient = class {
1213
1224
  const borrowWei = import_ethers2.ethers.parseUnits(borrowUsdcAmount, 6);
1214
1225
  const morphoAddr = this.config.contracts.morphoBlue;
1215
1226
  const colToken = new import_ethers2.Contract(colInfo.address, ERC20_ABI, this._signer);
1216
- const transferTx = await colToken.transfer(acctAddr, colWei);
1217
- await transferTx.wait();
1218
- this._refreshSigner();
1227
+ const acctBalance = await colToken.balanceOf(acctAddr);
1228
+ if (acctBalance < colWei) {
1229
+ const shortfall = colWei - acctBalance;
1230
+ const eoaBalance = await colToken.balanceOf(await this.getSignerAddress());
1231
+ if (eoaBalance < shortfall) {
1232
+ throw new AgetherError(
1233
+ `Insufficient ${tokenSymbol}. Need ${collateralAmount}, AgentAccount has ${import_ethers2.ethers.formatUnits(acctBalance, colInfo.decimals)}, EOA has ${import_ethers2.ethers.formatUnits(eoaBalance, colInfo.decimals)}.`,
1234
+ "INSUFFICIENT_BALANCE"
1235
+ );
1236
+ }
1237
+ const transferTx = await colToken.transfer(acctAddr, shortfall);
1238
+ await transferTx.wait();
1239
+ this._refreshSigner();
1240
+ }
1219
1241
  const targets = [colInfo.address, morphoAddr, morphoAddr];
1220
1242
  const values = [0n, 0n, 0n];
1221
1243
  const datas = [
package/dist/index.mjs CHANGED
@@ -1064,9 +1064,20 @@ var MorphoClient = class {
1064
1064
  const weiAmount = ethers2.parseUnits(amount, colInfo.decimals);
1065
1065
  const morphoAddr = this.config.contracts.morphoBlue;
1066
1066
  const colToken = new Contract2(colInfo.address, ERC20_ABI, this._signer);
1067
- const transferTx = await colToken.transfer(acctAddr, weiAmount);
1068
- await transferTx.wait();
1069
- this._refreshSigner();
1067
+ const acctBalance = await colToken.balanceOf(acctAddr);
1068
+ if (acctBalance < weiAmount) {
1069
+ const shortfall = weiAmount - acctBalance;
1070
+ const eoaBalance = await colToken.balanceOf(await this.getSignerAddress());
1071
+ if (eoaBalance < shortfall) {
1072
+ throw new AgetherError(
1073
+ `Insufficient ${tokenSymbol}. Need ${amount}, AgentAccount has ${ethers2.formatUnits(acctBalance, colInfo.decimals)}, EOA has ${ethers2.formatUnits(eoaBalance, colInfo.decimals)}.`,
1074
+ "INSUFFICIENT_BALANCE"
1075
+ );
1076
+ }
1077
+ const transferTx = await colToken.transfer(acctAddr, shortfall);
1078
+ await transferTx.wait();
1079
+ this._refreshSigner();
1080
+ }
1070
1081
  const targets = [colInfo.address, morphoAddr];
1071
1082
  const values = [0n, 0n];
1072
1083
  const datas = [
@@ -1141,9 +1152,20 @@ var MorphoClient = class {
1141
1152
  const borrowWei = ethers2.parseUnits(borrowUsdcAmount, 6);
1142
1153
  const morphoAddr = this.config.contracts.morphoBlue;
1143
1154
  const colToken = new Contract2(colInfo.address, ERC20_ABI, this._signer);
1144
- const transferTx = await colToken.transfer(acctAddr, colWei);
1145
- await transferTx.wait();
1146
- this._refreshSigner();
1155
+ const acctBalance = await colToken.balanceOf(acctAddr);
1156
+ if (acctBalance < colWei) {
1157
+ const shortfall = colWei - acctBalance;
1158
+ const eoaBalance = await colToken.balanceOf(await this.getSignerAddress());
1159
+ if (eoaBalance < shortfall) {
1160
+ throw new AgetherError(
1161
+ `Insufficient ${tokenSymbol}. Need ${collateralAmount}, AgentAccount has ${ethers2.formatUnits(acctBalance, colInfo.decimals)}, EOA has ${ethers2.formatUnits(eoaBalance, colInfo.decimals)}.`,
1162
+ "INSUFFICIENT_BALANCE"
1163
+ );
1164
+ }
1165
+ const transferTx = await colToken.transfer(acctAddr, shortfall);
1166
+ await transferTx.wait();
1167
+ this._refreshSigner();
1168
+ }
1147
1169
  const targets = [colInfo.address, morphoAddr, morphoAddr];
1148
1170
  const values = [0n, 0n, 0n];
1149
1171
  const datas = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agether/sdk",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "TypeScript SDK for Agether - autonomous credit for AI agents on Base",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",