@ardrive/turbo-sdk 1.34.0 → 1.35.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 (47) hide show
  1. package/README.md +40 -5
  2. package/bundles/web.bundle.min.js +230 -24
  3. package/lib/cjs/common/factory.js +1 -2
  4. package/lib/cjs/common/signer.js +3 -0
  5. package/lib/cjs/common/token/baseEth.js +7 -6
  6. package/lib/cjs/common/token/erc20.js +91 -0
  7. package/lib/cjs/common/token/ethereum.js +7 -6
  8. package/lib/cjs/common/token/index.js +11 -0
  9. package/lib/cjs/common/token/polygon.js +7 -6
  10. package/lib/cjs/common/token/usdc.js +83 -0
  11. package/lib/cjs/common/upload.js +6 -1
  12. package/lib/cjs/types.js +13 -1
  13. package/lib/cjs/utils/common.js +19 -4
  14. package/lib/cjs/version.js +1 -1
  15. package/lib/esm/common/factory.js +2 -3
  16. package/lib/esm/common/signer.js +3 -0
  17. package/lib/esm/common/token/baseEth.js +6 -5
  18. package/lib/esm/common/token/erc20.js +87 -0
  19. package/lib/esm/common/token/ethereum.js +6 -5
  20. package/lib/esm/common/token/index.js +11 -0
  21. package/lib/esm/common/token/polygon.js +6 -5
  22. package/lib/esm/common/token/usdc.js +76 -0
  23. package/lib/esm/common/upload.js +6 -1
  24. package/lib/esm/types.js +12 -0
  25. package/lib/esm/utils/common.js +19 -4
  26. package/lib/esm/version.js +1 -1
  27. package/lib/types/common/factory.d.ts.map +1 -1
  28. package/lib/types/common/signer.d.ts +1 -1
  29. package/lib/types/common/signer.d.ts.map +1 -1
  30. package/lib/types/common/token/baseEth.d.ts +5 -0
  31. package/lib/types/common/token/baseEth.d.ts.map +1 -1
  32. package/lib/types/common/token/erc20.d.ts +19 -0
  33. package/lib/types/common/token/erc20.d.ts.map +1 -0
  34. package/lib/types/common/token/ethereum.d.ts +1 -0
  35. package/lib/types/common/token/ethereum.d.ts.map +1 -1
  36. package/lib/types/common/token/index.d.ts.map +1 -1
  37. package/lib/types/common/token/polygon.d.ts +5 -0
  38. package/lib/types/common/token/polygon.d.ts.map +1 -1
  39. package/lib/types/common/token/usdc.d.ts +36 -0
  40. package/lib/types/common/token/usdc.d.ts.map +1 -0
  41. package/lib/types/common/upload.d.ts.map +1 -1
  42. package/lib/types/types.d.ts +4 -2
  43. package/lib/types/types.d.ts.map +1 -1
  44. package/lib/types/utils/common.d.ts.map +1 -1
  45. package/lib/types/version.d.ts +1 -1
  46. package/lib/types/version.d.ts.map +1 -1
  47. package/package.json +1 -1
@@ -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
  }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USDCToken = exports.USDCToTokenAmount = exports.mUSDCToTokenAmount = exports.usdcNetworks = 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 bignumber_js_1 = require("bignumber.js");
20
+ const common_js_1 = require("../../utils/common.js");
21
+ const baseEth_js_1 = require("./baseEth.js");
22
+ const erc20_js_1 = require("./erc20.js");
23
+ const ethereum_js_1 = require("./ethereum.js");
24
+ const polygon_js_1 = require("./polygon.js");
25
+ /**
26
+ * Known USDC contract addresses and default RPCs by network
27
+ */
28
+ const usdcNetworks = (useDevnet = false) => ({
29
+ ethereum: {
30
+ tokenContractAddress: useDevnet
31
+ ? ethSepoliaUsdcAddress
32
+ : ethMainnetUsdcAddress,
33
+ rpcEndpoint: useDevnet
34
+ ? common_js_1.tokenToDevGatewayMap.ethereum
35
+ : common_js_1.defaultProdGatewayUrls.ethereum,
36
+ defaultPollingOptions: ethereum_js_1.defaultEthereumPollingOptions,
37
+ },
38
+ base: {
39
+ tokenContractAddress: useDevnet
40
+ ? baseSepoliaUsdcAddress
41
+ : baseMainnetUsdcAddress,
42
+ rpcEndpoint: useDevnet
43
+ ? common_js_1.tokenToDevGatewayMap['base-eth']
44
+ : common_js_1.defaultProdGatewayUrls['base-eth'],
45
+ defaultPollingOptions: baseEth_js_1.defaultBaseNetworkPollingOptions,
46
+ },
47
+ polygon: {
48
+ tokenContractAddress: useDevnet
49
+ ? polygonAmoyUsdcAddress
50
+ : polygonMainnetUsdcAddress,
51
+ rpcEndpoint: useDevnet
52
+ ? common_js_1.tokenToDevGatewayMap.pol
53
+ : common_js_1.defaultProdGatewayUrls.pol,
54
+ defaultPollingOptions: polygon_js_1.defaultPolygonPollingOptions,
55
+ },
56
+ });
57
+ exports.usdcNetworks = usdcNetworks;
58
+ const ethMainnetUsdcAddress = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
59
+ const baseMainnetUsdcAddress = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
60
+ const polygonMainnetUsdcAddress = '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359';
61
+ const ethSepoliaUsdcAddress = '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238';
62
+ const baseSepoliaUsdcAddress = '0x036CbD53842c5426634e7929541eC2318f3dCF7e';
63
+ const polygonAmoyUsdcAddress = '0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582';
64
+ const mUSDCToTokenAmount = (mUSDC) => mUSDC;
65
+ exports.mUSDCToTokenAmount = mUSDCToTokenAmount;
66
+ const USDCToTokenAmount = (usdc) => new bignumber_js_1.BigNumber(usdc).times(1e6).valueOf();
67
+ exports.USDCToTokenAmount = USDCToTokenAmount;
68
+ class USDCToken extends erc20_js_1.ERC20Token {
69
+ constructor({ network = 'ethereum', logger, gatewayUrl, tokenContractAddress, pollingOptions, useDevnet, } = {}) {
70
+ if (useDevnet === undefined) {
71
+ const keywords = ['sepolia', 'amoy'];
72
+ useDevnet = keywords.some((keyword) => (gatewayUrl ?? '').toLowerCase().includes(keyword));
73
+ }
74
+ const { tokenContractAddress: usdcContractAddress, rpcEndpoint, defaultPollingOptions, } = (0, exports.usdcNetworks)(useDevnet)[network];
75
+ super({
76
+ tokenContractAddress: tokenContractAddress ?? usdcContractAddress,
77
+ logger,
78
+ gatewayUrl: gatewayUrl ?? rpcEndpoint,
79
+ pollingOptions: pollingOptions ?? defaultPollingOptions,
80
+ });
81
+ }
82
+ }
83
+ exports.USDCToken = USDCToken;
@@ -94,7 +94,12 @@ exports.TurboUnauthenticatedUploadService = TurboUnauthenticatedUploadService;
94
94
  class TurboAuthenticatedBaseUploadService extends TurboUnauthenticatedUploadService {
95
95
  constructor({ url = exports.defaultUploadServiceURL, retryConfig, signer, logger, token, paymentService, }) {
96
96
  super({ url, retryConfig, logger, token });
97
- this.enabledOnDemandTokens = ['ario', 'solana', 'base-eth'];
97
+ this.enabledOnDemandTokens = [
98
+ 'ario',
99
+ 'solana',
100
+ 'base-eth',
101
+ 'base-usdc',
102
+ ];
98
103
  this.signer = signer;
99
104
  this.paymentService = paymentService;
100
105
  }
package/lib/cjs/types.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validChunkingModes = exports.isJWK = exports.isWebUploadFolderParams = exports.isNodeUploadFolderParams = exports.multipartFinalizedStatus = exports.multipartFailedStatus = exports.multipartPendingStatus = exports.OnDemandFunding = exports.ExistingBalanceFunding = exports.tokenTypes = exports.fiatCurrencyTypes = void 0;
3
+ exports.validChunkingModes = exports.isJWK = exports.isWebUploadFolderParams = exports.isNodeUploadFolderParams = exports.multipartFinalizedStatus = exports.multipartFailedStatus = exports.multipartPendingStatus = exports.OnDemandFunding = exports.ExistingBalanceFunding = exports.supportedEvmSignerTokens = exports.tokenTypes = exports.fiatCurrencyTypes = void 0;
4
4
  exports.isCurrency = isCurrency;
5
5
  exports.isKyvePrivateKey = isKyvePrivateKey;
6
6
  exports.isEthPrivateKey = isEthPrivateKey;
@@ -31,7 +31,19 @@ exports.tokenTypes = [
31
31
  'matic',
32
32
  'pol',
33
33
  'base-eth',
34
+ 'usdc',
35
+ 'base-usdc',
36
+ 'polygon-usdc',
34
37
  ];
38
+ exports.supportedEvmSignerTokens = new Set([
39
+ 'ethereum',
40
+ 'base-eth',
41
+ 'matic',
42
+ 'pol',
43
+ 'polygon-usdc',
44
+ 'usdc',
45
+ 'base-usdc',
46
+ ]);
35
47
  class ExistingBalanceFunding {
36
48
  }
37
49
  exports.ExistingBalanceFunding = ExistingBalanceFunding;
@@ -43,15 +43,21 @@ function sleep(ms) {
43
43
  function isWeb() {
44
44
  return typeof window !== 'undefined';
45
45
  }
46
+ const ethTestnetRpc = 'https://eth-sepolia.public.blastapi.io';
47
+ const baseTestnetRpc = 'https://sepolia.base.org';
48
+ const polygonTestnetRpc = 'https://rpc-amoy.polygon.technology';
46
49
  exports.tokenToDevGatewayMap = {
47
50
  arweave: 'https://arweave.net', // No arweave test net
48
51
  ario: 'https://arweave.net', // No arweave test net
49
52
  solana: 'https://api.devnet.solana.com',
50
- ethereum: 'https://ethereum-holesky-rpc.publicnode.com',
51
- 'base-eth': 'https://sepolia.base.org',
53
+ ethereum: ethTestnetRpc,
54
+ 'base-eth': baseTestnetRpc,
52
55
  kyve: 'https://api.korellia.kyve.network',
53
- matic: 'https://rpc-amoy.polygon.technology',
54
- pol: 'https://rpc-amoy.polygon.technology',
56
+ matic: polygonTestnetRpc,
57
+ pol: polygonTestnetRpc,
58
+ usdc: ethTestnetRpc,
59
+ 'base-usdc': baseTestnetRpc,
60
+ 'polygon-usdc': polygonTestnetRpc,
55
61
  };
56
62
  exports.tokenToDevAoConfigMap = {
57
63
  ario: {
@@ -68,6 +74,9 @@ exports.defaultProdGatewayUrls = {
68
74
  kyve: 'https://api.kyve.network/',
69
75
  matic: 'https://polygon-rpc.com/',
70
76
  pol: 'https://polygon-rpc.com/',
77
+ usdc: 'https://cloudflare-eth.com/',
78
+ 'base-usdc': 'https://mainnet.base.org',
79
+ 'polygon-usdc': 'https://polygon-rpc.com/',
71
80
  };
72
81
  exports.defaultProdAoConfigs = {
73
82
  ario: {
@@ -99,6 +108,9 @@ function createTurboSigner({ signer: clientProvidedSigner, privateKey: clientPro
99
108
  case 'pol':
100
109
  case 'matic':
101
110
  case 'base-eth':
111
+ case 'usdc':
112
+ case 'base-usdc':
113
+ case 'polygon-usdc':
102
114
  if (!(0, types_js_1.isEthPrivateKey)(clientProvidedPrivateKey)) {
103
115
  throw new Error('A valid Ethereum private key must be provided for EthereumSigner.');
104
116
  }
@@ -162,6 +174,9 @@ function isValidUserAddress(address, type) {
162
174
  case 'base-eth':
163
175
  case 'matic':
164
176
  case 'pol':
177
+ case 'base-usdc':
178
+ case 'usdc':
179
+ case 'polygon-usdc':
165
180
  return isValidECDSAAddress(address);
166
181
  case 'kyve':
167
182
  return isValidKyveAddress(address);
@@ -17,4 +17,4 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.version = void 0;
19
19
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
20
- exports.version = '1.34.0';
20
+ exports.version = '1.35.0-alpha.2';
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { HexInjectedSolanaSigner, InjectedEthereumSigner, SignatureConfig, } from '@dha-team/arbundles';
17
- import { isEthereumWalletAdapter, isSolanaWalletAdapter, } from '../types.js';
17
+ import { isEthereumWalletAdapter, isSolanaWalletAdapter, supportedEvmSignerTokens, } from '../types.js';
18
18
  import { TurboWinstonLogger } from './logger.js';
19
19
  import { TurboAuthenticatedPaymentService, TurboUnauthenticatedPaymentService, } from './payment.js';
20
20
  import { defaultTokenMap } from './token/index.js';
@@ -138,8 +138,7 @@ export class TurboBaseFactory {
138
138
  }
139
139
  return new HexInjectedSolanaSigner(walletAdapter);
140
140
  }
141
- const ethTokens = new Set(['ethereum', 'base-eth', 'matic', 'pol']);
142
- if (ethTokens.has(token)) {
141
+ if (supportedEvmSignerTokens.has(token)) {
143
142
  if (!isEthereumWalletAdapter(walletAdapter)) {
144
143
  throw new Error('Unsupported wallet adapter -- must implement getSigner');
145
144
  }
@@ -48,6 +48,9 @@ export class TurboDataItemAbstractSigner {
48
48
  case 'matic':
49
49
  case 'pol':
50
50
  case 'base-eth':
51
+ case 'usdc':
52
+ case 'base-usdc':
53
+ case 'polygon-usdc':
51
54
  return computeAddress(computePublicKey(fromB64Url(owner)));
52
55
  case 'kyve':
53
56
  return pubkeyToAddress({
@@ -1,11 +1,12 @@
1
1
  import { defaultProdGatewayUrls } from '../../utils/common.js';
2
2
  import { EthereumToken } from './ethereum.js';
3
+ export const defaultBaseNetworkPollingOptions = {
4
+ initialBackoffMs: 2_500,
5
+ maxAttempts: 10,
6
+ pollingIntervalMs: 750,
7
+ };
3
8
  export class BaseEthToken extends EthereumToken {
4
- constructor({ logger, gatewayUrl = defaultProdGatewayUrls['base-eth'], pollingOptions = {
5
- initialBackoffMs: 2_500,
6
- maxAttempts: 10,
7
- pollingIntervalMs: 2_500,
8
- }, } = {}) {
9
+ constructor({ logger, gatewayUrl = defaultProdGatewayUrls['base-eth'], pollingOptions = defaultBaseNetworkPollingOptions, } = {}) {
9
10
  super({
10
11
  logger,
11
12
  gatewayUrl,
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { EthereumSigner } from '@dha-team/arbundles';
17
+ import { Wallet as EthereumWallet, JsonRpcProvider, ethers } from 'ethers';
18
+ import { isEthereumWalletAdapter, } from '../../types.js';
19
+ import { defaultProdGatewayUrls } from '../../utils/common.js';
20
+ import { TurboWinstonLogger } from '../logger.js';
21
+ import { EthereumToken, ethDataFromTurboCreditDestinationAddress, } from './ethereum.js';
22
+ export class ERC20Token extends EthereumToken {
23
+ constructor({ tokenContractAddress, logger = TurboWinstonLogger.default, gatewayUrl = defaultProdGatewayUrls.ethereum, pollingOptions, }) {
24
+ super({ logger, gatewayUrl, pollingOptions });
25
+ this.tokenContract = new ethers.Contract(tokenContractAddress, [
26
+ 'function decimals() view returns (uint8)',
27
+ 'function balanceOf(address) view returns (uint256)',
28
+ 'function transfer(address to, uint256 value) returns (bool)',
29
+ ], this.rpcProvider);
30
+ }
31
+ async createAndSubmitTx({ target, tokenAmount, signer, turboCreditDestinationAddress, }) {
32
+ try {
33
+ let connected;
34
+ let walletOrSigner;
35
+ if (signer.signer instanceof EthereumSigner) {
36
+ const provider = new JsonRpcProvider(this.gatewayUrl);
37
+ // 🧩 CLI / Node path
38
+ const keyHex = Buffer.from(signer.signer.key).toString('hex');
39
+ walletOrSigner = new EthereumWallet(keyHex, provider);
40
+ connected = this.tokenContract.connect(walletOrSigner);
41
+ }
42
+ else if (signer.walletAdapter !== undefined &&
43
+ isEthereumWalletAdapter(signer.walletAdapter)) {
44
+ walletOrSigner = signer.walletAdapter.getSigner();
45
+ connected = this.tokenContract.connect(walletOrSigner);
46
+ }
47
+ else {
48
+ throw new Error('Unsupported signer -- must be EthereumSigner or have a walletAdapter implementing getSigner');
49
+ }
50
+ // Encode transfer data
51
+ const baseTransferData = connected.interface.encodeFunctionData('transfer', [target, tokenAmount.toString()]);
52
+ let finalData = baseTransferData;
53
+ // Append optional memo data with turbo credit destination address
54
+ const memoData = ethDataFromTurboCreditDestinationAddress(turboCreditDestinationAddress);
55
+ if (memoData !== undefined) {
56
+ // remove the "0x" prefix and append
57
+ finalData += memoData.slice(2);
58
+ }
59
+ const txRequest = {
60
+ to: await connected.getAddress(),
61
+ data: finalData,
62
+ };
63
+ this.logger.debug('Submitting ERC20 transfer', {
64
+ target,
65
+ tokenAmount: tokenAmount.toString(),
66
+ rpcEndpoint: this.gatewayUrl,
67
+ txRequest,
68
+ });
69
+ const tx = await walletOrSigner.sendTransaction(txRequest);
70
+ this.logger.debug('ERC20 transfer submitted', {
71
+ txHash: tx.hash,
72
+ target,
73
+ tx,
74
+ });
75
+ return { id: tx.hash, target };
76
+ }
77
+ catch (e) {
78
+ this.logger.error('Error creating/submitting ERC20 tx', {
79
+ error: e instanceof Error ? e.message : e,
80
+ target,
81
+ tokenAmount,
82
+ rpcEndpoint: this.gatewayUrl,
83
+ });
84
+ throw e;
85
+ }
86
+ }
87
+ }
@@ -19,12 +19,13 @@ import { defaultProdGatewayUrls } from '../../utils/common.js';
19
19
  import { TurboWinstonLogger } from '../logger.js';
20
20
  export const weiToTokenAmount = (wei) => wei;
21
21
  export const ETHToTokenAmount = (eth) => new BigNumber(eth).times(1e18).valueOf();
22
+ export const defaultEthereumPollingOptions = {
23
+ initialBackoffMs: 25_000,
24
+ maxAttempts: 10,
25
+ pollingIntervalMs: 1_500,
26
+ };
22
27
  export class EthereumToken {
23
- constructor({ logger = TurboWinstonLogger.default, gatewayUrl = defaultProdGatewayUrls.ethereum, pollingOptions = {
24
- maxAttempts: 10,
25
- pollingIntervalMs: 4_000,
26
- initialBackoffMs: 25_000,
27
- }, } = {}) {
28
+ constructor({ logger = TurboWinstonLogger.default, gatewayUrl = defaultProdGatewayUrls.ethereum, pollingOptions = defaultEthereumPollingOptions, } = {}) {
28
29
  this.logger = logger;
29
30
  this.gatewayUrl = gatewayUrl;
30
31
  this.pollingOptions = pollingOptions;
@@ -6,6 +6,7 @@ import { ETHToTokenAmount, EthereumToken } from './ethereum.js';
6
6
  import { KYVEToTokenAmount, KyveToken } from './kyve.js';
7
7
  import { POLToTokenAmount, PolygonToken } from './polygon.js';
8
8
  import { SOLToTokenAmount, SolanaToken } from './solana.js';
9
+ import { USDCToTokenAmount, USDCToken } from './usdc.js';
9
10
  export const defaultTokenMap = {
10
11
  arweave: (config) => new ArweaveToken(config),
11
12
  ario: (config) => new ARIOToken(config),
@@ -15,8 +16,12 @@ export const defaultTokenMap = {
15
16
  kyve: (config) => new KyveToken(config),
16
17
  matic: (config) => new PolygonToken(config),
17
18
  pol: (config) => new PolygonToken(config),
19
+ usdc: (config) => new USDCToken({ network: 'ethereum', ...config }),
20
+ 'base-usdc': (config) => new USDCToken({ network: 'base', ...config }),
21
+ 'polygon-usdc': (config) => new USDCToken({ network: 'polygon', ...config }),
18
22
  };
19
23
  const ethExponent = 18;
24
+ const usdcExponent = 6;
20
25
  export const exponentMap = {
21
26
  arweave: 12,
22
27
  ario: 6,
@@ -26,6 +31,9 @@ export const exponentMap = {
26
31
  kyve: 6,
27
32
  matic: ethExponent,
28
33
  pol: ethExponent,
34
+ usdc: usdcExponent,
35
+ 'base-usdc': usdcExponent,
36
+ 'polygon-usdc': usdcExponent,
29
37
  };
30
38
  export const tokenToBaseMap = {
31
39
  arweave: (a) => ARToTokenAmount(a),
@@ -36,6 +44,9 @@ export const tokenToBaseMap = {
36
44
  kyve: (a) => KYVEToTokenAmount(a),
37
45
  matic: (a) => POLToTokenAmount(a),
38
46
  pol: (a) => POLToTokenAmount(a),
47
+ usdc: (a) => USDCToTokenAmount(a),
48
+ 'base-usdc': (a) => USDCToTokenAmount(a),
49
+ 'polygon-usdc': (a) => USDCToTokenAmount(a),
39
50
  };
40
51
  export function isTokenType(token) {
41
52
  return tokenTypes.includes(token);
@@ -2,12 +2,13 @@ import { defaultProdGatewayUrls } from '../../utils/common.js';
2
2
  import { TurboWinstonLogger } from '../logger.js';
3
3
  import { ETHToTokenAmount, EthereumToken } from './ethereum.js';
4
4
  export const POLToTokenAmount = ETHToTokenAmount;
5
+ export const defaultPolygonPollingOptions = {
6
+ maxAttempts: 10,
7
+ initialBackoffMs: 5_000,
8
+ pollingIntervalMs: 1_000,
9
+ };
5
10
  export class PolygonToken extends EthereumToken {
6
- constructor({ logger = TurboWinstonLogger.default, gatewayUrl = defaultProdGatewayUrls.pol, pollingOptions = {
7
- maxAttempts: 10,
8
- pollingIntervalMs: 4_000,
9
- initialBackoffMs: 5_000,
10
- }, } = {}) {
11
+ constructor({ logger = TurboWinstonLogger.default, gatewayUrl = defaultProdGatewayUrls.pol, pollingOptions = defaultPolygonPollingOptions, } = {}) {
11
12
  super({ logger, gatewayUrl, pollingOptions });
12
13
  }
13
14
  }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { BigNumber } from 'bignumber.js';
17
+ import { defaultProdGatewayUrls, tokenToDevGatewayMap, } from '../../utils/common.js';
18
+ import { defaultBaseNetworkPollingOptions } from './baseEth.js';
19
+ import { ERC20Token } from './erc20.js';
20
+ import { defaultEthereumPollingOptions } from './ethereum.js';
21
+ import { defaultPolygonPollingOptions } from './polygon.js';
22
+ /**
23
+ * Known USDC contract addresses and default RPCs by network
24
+ */
25
+ export const usdcNetworks = (useDevnet = false) => ({
26
+ ethereum: {
27
+ tokenContractAddress: useDevnet
28
+ ? ethSepoliaUsdcAddress
29
+ : ethMainnetUsdcAddress,
30
+ rpcEndpoint: useDevnet
31
+ ? tokenToDevGatewayMap.ethereum
32
+ : defaultProdGatewayUrls.ethereum,
33
+ defaultPollingOptions: defaultEthereumPollingOptions,
34
+ },
35
+ base: {
36
+ tokenContractAddress: useDevnet
37
+ ? baseSepoliaUsdcAddress
38
+ : baseMainnetUsdcAddress,
39
+ rpcEndpoint: useDevnet
40
+ ? tokenToDevGatewayMap['base-eth']
41
+ : defaultProdGatewayUrls['base-eth'],
42
+ defaultPollingOptions: defaultBaseNetworkPollingOptions,
43
+ },
44
+ polygon: {
45
+ tokenContractAddress: useDevnet
46
+ ? polygonAmoyUsdcAddress
47
+ : polygonMainnetUsdcAddress,
48
+ rpcEndpoint: useDevnet
49
+ ? tokenToDevGatewayMap.pol
50
+ : defaultProdGatewayUrls.pol,
51
+ defaultPollingOptions: defaultPolygonPollingOptions,
52
+ },
53
+ });
54
+ const ethMainnetUsdcAddress = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
55
+ const baseMainnetUsdcAddress = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
56
+ const polygonMainnetUsdcAddress = '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359';
57
+ const ethSepoliaUsdcAddress = '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238';
58
+ const baseSepoliaUsdcAddress = '0x036CbD53842c5426634e7929541eC2318f3dCF7e';
59
+ const polygonAmoyUsdcAddress = '0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582';
60
+ export const mUSDCToTokenAmount = (mUSDC) => mUSDC;
61
+ export const USDCToTokenAmount = (usdc) => new BigNumber(usdc).times(1e6).valueOf();
62
+ export class USDCToken extends ERC20Token {
63
+ constructor({ network = 'ethereum', logger, gatewayUrl, tokenContractAddress, pollingOptions, useDevnet, } = {}) {
64
+ if (useDevnet === undefined) {
65
+ const keywords = ['sepolia', 'amoy'];
66
+ useDevnet = keywords.some((keyword) => (gatewayUrl ?? '').toLowerCase().includes(keyword));
67
+ }
68
+ const { tokenContractAddress: usdcContractAddress, rpcEndpoint, defaultPollingOptions, } = usdcNetworks(useDevnet)[network];
69
+ super({
70
+ tokenContractAddress: tokenContractAddress ?? usdcContractAddress,
71
+ logger,
72
+ gatewayUrl: gatewayUrl ?? rpcEndpoint,
73
+ pollingOptions: pollingOptions ?? defaultPollingOptions,
74
+ });
75
+ }
76
+ }
@@ -90,7 +90,12 @@ export class TurboUnauthenticatedUploadService {
90
90
  export class TurboAuthenticatedBaseUploadService extends TurboUnauthenticatedUploadService {
91
91
  constructor({ url = defaultUploadServiceURL, retryConfig, signer, logger, token, paymentService, }) {
92
92
  super({ url, retryConfig, logger, token });
93
- this.enabledOnDemandTokens = ['ario', 'solana', 'base-eth'];
93
+ this.enabledOnDemandTokens = [
94
+ 'ario',
95
+ 'solana',
96
+ 'base-eth',
97
+ 'base-usdc',
98
+ ];
94
99
  this.signer = signer;
95
100
  this.paymentService = paymentService;
96
101
  }
package/lib/esm/types.js CHANGED
@@ -23,7 +23,19 @@ export const tokenTypes = [
23
23
  'matic',
24
24
  'pol',
25
25
  'base-eth',
26
+ 'usdc',
27
+ 'base-usdc',
28
+ 'polygon-usdc',
26
29
  ];
30
+ export const supportedEvmSignerTokens = new Set([
31
+ 'ethereum',
32
+ 'base-eth',
33
+ 'matic',
34
+ 'pol',
35
+ 'polygon-usdc',
36
+ 'usdc',
37
+ 'base-usdc',
38
+ ]);
27
39
  export class ExistingBalanceFunding {
28
40
  }
29
41
  export class OnDemandFunding {
@@ -28,15 +28,21 @@ export function sleep(ms) {
28
28
  export function isWeb() {
29
29
  return typeof window !== 'undefined';
30
30
  }
31
+ const ethTestnetRpc = 'https://eth-sepolia.public.blastapi.io';
32
+ const baseTestnetRpc = 'https://sepolia.base.org';
33
+ const polygonTestnetRpc = 'https://rpc-amoy.polygon.technology';
31
34
  export const tokenToDevGatewayMap = {
32
35
  arweave: 'https://arweave.net', // No arweave test net
33
36
  ario: 'https://arweave.net', // No arweave test net
34
37
  solana: 'https://api.devnet.solana.com',
35
- ethereum: 'https://ethereum-holesky-rpc.publicnode.com',
36
- 'base-eth': 'https://sepolia.base.org',
38
+ ethereum: ethTestnetRpc,
39
+ 'base-eth': baseTestnetRpc,
37
40
  kyve: 'https://api.korellia.kyve.network',
38
- matic: 'https://rpc-amoy.polygon.technology',
39
- pol: 'https://rpc-amoy.polygon.technology',
41
+ matic: polygonTestnetRpc,
42
+ pol: polygonTestnetRpc,
43
+ usdc: ethTestnetRpc,
44
+ 'base-usdc': baseTestnetRpc,
45
+ 'polygon-usdc': polygonTestnetRpc,
40
46
  };
41
47
  export const tokenToDevAoConfigMap = {
42
48
  ario: {
@@ -53,6 +59,9 @@ export const defaultProdGatewayUrls = {
53
59
  kyve: 'https://api.kyve.network/',
54
60
  matic: 'https://polygon-rpc.com/',
55
61
  pol: 'https://polygon-rpc.com/',
62
+ usdc: 'https://cloudflare-eth.com/',
63
+ 'base-usdc': 'https://mainnet.base.org',
64
+ 'polygon-usdc': 'https://polygon-rpc.com/',
56
65
  };
57
66
  export const defaultProdAoConfigs = {
58
67
  ario: {
@@ -84,6 +93,9 @@ export function createTurboSigner({ signer: clientProvidedSigner, privateKey: cl
84
93
  case 'pol':
85
94
  case 'matic':
86
95
  case 'base-eth':
96
+ case 'usdc':
97
+ case 'base-usdc':
98
+ case 'polygon-usdc':
87
99
  if (!isEthPrivateKey(clientProvidedPrivateKey)) {
88
100
  throw new Error('A valid Ethereum private key must be provided for EthereumSigner.');
89
101
  }
@@ -147,6 +159,9 @@ export function isValidUserAddress(address, type) {
147
159
  case 'base-eth':
148
160
  case 'matic':
149
161
  case 'pol':
162
+ case 'base-usdc':
163
+ case 'usdc':
164
+ case 'polygon-usdc':
150
165
  return isValidECDSAAddress(address);
151
166
  case 'kyve':
152
167
  return isValidKyveAddress(address);
@@ -14,4 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
17
- export const version = '1.34.0';
17
+ export const version = '1.35.0-alpha.2';
@@ -1 +1 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/common/factory.ts"],"names":[],"mappings":"AAqBA,OAAO,EACL,oBAAoB,EAEpB,+BAA+B,EAC/B,4CAA4C,EAC5C,wCAAwC,EACxC,iCAAiC,EAIlC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EACL,gCAAgC,EAEjC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC3B,MAAM,YAAY,CAAC;AAGpB,8BAAsB,gBAAgB;IACpC,SAAS,CAAC,MAAM,CAAC,MAAM,qBAA8B;IAGrD,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM;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M,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM;IAIlC,MAAM,CAAC,eAAe,CAAC,EACrB,oBAAyB,EACzB,mBAAwB,EACxB,KAAK,GACN,GAAE,iCAAsC;IAqBzC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,EAC3B,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACrB,MAAM,EACN,KAAK,GACN,EAAE,oBAAoB,GAAG,2BAA2B;IAErD,SAAS,CAAC,QAAQ,CAAC,6BAA6B,CAC9C,MAAM,EAAE,4CAA4C,GAAG;QACrD,cAAc,EAAE,gCAAgC,CAAC;KAClD,GACA,wCAAwC;IAE3C,SAAS,CAAC,qBAAqB,CAAC,EAC9B,UAAU,EACV,MAAM,EAAE,cAAc,EACtB,oBAAyB,EACzB,mBAAwB,EACxB,KAAK,EACL,UAAU,EACV,QAAQ,EACR,UAAU,EACV,MAAM,EACN,aAAa,EACb,SAAS,EACT,KAAK,GACN,EAAE,+BAA+B,GAAG;QAAE,MAAM,EAAE,kBAAkB,CAAA;KAAE;IAgGnE,OAAO,CAAC,iBAAiB;CAuB1B"}
@@ -4,9 +4,9 @@ import { FileStreamFactory, NativeAddress, SendTxWithSignerParams, TokenType, Tu
4
4
  */
5
5
  export declare abstract class TurboDataItemAbstractSigner implements TurboDataItemSigner {
6
6
  signer: TurboSigner;
7
+ walletAdapter: WalletAdapter | undefined;
7
8
  protected logger: TurboLogger;
8
9
  protected token: TokenType;
9
- protected walletAdapter: WalletAdapter | undefined;
10
10
  constructor({ signer, logger, token, walletAdapter, }: TurboDataItemSignerParams);
11
11
  abstract signDataItem({ fileStreamFactory, fileSizeFactory, dataItemOpts, emitter, }: TurboFileFactory<FileStreamFactory>): Promise<TurboSignedDataItemFactory>;
12
12
  private ownerToNativeAddress;
@@ -1 +1 @@
1
- {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../../src/common/signer.ts"],"names":[],"mappings":"AAkCA,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb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mBAAmB;IAEvB,MAAM,EAAE,WAAW,CAAC;IACpB,aAAa,EAAE,aAAa,GAAG,SAAS,CAAC;IAEhD,SAAS,CAAC,MAAM,EAAE,WAAW,CAAC;IAC9B,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC;gBAEf,EACV,MAAM,EACN,MAAmC,EACnC,KAAK,EACL,aAAa,GACd,EAAE,yBAAyB;IAO5B,QAAQ,CAAC,YAAY,CAAC,EACpB,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,OAAO,GACR,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAE5E,OAAO,CAAC,oBAAoB;IA+Bf,4BAA4B;;;;;IAY5B,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IAI/B,gBAAgB,IAAI,OAAO,CAAC,aAAa,CAAC;IAOvD,gGAAgG;IACnF,eAAe,CAAC,EAC3B,MAAM,EACN,MAAM,EACN,UAAU,EACV,6BAA6B,GAC9B,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC;IAuF9B,QAAQ,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;CAgBnE"}
@@ -15,6 +15,11 @@
15
15
  */
16
16
  import { TokenConfig } from '../../types.js';
17
17
  import { EthereumToken } from './ethereum.js';
18
+ export declare const defaultBaseNetworkPollingOptions: {
19
+ initialBackoffMs: number;
20
+ maxAttempts: number;
21
+ pollingIntervalMs: number;
22
+ };
18
23
  export declare class BaseEthToken extends EthereumToken {
19
24
  constructor({ logger, gatewayUrl, pollingOptions, }?: TokenConfig);
20
25
  protected getTxAvailability(txId: string): Promise<boolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"baseEth.d.ts","sourceRoot":"","sources":["../../../../src/common/token/baseEth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,qBAAa,YAAa,SAAQ,aAAa;gBACjC,EACV,MAAM,EACN,UAA+C,EAC/C,cAIC,GACF,GAAE,WAAgB;cAQH,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAiBlE"}
1
+ {"version":3,"file":"baseEth.d.ts","sourceRoot":"","sources":["../../../../src/common/token/baseEth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,eAAO,MAAM,gCAAgC;;;;CAI5C,CAAC;AAEF,qBAAa,YAAa,SAAQ,aAAa;gBACjC,EACV,MAAM,EACN,UAA+C,EAC/C,cAAiD,GAClD,GAAE,WAAgB;cAQH,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAiBlE"}