@ardrive/turbo-sdk 1.34.0-alpha.1 → 1.34.0-alpha.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.
Files changed (44) hide show
  1. package/README.md +40 -5
  2. package/bundles/web.bundle.min.js +219 -22
  3. package/lib/cjs/common/signer.js +3 -0
  4. package/lib/cjs/common/token/baseEth.js +7 -6
  5. package/lib/cjs/common/token/erc20.js +91 -0
  6. package/lib/cjs/common/token/ethereum.js +7 -6
  7. package/lib/cjs/common/token/index.js +11 -0
  8. package/lib/cjs/common/token/polygon.js +7 -6
  9. package/lib/cjs/common/token/usdc.js +83 -0
  10. package/lib/cjs/common/upload.js +6 -1
  11. package/lib/cjs/types.js +3 -0
  12. package/lib/cjs/utils/common.js +19 -4
  13. package/lib/cjs/version.js +1 -1
  14. package/lib/esm/common/signer.js +3 -0
  15. package/lib/esm/common/token/baseEth.js +6 -5
  16. package/lib/esm/common/token/erc20.js +87 -0
  17. package/lib/esm/common/token/ethereum.js +6 -5
  18. package/lib/esm/common/token/index.js +11 -0
  19. package/lib/esm/common/token/polygon.js +6 -5
  20. package/lib/esm/common/token/usdc.js +76 -0
  21. package/lib/esm/common/upload.js +6 -1
  22. package/lib/esm/types.js +3 -0
  23. package/lib/esm/utils/common.js +19 -4
  24. package/lib/esm/version.js +1 -1
  25. package/lib/types/common/signer.d.ts +1 -1
  26. package/lib/types/common/signer.d.ts.map +1 -1
  27. package/lib/types/common/token/baseEth.d.ts +5 -0
  28. package/lib/types/common/token/baseEth.d.ts.map +1 -1
  29. package/lib/types/common/token/erc20.d.ts +19 -0
  30. package/lib/types/common/token/erc20.d.ts.map +1 -0
  31. package/lib/types/common/token/ethereum.d.ts +1 -0
  32. package/lib/types/common/token/ethereum.d.ts.map +1 -1
  33. package/lib/types/common/token/index.d.ts.map +1 -1
  34. package/lib/types/common/token/polygon.d.ts +5 -0
  35. package/lib/types/common/token/polygon.d.ts.map +1 -1
  36. package/lib/types/common/token/usdc.d.ts +36 -0
  37. package/lib/types/common/token/usdc.d.ts.map +1 -0
  38. package/lib/types/common/upload.d.ts.map +1 -1
  39. package/lib/types/types.d.ts +3 -2
  40. package/lib/types/types.d.ts.map +1 -1
  41. package/lib/types/utils/common.d.ts.map +1 -1
  42. package/lib/types/version.d.ts +1 -1
  43. package/lib/types/version.d.ts.map +1 -1
  44. package/package.json +1 -1
package/README.md CHANGED
@@ -340,11 +340,11 @@ const turbo = TurboFactory.authenticated({
340
340
  }
341
341
  });
342
342
 
343
- // Ethereum Holesky
343
+ // Ethereum Sepolia
344
344
  const turbo = TurboFactory.authenticated({
345
- privateKey: process.env.HOLESKY_PRIVATE_KEY,
345
+ privateKey: process.env.SEPOLIA_PRIVATE_KEY,
346
346
  token: 'ethereum',
347
- gatewayUrl: 'https://ethereum-holesky-rpc.publicnode.com',
347
+ gatewayUrl: 'https://eth-sepolia.public.blastapi.io',
348
348
  paymentServiceConfig: {
349
349
  url: 'https://payment.ardrive.dev',
350
350
  },
@@ -358,7 +358,7 @@ const turbo = TurboFactory.authenticated({
358
358
 
359
359
  - **Base Sepolia** (`base-eth`) - Supports on-demand funding
360
360
  - **Solana Devnet** (`solana`) - Supports on-demand funding
361
- - **Ethereum Holesky** (`ethereum`) - Manual top-up only
361
+ - **Ethereum Sepolia** (`ethereum`) - Manual top-up only
362
362
  - **Polygon Amoy** (`pol`) - Manual top-up only
363
363
 
364
364
  ### TurboUnauthenticatedClient
@@ -730,7 +730,7 @@ With the upload methods, you can choose to Top Up with selected crypto token on
730
730
 
731
731
  This is done by providing the `OnDemandFunding` class to the `fundingMode` parameter on upload methods. The `maxTokenAmount` (optional) is the maximum amount of tokens in the token type's smallest unit value (e.g: Winston for arweave token type) to fund the wallet with. The `topUpBufferMultiplier` (optional) is the multiplier to apply to the estimated top-up amount to avoid underpayment during on-demand top-ups due to price fluctuations on longer uploads. Defaults to 1.1, meaning a 10% buffer.
732
732
 
733
- Note: On demand API currently only available for $ARIO (`ario`), $SOL (`solana`), and $ETH on Base Network (`base-eth`) token types.
733
+ Note: On demand API currently only available for $ARIO (`ario`), $SOL (`solana`), $ETH on Base Network (`base-eth`) and $USDC on Base Network (`base-usdc`) token types.
734
734
 
735
735
  ```typescript
736
736
  const turbo = TurboFactory.authenticated({
@@ -899,6 +899,36 @@ const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
899
899
  });
900
900
  ```
901
901
 
902
+ ##### USDC Crypto Top Up
903
+
904
+ ```typescript
905
+
906
+ // USDC on Ethereum Mainnet
907
+ const { winc, status, id, ...fundResult } = await TurboFactory.authenticated({
908
+ signer,
909
+ token: 'usdc',
910
+ }).topUpWithTokens({
911
+ tokenAmount: USDCToTokenAmount(1), // 1 USDC
912
+ });
913
+
914
+ // USDC on Base Network
915
+ const { winc, status, id, ...fundResult } = await TurboFactory.authenticated({
916
+ signer,
917
+ token: 'base-usdc',
918
+ }).topUpWithTokens({
919
+ tokenAmount: USDCToTokenAmount(1), // 1 USDC
920
+ });
921
+
922
+
923
+ // USDC on Polygon Network
924
+ const { winc, status, id, ...fundResult } = await TurboFactory.authenticated({
925
+ signer,
926
+ token: 'polygon-usdc',
927
+ }).topUpWithTokens({
928
+ tokenAmount: USDCToTokenAmount(1), // 1 USDC
929
+ });
930
+ ```
931
+
902
932
  ##### Ethereum (ETH) Crypto Top Up
903
933
 
904
934
  ```typescript
@@ -1191,6 +1221,11 @@ Command Options:
1191
1221
 
1192
1222
  e.g:
1193
1223
 
1224
+ ```shell
1225
+ # Fund any valid destination wallet with 10 USDC worth of Turbo Credits on Base Network
1226
+ turbo crypto-fund --value 10 --token base-usdc --private-key '0xabc...123' --address 'any-valid-evm-sol-ar-kyve-native-address'
1227
+ ```
1228
+
1194
1229
  ```shell
1195
1230
  turbo crypto-fund --value 0.0001 --token kyve --private-key 'b27...45c'
1196
1231
  ```
@@ -222361,7 +222361,10 @@ var tokenTypes = [
222361
222361
  "kyve",
222362
222362
  "matic",
222363
222363
  "pol",
222364
- "base-eth"
222364
+ "base-eth",
222365
+ "usdc",
222366
+ "base-usdc",
222367
+ "polygon-usdc"
222365
222368
  ];
222366
222369
  var ExistingBalanceFunding = class {
222367
222370
  };
@@ -222423,7 +222426,7 @@ var import_winston = __toESM(require_winston(), 1);
222423
222426
  init_dirname();
222424
222427
  init_buffer2();
222425
222428
  init_process2();
222426
- var version21 = "1.33.1-alpha.1";
222429
+ var version21 = "1.33.1";
222427
222430
 
222428
222431
  // src/common/logger.ts
222429
222432
  var TurboWinstonLogger = class _TurboWinstonLogger {
@@ -259254,6 +259257,24 @@ var wordlists2 = {
259254
259257
  function sleep2(ms2) {
259255
259258
  return new Promise((resolve3) => setTimeout(resolve3, ms2));
259256
259259
  }
259260
+ var ethTestnetRpc = "https://eth-sepolia.public.blastapi.io";
259261
+ var baseTestnetRpc = "https://sepolia.base.org";
259262
+ var polygonTestnetRpc = "https://rpc-amoy.polygon.technology";
259263
+ var tokenToDevGatewayMap = {
259264
+ arweave: "https://arweave.net",
259265
+ // No arweave test net
259266
+ ario: "https://arweave.net",
259267
+ // No arweave test net
259268
+ solana: "https://api.devnet.solana.com",
259269
+ ethereum: ethTestnetRpc,
259270
+ "base-eth": baseTestnetRpc,
259271
+ kyve: "https://api.korellia.kyve.network",
259272
+ matic: polygonTestnetRpc,
259273
+ pol: polygonTestnetRpc,
259274
+ usdc: ethTestnetRpc,
259275
+ "base-usdc": baseTestnetRpc,
259276
+ "polygon-usdc": polygonTestnetRpc
259277
+ };
259257
259278
  var defaultProdGatewayUrls = {
259258
259279
  arweave: "https://arweave.net",
259259
259280
  ario: "https://arweave.net",
@@ -259262,7 +259283,10 @@ var defaultProdGatewayUrls = {
259262
259283
  "base-eth": "https://mainnet.base.org",
259263
259284
  kyve: "https://api.kyve.network/",
259264
259285
  matic: "https://polygon-rpc.com/",
259265
- pol: "https://polygon-rpc.com/"
259286
+ pol: "https://polygon-rpc.com/",
259287
+ usdc: "https://cloudflare-eth.com/",
259288
+ "base-usdc": "https://mainnet.base.org",
259289
+ "polygon-usdc": "https://polygon-rpc.com/"
259266
259290
  };
259267
259291
  var defaultProdAoConfigs = {
259268
259292
  ario: {
@@ -259297,6 +259321,9 @@ function createTurboSigner({
259297
259321
  case "pol":
259298
259322
  case "matic":
259299
259323
  case "base-eth":
259324
+ case "usdc":
259325
+ case "base-usdc":
259326
+ case "polygon-usdc":
259300
259327
  if (!isEthPrivateKey(clientProvidedPrivateKey)) {
259301
259328
  throw new Error(
259302
259329
  "A valid Ethereum private key must be provided for EthereumSigner."
@@ -259354,6 +259381,9 @@ function isValidUserAddress(address, type4) {
259354
259381
  case "base-eth":
259355
259382
  case "matic":
259356
259383
  case "pol":
259384
+ case "base-usdc":
259385
+ case "usdc":
259386
+ case "polygon-usdc":
259357
259387
  return isValidECDSAAddress(address);
259358
259388
  case "kyve":
259359
259389
  return isValidKyveAddress(address);
@@ -273336,15 +273366,16 @@ init_buffer2();
273336
273366
  init_process2();
273337
273367
  var weiToTokenAmount = (wei) => wei;
273338
273368
  var ETHToTokenAmount = (eth) => new BigNumber2(eth).times(1e18).valueOf();
273369
+ var defaultEthereumPollingOptions = {
273370
+ initialBackoffMs: 25e3,
273371
+ maxAttempts: 10,
273372
+ pollingIntervalMs: 1500
273373
+ };
273339
273374
  var EthereumToken = class {
273340
273375
  constructor({
273341
273376
  logger: logger19 = TurboWinstonLogger.default,
273342
273377
  gatewayUrl = defaultProdGatewayUrls.ethereum,
273343
- pollingOptions = {
273344
- maxAttempts: 10,
273345
- pollingIntervalMs: 4e3,
273346
- initialBackoffMs: 25e3
273347
- }
273378
+ pollingOptions = defaultEthereumPollingOptions
273348
273379
  } = {}) {
273349
273380
  this.logger = logger19;
273350
273381
  this.gatewayUrl = gatewayUrl;
@@ -273422,15 +273453,16 @@ function ethDataFromTurboCreditDestinationAddress(turboCreditDestinationAddress)
273422
273453
  }
273423
273454
 
273424
273455
  // src/common/token/baseEth.ts
273456
+ var defaultBaseNetworkPollingOptions = {
273457
+ initialBackoffMs: 2500,
273458
+ maxAttempts: 10,
273459
+ pollingIntervalMs: 750
273460
+ };
273425
273461
  var BaseEthToken = class extends EthereumToken {
273426
273462
  constructor({
273427
273463
  logger: logger19,
273428
273464
  gatewayUrl = defaultProdGatewayUrls["base-eth"],
273429
- pollingOptions = {
273430
- initialBackoffMs: 2500,
273431
- maxAttempts: 10,
273432
- pollingIntervalMs: 2500
273433
- }
273465
+ pollingOptions = defaultBaseNetworkPollingOptions
273434
273466
  } = {}) {
273435
273467
  super({
273436
273468
  logger: logger19,
@@ -273678,15 +273710,16 @@ init_dirname();
273678
273710
  init_buffer2();
273679
273711
  init_process2();
273680
273712
  var POLToTokenAmount = ETHToTokenAmount;
273713
+ var defaultPolygonPollingOptions = {
273714
+ maxAttempts: 10,
273715
+ initialBackoffMs: 5e3,
273716
+ pollingIntervalMs: 1e3
273717
+ };
273681
273718
  var PolygonToken = class extends EthereumToken {
273682
273719
  constructor({
273683
273720
  logger: logger19 = TurboWinstonLogger.default,
273684
273721
  gatewayUrl = defaultProdGatewayUrls.pol,
273685
- pollingOptions = {
273686
- maxAttempts: 10,
273687
- pollingIntervalMs: 4e3,
273688
- initialBackoffMs: 5e3
273689
- }
273722
+ pollingOptions = defaultPolygonPollingOptions
273690
273723
  } = {}) {
273691
273724
  super({ logger: logger19, gatewayUrl, pollingOptions });
273692
273725
  }
@@ -273817,6 +273850,149 @@ var SolanaToken = class {
273817
273850
  }
273818
273851
  };
273819
273852
 
273853
+ // src/common/token/usdc.ts
273854
+ init_dirname();
273855
+ init_buffer2();
273856
+ init_process2();
273857
+
273858
+ // src/common/token/erc20.ts
273859
+ init_dirname();
273860
+ init_buffer2();
273861
+ init_process2();
273862
+ var ERC20Token = class extends EthereumToken {
273863
+ constructor({
273864
+ tokenContractAddress,
273865
+ logger: logger19 = TurboWinstonLogger.default,
273866
+ gatewayUrl = defaultProdGatewayUrls.ethereum,
273867
+ pollingOptions
273868
+ }) {
273869
+ super({ logger: logger19, gatewayUrl, pollingOptions });
273870
+ this.tokenContract = new ethers_exports.Contract(
273871
+ tokenContractAddress,
273872
+ [
273873
+ "function decimals() view returns (uint8)",
273874
+ "function balanceOf(address) view returns (uint256)",
273875
+ "function transfer(address to, uint256 value) returns (bool)"
273876
+ ],
273877
+ this.rpcProvider
273878
+ );
273879
+ }
273880
+ async createAndSubmitTx({
273881
+ target,
273882
+ tokenAmount,
273883
+ signer,
273884
+ turboCreditDestinationAddress
273885
+ }) {
273886
+ try {
273887
+ let connected;
273888
+ let walletOrSigner;
273889
+ if (signer.signer instanceof EthereumSigner) {
273890
+ const provider = new JsonRpcProvider(this.gatewayUrl);
273891
+ const keyHex = Buffer2.from(signer.signer.key).toString("hex");
273892
+ walletOrSigner = new Wallet2(keyHex, provider);
273893
+ connected = this.tokenContract.connect(walletOrSigner);
273894
+ } else if (signer.walletAdapter !== void 0 && isEthereumWalletAdapter(signer.walletAdapter)) {
273895
+ walletOrSigner = signer.walletAdapter.getSigner();
273896
+ connected = this.tokenContract.connect(walletOrSigner);
273897
+ } else {
273898
+ throw new Error(
273899
+ "Unsupported signer -- must be EthereumSigner or have a walletAdapter implementing getSigner"
273900
+ );
273901
+ }
273902
+ const baseTransferData = connected.interface.encodeFunctionData(
273903
+ "transfer",
273904
+ [target, tokenAmount.toString()]
273905
+ );
273906
+ let finalData = baseTransferData;
273907
+ const memoData = ethDataFromTurboCreditDestinationAddress(
273908
+ turboCreditDestinationAddress
273909
+ );
273910
+ if (memoData !== void 0) {
273911
+ finalData += memoData.slice(2);
273912
+ }
273913
+ const txRequest = {
273914
+ to: await connected.getAddress(),
273915
+ data: finalData
273916
+ };
273917
+ this.logger.debug("Submitting ERC20 transfer", {
273918
+ target,
273919
+ tokenAmount: tokenAmount.toString(),
273920
+ rpcEndpoint: this.gatewayUrl,
273921
+ txRequest
273922
+ });
273923
+ const tx = await walletOrSigner.sendTransaction(txRequest);
273924
+ this.logger.debug("ERC20 transfer submitted", {
273925
+ txHash: tx.hash,
273926
+ target,
273927
+ tx
273928
+ });
273929
+ return { id: tx.hash, target };
273930
+ } catch (e12) {
273931
+ this.logger.error("Error creating/submitting ERC20 tx", {
273932
+ error: e12 instanceof Error ? e12.message : e12,
273933
+ target,
273934
+ tokenAmount,
273935
+ rpcEndpoint: this.gatewayUrl
273936
+ });
273937
+ throw e12;
273938
+ }
273939
+ }
273940
+ };
273941
+
273942
+ // src/common/token/usdc.ts
273943
+ var usdcNetworks = (useDevnet = false) => ({
273944
+ ethereum: {
273945
+ tokenContractAddress: useDevnet ? ethSepoliaUsdcAddress : ethMainnetUsdcAddress,
273946
+ rpcEndpoint: useDevnet ? tokenToDevGatewayMap.ethereum : defaultProdGatewayUrls.ethereum,
273947
+ defaultPollingOptions: defaultEthereumPollingOptions
273948
+ },
273949
+ base: {
273950
+ tokenContractAddress: useDevnet ? baseSepoliaUsdcAddress : baseMainnetUsdcAddress,
273951
+ rpcEndpoint: useDevnet ? tokenToDevGatewayMap["base-eth"] : defaultProdGatewayUrls["base-eth"],
273952
+ defaultPollingOptions: defaultBaseNetworkPollingOptions
273953
+ },
273954
+ polygon: {
273955
+ tokenContractAddress: useDevnet ? polygonAmoyUsdcAddress : polygonMainnetUsdcAddress,
273956
+ rpcEndpoint: useDevnet ? tokenToDevGatewayMap.pol : defaultProdGatewayUrls.pol,
273957
+ defaultPollingOptions: defaultPolygonPollingOptions
273958
+ }
273959
+ });
273960
+ var ethMainnetUsdcAddress = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
273961
+ var baseMainnetUsdcAddress = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
273962
+ var polygonMainnetUsdcAddress = "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359";
273963
+ var ethSepoliaUsdcAddress = "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238";
273964
+ var baseSepoliaUsdcAddress = "0x036CbD53842c5426634e7929541eC2318f3dCF7e";
273965
+ var polygonAmoyUsdcAddress = "0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582";
273966
+ var USDCToTokenAmount = (usdc) => new BigNumber2(usdc).times(1e6).valueOf();
273967
+ var USDCToken = class extends ERC20Token {
273968
+ constructor({
273969
+ network = "ethereum",
273970
+ logger: logger19,
273971
+ gatewayUrl,
273972
+ tokenContractAddress,
273973
+ pollingOptions,
273974
+ useDevnet
273975
+ } = {}) {
273976
+ if (useDevnet === void 0) {
273977
+ const keywords = ["sepolia", "amoy"];
273978
+ useDevnet = keywords.some(
273979
+ (keyword) => (gatewayUrl ?? "").toLowerCase().includes(keyword)
273980
+ );
273981
+ }
273982
+ const {
273983
+ tokenContractAddress: usdcContractAddress,
273984
+ rpcEndpoint,
273985
+ defaultPollingOptions
273986
+ } = usdcNetworks(useDevnet)[network];
273987
+ super({
273988
+ tokenContractAddress: tokenContractAddress ?? usdcContractAddress,
273989
+ logger: logger19,
273990
+ gatewayUrl: gatewayUrl ?? rpcEndpoint,
273991
+ pollingOptions: pollingOptions ?? defaultPollingOptions
273992
+ });
273993
+ }
273994
+ };
273995
+
273820
273996
  // src/common/token/index.ts
273821
273997
  var defaultTokenMap = {
273822
273998
  arweave: (config2) => new ArweaveToken(config2),
@@ -273826,9 +274002,13 @@ var defaultTokenMap = {
273826
274002
  "base-eth": (config2) => new BaseEthToken(config2),
273827
274003
  kyve: (config2) => new KyveToken(config2),
273828
274004
  matic: (config2) => new PolygonToken(config2),
273829
- pol: (config2) => new PolygonToken(config2)
274005
+ pol: (config2) => new PolygonToken(config2),
274006
+ usdc: (config2) => new USDCToken({ network: "ethereum", ...config2 }),
274007
+ "base-usdc": (config2) => new USDCToken({ network: "base", ...config2 }),
274008
+ "polygon-usdc": (config2) => new USDCToken({ network: "polygon", ...config2 })
273830
274009
  };
273831
274010
  var ethExponent = 18;
274011
+ var usdcExponent = 6;
273832
274012
  var exponentMap = {
273833
274013
  arweave: 12,
273834
274014
  ario: 6,
@@ -273837,7 +274017,10 @@ var exponentMap = {
273837
274017
  "base-eth": ethExponent,
273838
274018
  kyve: 6,
273839
274019
  matic: ethExponent,
273840
- pol: ethExponent
274020
+ pol: ethExponent,
274021
+ usdc: usdcExponent,
274022
+ "base-usdc": usdcExponent,
274023
+ "polygon-usdc": usdcExponent
273841
274024
  };
273842
274025
  var tokenToBaseMap = {
273843
274026
  arweave: (a8) => ARToTokenAmount(a8),
@@ -273847,7 +274030,10 @@ var tokenToBaseMap = {
273847
274030
  "base-eth": (a8) => ETHToTokenAmount(a8),
273848
274031
  kyve: (a8) => KYVEToTokenAmount(a8),
273849
274032
  matic: (a8) => POLToTokenAmount(a8),
273850
- pol: (a8) => POLToTokenAmount(a8)
274033
+ pol: (a8) => POLToTokenAmount(a8),
274034
+ usdc: (a8) => USDCToTokenAmount(a8),
274035
+ "base-usdc": (a8) => USDCToTokenAmount(a8),
274036
+ "polygon-usdc": (a8) => USDCToTokenAmount(a8)
273851
274037
  };
273852
274038
  function isTokenType(token) {
273853
274039
  return tokenTypes.includes(token);
@@ -275133,7 +275319,12 @@ var TurboAuthenticatedBaseUploadService = class extends TurboUnauthenticatedUplo
275133
275319
  paymentService
275134
275320
  }) {
275135
275321
  super({ url, retryConfig, logger: logger19, token });
275136
- this.enabledOnDemandTokens = ["ario", "solana", "base-eth"];
275322
+ this.enabledOnDemandTokens = [
275323
+ "ario",
275324
+ "solana",
275325
+ "base-eth",
275326
+ "base-usdc"
275327
+ ];
275137
275328
  this.signer = signer;
275138
275329
  this.paymentService = paymentService;
275139
275330
  }
@@ -276107,6 +276298,9 @@ var TurboDataItemAbstractSigner = class {
276107
276298
  case "matic":
276108
276299
  case "pol":
276109
276300
  case "base-eth":
276301
+ case "usdc":
276302
+ case "base-usdc":
276303
+ case "polygon-usdc":
276110
276304
  return computeAddress2(computePublicKey(fromB64Url(owner)));
276111
276305
  case "kyve":
276112
276306
  return (0, import_amino3.pubkeyToAddress)(
@@ -276629,7 +276823,10 @@ export {
276629
276823
  createStreamWithUploadEvents,
276630
276824
  creditSharingTagNames,
276631
276825
  currencyMap,
276826
+ defaultBaseNetworkPollingOptions,
276827
+ defaultEthereumPollingOptions,
276632
276828
  defaultPaymentServiceURL,
276829
+ defaultPolygonPollingOptions,
276633
276830
  defaultTokenMap,
276634
276831
  defaultTurboConfiguration,
276635
276832
  defaultUploadServiceURL,
@@ -54,6 +54,9 @@ class TurboDataItemAbstractSigner {
54
54
  case 'matic':
55
55
  case 'pol':
56
56
  case 'base-eth':
57
+ case 'usdc':
58
+ case 'base-usdc':
59
+ case 'polygon-usdc':
57
60
  return (0, ethers_2.computeAddress)((0, signing_key_1.computePublicKey)((0, base64_js_1.fromB64Url)(owner)));
58
61
  case 'kyve':
59
62
  return (0, amino_1.pubkeyToAddress)({
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseEthToken = void 0;
3
+ exports.BaseEthToken = exports.defaultBaseNetworkPollingOptions = void 0;
4
4
  const common_js_1 = require("../../utils/common.js");
5
5
  const ethereum_js_1 = require("./ethereum.js");
6
+ exports.defaultBaseNetworkPollingOptions = {
7
+ initialBackoffMs: 2_500,
8
+ maxAttempts: 10,
9
+ pollingIntervalMs: 750,
10
+ };
6
11
  class BaseEthToken extends ethereum_js_1.EthereumToken {
7
- constructor({ logger, gatewayUrl = common_js_1.defaultProdGatewayUrls['base-eth'], pollingOptions = {
8
- initialBackoffMs: 2_500,
9
- maxAttempts: 10,
10
- pollingIntervalMs: 2_500,
11
- }, } = {}) {
12
+ constructor({ logger, gatewayUrl = common_js_1.defaultProdGatewayUrls['base-eth'], pollingOptions = exports.defaultBaseNetworkPollingOptions, } = {}) {
12
13
  super({
13
14
  logger,
14
15
  gatewayUrl,
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ERC20Token = void 0;
4
+ /**
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ const arbundles_1 = require("@dha-team/arbundles");
20
+ const ethers_1 = require("ethers");
21
+ const types_js_1 = require("../../types.js");
22
+ const common_js_1 = require("../../utils/common.js");
23
+ const logger_js_1 = require("../logger.js");
24
+ const ethereum_js_1 = require("./ethereum.js");
25
+ class ERC20Token extends ethereum_js_1.EthereumToken {
26
+ constructor({ tokenContractAddress, logger = logger_js_1.TurboWinstonLogger.default, gatewayUrl = common_js_1.defaultProdGatewayUrls.ethereum, pollingOptions, }) {
27
+ super({ logger, gatewayUrl, pollingOptions });
28
+ this.tokenContract = new ethers_1.ethers.Contract(tokenContractAddress, [
29
+ 'function decimals() view returns (uint8)',
30
+ 'function balanceOf(address) view returns (uint256)',
31
+ 'function transfer(address to, uint256 value) returns (bool)',
32
+ ], this.rpcProvider);
33
+ }
34
+ async createAndSubmitTx({ target, tokenAmount, signer, turboCreditDestinationAddress, }) {
35
+ try {
36
+ let connected;
37
+ let walletOrSigner;
38
+ if (signer.signer instanceof arbundles_1.EthereumSigner) {
39
+ const provider = new ethers_1.JsonRpcProvider(this.gatewayUrl);
40
+ // 🧩 CLI / Node path
41
+ const keyHex = Buffer.from(signer.signer.key).toString('hex');
42
+ walletOrSigner = new ethers_1.Wallet(keyHex, provider);
43
+ connected = this.tokenContract.connect(walletOrSigner);
44
+ }
45
+ else if (signer.walletAdapter !== undefined &&
46
+ (0, types_js_1.isEthereumWalletAdapter)(signer.walletAdapter)) {
47
+ walletOrSigner = signer.walletAdapter.getSigner();
48
+ connected = this.tokenContract.connect(walletOrSigner);
49
+ }
50
+ else {
51
+ throw new Error('Unsupported signer -- must be EthereumSigner or have a walletAdapter implementing getSigner');
52
+ }
53
+ // Encode transfer data
54
+ const baseTransferData = connected.interface.encodeFunctionData('transfer', [target, tokenAmount.toString()]);
55
+ let finalData = baseTransferData;
56
+ // Append optional memo data with turbo credit destination address
57
+ const memoData = (0, ethereum_js_1.ethDataFromTurboCreditDestinationAddress)(turboCreditDestinationAddress);
58
+ if (memoData !== undefined) {
59
+ // remove the "0x" prefix and append
60
+ finalData += memoData.slice(2);
61
+ }
62
+ const txRequest = {
63
+ to: await connected.getAddress(),
64
+ data: finalData,
65
+ };
66
+ this.logger.debug('Submitting ERC20 transfer', {
67
+ target,
68
+ tokenAmount: tokenAmount.toString(),
69
+ rpcEndpoint: this.gatewayUrl,
70
+ txRequest,
71
+ });
72
+ const tx = await walletOrSigner.sendTransaction(txRequest);
73
+ this.logger.debug('ERC20 transfer submitted', {
74
+ txHash: tx.hash,
75
+ target,
76
+ tx,
77
+ });
78
+ return { id: tx.hash, target };
79
+ }
80
+ catch (e) {
81
+ this.logger.error('Error creating/submitting ERC20 tx', {
82
+ error: e instanceof Error ? e.message : e,
83
+ target,
84
+ tokenAmount,
85
+ rpcEndpoint: this.gatewayUrl,
86
+ });
87
+ throw e;
88
+ }
89
+ }
90
+ }
91
+ exports.ERC20Token = ERC20Token;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EthereumToken = exports.ETHToTokenAmount = exports.weiToTokenAmount = void 0;
3
+ exports.EthereumToken = exports.defaultEthereumPollingOptions = exports.ETHToTokenAmount = exports.weiToTokenAmount = void 0;
4
4
  exports.ethDataFromTurboCreditDestinationAddress = ethDataFromTurboCreditDestinationAddress;
5
5
  /**
6
6
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
@@ -25,12 +25,13 @@ const weiToTokenAmount = (wei) => wei;
25
25
  exports.weiToTokenAmount = weiToTokenAmount;
26
26
  const ETHToTokenAmount = (eth) => new bignumber_js_1.BigNumber(eth).times(1e18).valueOf();
27
27
  exports.ETHToTokenAmount = ETHToTokenAmount;
28
+ exports.defaultEthereumPollingOptions = {
29
+ initialBackoffMs: 25_000,
30
+ maxAttempts: 10,
31
+ pollingIntervalMs: 1_500,
32
+ };
28
33
  class EthereumToken {
29
- constructor({ logger = logger_js_1.TurboWinstonLogger.default, gatewayUrl = common_js_1.defaultProdGatewayUrls.ethereum, pollingOptions = {
30
- maxAttempts: 10,
31
- pollingIntervalMs: 4_000,
32
- initialBackoffMs: 25_000,
33
- }, } = {}) {
34
+ constructor({ logger = logger_js_1.TurboWinstonLogger.default, gatewayUrl = common_js_1.defaultProdGatewayUrls.ethereum, pollingOptions = exports.defaultEthereumPollingOptions, } = {}) {
34
35
  this.logger = logger;
35
36
  this.gatewayUrl = gatewayUrl;
36
37
  this.pollingOptions = pollingOptions;
@@ -24,6 +24,7 @@ const ethereum_js_1 = require("./ethereum.js");
24
24
  const kyve_js_1 = require("./kyve.js");
25
25
  const polygon_js_1 = require("./polygon.js");
26
26
  const solana_js_1 = require("./solana.js");
27
+ const usdc_js_1 = require("./usdc.js");
27
28
  exports.defaultTokenMap = {
28
29
  arweave: (config) => new arweave_js_1.ArweaveToken(config),
29
30
  ario: (config) => new ario_js_1.ARIOToken(config),
@@ -33,8 +34,12 @@ exports.defaultTokenMap = {
33
34
  kyve: (config) => new kyve_js_1.KyveToken(config),
34
35
  matic: (config) => new polygon_js_1.PolygonToken(config),
35
36
  pol: (config) => new polygon_js_1.PolygonToken(config),
37
+ usdc: (config) => new usdc_js_1.USDCToken({ network: 'ethereum', ...config }),
38
+ 'base-usdc': (config) => new usdc_js_1.USDCToken({ network: 'base', ...config }),
39
+ 'polygon-usdc': (config) => new usdc_js_1.USDCToken({ network: 'polygon', ...config }),
36
40
  };
37
41
  const ethExponent = 18;
42
+ const usdcExponent = 6;
38
43
  exports.exponentMap = {
39
44
  arweave: 12,
40
45
  ario: 6,
@@ -44,6 +49,9 @@ exports.exponentMap = {
44
49
  kyve: 6,
45
50
  matic: ethExponent,
46
51
  pol: ethExponent,
52
+ usdc: usdcExponent,
53
+ 'base-usdc': usdcExponent,
54
+ 'polygon-usdc': usdcExponent,
47
55
  };
48
56
  exports.tokenToBaseMap = {
49
57
  arweave: (a) => (0, arweave_js_1.ARToTokenAmount)(a),
@@ -54,6 +62,9 @@ exports.tokenToBaseMap = {
54
62
  kyve: (a) => (0, kyve_js_1.KYVEToTokenAmount)(a),
55
63
  matic: (a) => (0, polygon_js_1.POLToTokenAmount)(a),
56
64
  pol: (a) => (0, polygon_js_1.POLToTokenAmount)(a),
65
+ usdc: (a) => (0, usdc_js_1.USDCToTokenAmount)(a),
66
+ 'base-usdc': (a) => (0, usdc_js_1.USDCToTokenAmount)(a),
67
+ 'polygon-usdc': (a) => (0, usdc_js_1.USDCToTokenAmount)(a),
57
68
  };
58
69
  function isTokenType(token) {
59
70
  return types_js_1.tokenTypes.includes(token);
@@ -1,16 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PolygonToken = exports.POLToTokenAmount = void 0;
3
+ exports.PolygonToken = exports.defaultPolygonPollingOptions = exports.POLToTokenAmount = void 0;
4
4
  const common_js_1 = require("../../utils/common.js");
5
5
  const logger_js_1 = require("../logger.js");
6
6
  const ethereum_js_1 = require("./ethereum.js");
7
7
  exports.POLToTokenAmount = ethereum_js_1.ETHToTokenAmount;
8
+ exports.defaultPolygonPollingOptions = {
9
+ maxAttempts: 10,
10
+ initialBackoffMs: 5_000,
11
+ pollingIntervalMs: 1_000,
12
+ };
8
13
  class PolygonToken extends ethereum_js_1.EthereumToken {
9
- constructor({ logger = logger_js_1.TurboWinstonLogger.default, gatewayUrl = common_js_1.defaultProdGatewayUrls.pol, pollingOptions = {
10
- maxAttempts: 10,
11
- pollingIntervalMs: 4_000,
12
- initialBackoffMs: 5_000,
13
- }, } = {}) {
14
+ constructor({ logger = logger_js_1.TurboWinstonLogger.default, gatewayUrl = common_js_1.defaultProdGatewayUrls.pol, pollingOptions = exports.defaultPolygonPollingOptions, } = {}) {
14
15
  super({ logger, gatewayUrl, pollingOptions });
15
16
  }
16
17
  }