@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.
- package/README.md +40 -5
- package/bundles/web.bundle.min.js +230 -24
- package/lib/cjs/common/factory.js +1 -2
- package/lib/cjs/common/signer.js +3 -0
- package/lib/cjs/common/token/baseEth.js +7 -6
- package/lib/cjs/common/token/erc20.js +91 -0
- package/lib/cjs/common/token/ethereum.js +7 -6
- package/lib/cjs/common/token/index.js +11 -0
- package/lib/cjs/common/token/polygon.js +7 -6
- package/lib/cjs/common/token/usdc.js +83 -0
- package/lib/cjs/common/upload.js +6 -1
- package/lib/cjs/types.js +13 -1
- package/lib/cjs/utils/common.js +19 -4
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/factory.js +2 -3
- package/lib/esm/common/signer.js +3 -0
- package/lib/esm/common/token/baseEth.js +6 -5
- package/lib/esm/common/token/erc20.js +87 -0
- package/lib/esm/common/token/ethereum.js +6 -5
- package/lib/esm/common/token/index.js +11 -0
- package/lib/esm/common/token/polygon.js +6 -5
- package/lib/esm/common/token/usdc.js +76 -0
- package/lib/esm/common/upload.js +6 -1
- package/lib/esm/types.js +12 -0
- package/lib/esm/utils/common.js +19 -4
- package/lib/esm/version.js +1 -1
- package/lib/types/common/factory.d.ts.map +1 -1
- package/lib/types/common/signer.d.ts +1 -1
- package/lib/types/common/signer.d.ts.map +1 -1
- package/lib/types/common/token/baseEth.d.ts +5 -0
- package/lib/types/common/token/baseEth.d.ts.map +1 -1
- package/lib/types/common/token/erc20.d.ts +19 -0
- package/lib/types/common/token/erc20.d.ts.map +1 -0
- package/lib/types/common/token/ethereum.d.ts +1 -0
- package/lib/types/common/token/ethereum.d.ts.map +1 -1
- package/lib/types/common/token/index.d.ts.map +1 -1
- package/lib/types/common/token/polygon.d.ts +5 -0
- package/lib/types/common/token/polygon.d.ts.map +1 -1
- package/lib/types/common/token/usdc.d.ts +36 -0
- package/lib/types/common/token/usdc.d.ts.map +1 -0
- package/lib/types/common/upload.d.ts.map +1 -1
- package/lib/types/types.d.ts +4 -2
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/utils/common.d.ts.map +1 -1
- package/lib/types/version.d.ts +1 -1
- package/lib/types/version.d.ts.map +1 -1
- 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
|
|
343
|
+
// Ethereum Sepolia
|
|
344
344
|
const turbo = TurboFactory.authenticated({
|
|
345
|
-
privateKey: process.env.
|
|
345
|
+
privateKey: process.env.SEPOLIA_PRIVATE_KEY,
|
|
346
346
|
token: 'ethereum',
|
|
347
|
-
gatewayUrl: 'https://
|
|
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
|
|
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`),
|
|
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,8 +222361,20 @@ 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
|
];
|
|
222369
|
+
var supportedEvmSignerTokens = /* @__PURE__ */ new Set([
|
|
222370
|
+
"ethereum",
|
|
222371
|
+
"base-eth",
|
|
222372
|
+
"matic",
|
|
222373
|
+
"pol",
|
|
222374
|
+
"polygon-usdc",
|
|
222375
|
+
"usdc",
|
|
222376
|
+
"base-usdc"
|
|
222377
|
+
]);
|
|
222366
222378
|
var ExistingBalanceFunding = class {
|
|
222367
222379
|
};
|
|
222368
222380
|
var OnDemandFunding = class {
|
|
@@ -222423,7 +222435,7 @@ var import_winston = __toESM(require_winston(), 1);
|
|
|
222423
222435
|
init_dirname();
|
|
222424
222436
|
init_buffer2();
|
|
222425
222437
|
init_process2();
|
|
222426
|
-
var version21 = "1.
|
|
222438
|
+
var version21 = "1.35.0-alpha.1";
|
|
222427
222439
|
|
|
222428
222440
|
// src/common/logger.ts
|
|
222429
222441
|
var TurboWinstonLogger = class _TurboWinstonLogger {
|
|
@@ -259254,6 +259266,24 @@ var wordlists2 = {
|
|
|
259254
259266
|
function sleep2(ms2) {
|
|
259255
259267
|
return new Promise((resolve3) => setTimeout(resolve3, ms2));
|
|
259256
259268
|
}
|
|
259269
|
+
var ethTestnetRpc = "https://eth-sepolia.public.blastapi.io";
|
|
259270
|
+
var baseTestnetRpc = "https://sepolia.base.org";
|
|
259271
|
+
var polygonTestnetRpc = "https://rpc-amoy.polygon.technology";
|
|
259272
|
+
var tokenToDevGatewayMap = {
|
|
259273
|
+
arweave: "https://arweave.net",
|
|
259274
|
+
// No arweave test net
|
|
259275
|
+
ario: "https://arweave.net",
|
|
259276
|
+
// No arweave test net
|
|
259277
|
+
solana: "https://api.devnet.solana.com",
|
|
259278
|
+
ethereum: ethTestnetRpc,
|
|
259279
|
+
"base-eth": baseTestnetRpc,
|
|
259280
|
+
kyve: "https://api.korellia.kyve.network",
|
|
259281
|
+
matic: polygonTestnetRpc,
|
|
259282
|
+
pol: polygonTestnetRpc,
|
|
259283
|
+
usdc: ethTestnetRpc,
|
|
259284
|
+
"base-usdc": baseTestnetRpc,
|
|
259285
|
+
"polygon-usdc": polygonTestnetRpc
|
|
259286
|
+
};
|
|
259257
259287
|
var defaultProdGatewayUrls = {
|
|
259258
259288
|
arweave: "https://arweave.net",
|
|
259259
259289
|
ario: "https://arweave.net",
|
|
@@ -259262,7 +259292,10 @@ var defaultProdGatewayUrls = {
|
|
|
259262
259292
|
"base-eth": "https://mainnet.base.org",
|
|
259263
259293
|
kyve: "https://api.kyve.network/",
|
|
259264
259294
|
matic: "https://polygon-rpc.com/",
|
|
259265
|
-
pol: "https://polygon-rpc.com/"
|
|
259295
|
+
pol: "https://polygon-rpc.com/",
|
|
259296
|
+
usdc: "https://cloudflare-eth.com/",
|
|
259297
|
+
"base-usdc": "https://mainnet.base.org",
|
|
259298
|
+
"polygon-usdc": "https://polygon-rpc.com/"
|
|
259266
259299
|
};
|
|
259267
259300
|
var defaultProdAoConfigs = {
|
|
259268
259301
|
ario: {
|
|
@@ -259297,6 +259330,9 @@ function createTurboSigner({
|
|
|
259297
259330
|
case "pol":
|
|
259298
259331
|
case "matic":
|
|
259299
259332
|
case "base-eth":
|
|
259333
|
+
case "usdc":
|
|
259334
|
+
case "base-usdc":
|
|
259335
|
+
case "polygon-usdc":
|
|
259300
259336
|
if (!isEthPrivateKey(clientProvidedPrivateKey)) {
|
|
259301
259337
|
throw new Error(
|
|
259302
259338
|
"A valid Ethereum private key must be provided for EthereumSigner."
|
|
@@ -259354,6 +259390,9 @@ function isValidUserAddress(address, type4) {
|
|
|
259354
259390
|
case "base-eth":
|
|
259355
259391
|
case "matic":
|
|
259356
259392
|
case "pol":
|
|
259393
|
+
case "base-usdc":
|
|
259394
|
+
case "usdc":
|
|
259395
|
+
case "polygon-usdc":
|
|
259357
259396
|
return isValidECDSAAddress(address);
|
|
259358
259397
|
case "kyve":
|
|
259359
259398
|
return isValidKyveAddress(address);
|
|
@@ -273336,15 +273375,16 @@ init_buffer2();
|
|
|
273336
273375
|
init_process2();
|
|
273337
273376
|
var weiToTokenAmount = (wei) => wei;
|
|
273338
273377
|
var ETHToTokenAmount = (eth) => new BigNumber2(eth).times(1e18).valueOf();
|
|
273378
|
+
var defaultEthereumPollingOptions = {
|
|
273379
|
+
initialBackoffMs: 25e3,
|
|
273380
|
+
maxAttempts: 10,
|
|
273381
|
+
pollingIntervalMs: 1500
|
|
273382
|
+
};
|
|
273339
273383
|
var EthereumToken = class {
|
|
273340
273384
|
constructor({
|
|
273341
273385
|
logger: logger19 = TurboWinstonLogger.default,
|
|
273342
273386
|
gatewayUrl = defaultProdGatewayUrls.ethereum,
|
|
273343
|
-
pollingOptions =
|
|
273344
|
-
maxAttempts: 10,
|
|
273345
|
-
pollingIntervalMs: 4e3,
|
|
273346
|
-
initialBackoffMs: 25e3
|
|
273347
|
-
}
|
|
273387
|
+
pollingOptions = defaultEthereumPollingOptions
|
|
273348
273388
|
} = {}) {
|
|
273349
273389
|
this.logger = logger19;
|
|
273350
273390
|
this.gatewayUrl = gatewayUrl;
|
|
@@ -273422,15 +273462,16 @@ function ethDataFromTurboCreditDestinationAddress(turboCreditDestinationAddress)
|
|
|
273422
273462
|
}
|
|
273423
273463
|
|
|
273424
273464
|
// src/common/token/baseEth.ts
|
|
273465
|
+
var defaultBaseNetworkPollingOptions = {
|
|
273466
|
+
initialBackoffMs: 2500,
|
|
273467
|
+
maxAttempts: 10,
|
|
273468
|
+
pollingIntervalMs: 750
|
|
273469
|
+
};
|
|
273425
273470
|
var BaseEthToken = class extends EthereumToken {
|
|
273426
273471
|
constructor({
|
|
273427
273472
|
logger: logger19,
|
|
273428
273473
|
gatewayUrl = defaultProdGatewayUrls["base-eth"],
|
|
273429
|
-
pollingOptions =
|
|
273430
|
-
initialBackoffMs: 2500,
|
|
273431
|
-
maxAttempts: 10,
|
|
273432
|
-
pollingIntervalMs: 2500
|
|
273433
|
-
}
|
|
273474
|
+
pollingOptions = defaultBaseNetworkPollingOptions
|
|
273434
273475
|
} = {}) {
|
|
273435
273476
|
super({
|
|
273436
273477
|
logger: logger19,
|
|
@@ -273678,15 +273719,16 @@ init_dirname();
|
|
|
273678
273719
|
init_buffer2();
|
|
273679
273720
|
init_process2();
|
|
273680
273721
|
var POLToTokenAmount = ETHToTokenAmount;
|
|
273722
|
+
var defaultPolygonPollingOptions = {
|
|
273723
|
+
maxAttempts: 10,
|
|
273724
|
+
initialBackoffMs: 5e3,
|
|
273725
|
+
pollingIntervalMs: 1e3
|
|
273726
|
+
};
|
|
273681
273727
|
var PolygonToken = class extends EthereumToken {
|
|
273682
273728
|
constructor({
|
|
273683
273729
|
logger: logger19 = TurboWinstonLogger.default,
|
|
273684
273730
|
gatewayUrl = defaultProdGatewayUrls.pol,
|
|
273685
|
-
pollingOptions =
|
|
273686
|
-
maxAttempts: 10,
|
|
273687
|
-
pollingIntervalMs: 4e3,
|
|
273688
|
-
initialBackoffMs: 5e3
|
|
273689
|
-
}
|
|
273731
|
+
pollingOptions = defaultPolygonPollingOptions
|
|
273690
273732
|
} = {}) {
|
|
273691
273733
|
super({ logger: logger19, gatewayUrl, pollingOptions });
|
|
273692
273734
|
}
|
|
@@ -273817,6 +273859,149 @@ var SolanaToken = class {
|
|
|
273817
273859
|
}
|
|
273818
273860
|
};
|
|
273819
273861
|
|
|
273862
|
+
// src/common/token/usdc.ts
|
|
273863
|
+
init_dirname();
|
|
273864
|
+
init_buffer2();
|
|
273865
|
+
init_process2();
|
|
273866
|
+
|
|
273867
|
+
// src/common/token/erc20.ts
|
|
273868
|
+
init_dirname();
|
|
273869
|
+
init_buffer2();
|
|
273870
|
+
init_process2();
|
|
273871
|
+
var ERC20Token = class extends EthereumToken {
|
|
273872
|
+
constructor({
|
|
273873
|
+
tokenContractAddress,
|
|
273874
|
+
logger: logger19 = TurboWinstonLogger.default,
|
|
273875
|
+
gatewayUrl = defaultProdGatewayUrls.ethereum,
|
|
273876
|
+
pollingOptions
|
|
273877
|
+
}) {
|
|
273878
|
+
super({ logger: logger19, gatewayUrl, pollingOptions });
|
|
273879
|
+
this.tokenContract = new ethers_exports.Contract(
|
|
273880
|
+
tokenContractAddress,
|
|
273881
|
+
[
|
|
273882
|
+
"function decimals() view returns (uint8)",
|
|
273883
|
+
"function balanceOf(address) view returns (uint256)",
|
|
273884
|
+
"function transfer(address to, uint256 value) returns (bool)"
|
|
273885
|
+
],
|
|
273886
|
+
this.rpcProvider
|
|
273887
|
+
);
|
|
273888
|
+
}
|
|
273889
|
+
async createAndSubmitTx({
|
|
273890
|
+
target,
|
|
273891
|
+
tokenAmount,
|
|
273892
|
+
signer,
|
|
273893
|
+
turboCreditDestinationAddress
|
|
273894
|
+
}) {
|
|
273895
|
+
try {
|
|
273896
|
+
let connected;
|
|
273897
|
+
let walletOrSigner;
|
|
273898
|
+
if (signer.signer instanceof EthereumSigner) {
|
|
273899
|
+
const provider = new JsonRpcProvider(this.gatewayUrl);
|
|
273900
|
+
const keyHex = Buffer2.from(signer.signer.key).toString("hex");
|
|
273901
|
+
walletOrSigner = new Wallet2(keyHex, provider);
|
|
273902
|
+
connected = this.tokenContract.connect(walletOrSigner);
|
|
273903
|
+
} else if (signer.walletAdapter !== void 0 && isEthereumWalletAdapter(signer.walletAdapter)) {
|
|
273904
|
+
walletOrSigner = signer.walletAdapter.getSigner();
|
|
273905
|
+
connected = this.tokenContract.connect(walletOrSigner);
|
|
273906
|
+
} else {
|
|
273907
|
+
throw new Error(
|
|
273908
|
+
"Unsupported signer -- must be EthereumSigner or have a walletAdapter implementing getSigner"
|
|
273909
|
+
);
|
|
273910
|
+
}
|
|
273911
|
+
const baseTransferData = connected.interface.encodeFunctionData(
|
|
273912
|
+
"transfer",
|
|
273913
|
+
[target, tokenAmount.toString()]
|
|
273914
|
+
);
|
|
273915
|
+
let finalData = baseTransferData;
|
|
273916
|
+
const memoData = ethDataFromTurboCreditDestinationAddress(
|
|
273917
|
+
turboCreditDestinationAddress
|
|
273918
|
+
);
|
|
273919
|
+
if (memoData !== void 0) {
|
|
273920
|
+
finalData += memoData.slice(2);
|
|
273921
|
+
}
|
|
273922
|
+
const txRequest = {
|
|
273923
|
+
to: await connected.getAddress(),
|
|
273924
|
+
data: finalData
|
|
273925
|
+
};
|
|
273926
|
+
this.logger.debug("Submitting ERC20 transfer", {
|
|
273927
|
+
target,
|
|
273928
|
+
tokenAmount: tokenAmount.toString(),
|
|
273929
|
+
rpcEndpoint: this.gatewayUrl,
|
|
273930
|
+
txRequest
|
|
273931
|
+
});
|
|
273932
|
+
const tx = await walletOrSigner.sendTransaction(txRequest);
|
|
273933
|
+
this.logger.debug("ERC20 transfer submitted", {
|
|
273934
|
+
txHash: tx.hash,
|
|
273935
|
+
target,
|
|
273936
|
+
tx
|
|
273937
|
+
});
|
|
273938
|
+
return { id: tx.hash, target };
|
|
273939
|
+
} catch (e12) {
|
|
273940
|
+
this.logger.error("Error creating/submitting ERC20 tx", {
|
|
273941
|
+
error: e12 instanceof Error ? e12.message : e12,
|
|
273942
|
+
target,
|
|
273943
|
+
tokenAmount,
|
|
273944
|
+
rpcEndpoint: this.gatewayUrl
|
|
273945
|
+
});
|
|
273946
|
+
throw e12;
|
|
273947
|
+
}
|
|
273948
|
+
}
|
|
273949
|
+
};
|
|
273950
|
+
|
|
273951
|
+
// src/common/token/usdc.ts
|
|
273952
|
+
var usdcNetworks = (useDevnet = false) => ({
|
|
273953
|
+
ethereum: {
|
|
273954
|
+
tokenContractAddress: useDevnet ? ethSepoliaUsdcAddress : ethMainnetUsdcAddress,
|
|
273955
|
+
rpcEndpoint: useDevnet ? tokenToDevGatewayMap.ethereum : defaultProdGatewayUrls.ethereum,
|
|
273956
|
+
defaultPollingOptions: defaultEthereumPollingOptions
|
|
273957
|
+
},
|
|
273958
|
+
base: {
|
|
273959
|
+
tokenContractAddress: useDevnet ? baseSepoliaUsdcAddress : baseMainnetUsdcAddress,
|
|
273960
|
+
rpcEndpoint: useDevnet ? tokenToDevGatewayMap["base-eth"] : defaultProdGatewayUrls["base-eth"],
|
|
273961
|
+
defaultPollingOptions: defaultBaseNetworkPollingOptions
|
|
273962
|
+
},
|
|
273963
|
+
polygon: {
|
|
273964
|
+
tokenContractAddress: useDevnet ? polygonAmoyUsdcAddress : polygonMainnetUsdcAddress,
|
|
273965
|
+
rpcEndpoint: useDevnet ? tokenToDevGatewayMap.pol : defaultProdGatewayUrls.pol,
|
|
273966
|
+
defaultPollingOptions: defaultPolygonPollingOptions
|
|
273967
|
+
}
|
|
273968
|
+
});
|
|
273969
|
+
var ethMainnetUsdcAddress = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
|
|
273970
|
+
var baseMainnetUsdcAddress = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
273971
|
+
var polygonMainnetUsdcAddress = "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359";
|
|
273972
|
+
var ethSepoliaUsdcAddress = "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238";
|
|
273973
|
+
var baseSepoliaUsdcAddress = "0x036CbD53842c5426634e7929541eC2318f3dCF7e";
|
|
273974
|
+
var polygonAmoyUsdcAddress = "0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582";
|
|
273975
|
+
var USDCToTokenAmount = (usdc) => new BigNumber2(usdc).times(1e6).valueOf();
|
|
273976
|
+
var USDCToken = class extends ERC20Token {
|
|
273977
|
+
constructor({
|
|
273978
|
+
network = "ethereum",
|
|
273979
|
+
logger: logger19,
|
|
273980
|
+
gatewayUrl,
|
|
273981
|
+
tokenContractAddress,
|
|
273982
|
+
pollingOptions,
|
|
273983
|
+
useDevnet
|
|
273984
|
+
} = {}) {
|
|
273985
|
+
if (useDevnet === void 0) {
|
|
273986
|
+
const keywords = ["sepolia", "amoy"];
|
|
273987
|
+
useDevnet = keywords.some(
|
|
273988
|
+
(keyword) => (gatewayUrl ?? "").toLowerCase().includes(keyword)
|
|
273989
|
+
);
|
|
273990
|
+
}
|
|
273991
|
+
const {
|
|
273992
|
+
tokenContractAddress: usdcContractAddress,
|
|
273993
|
+
rpcEndpoint,
|
|
273994
|
+
defaultPollingOptions
|
|
273995
|
+
} = usdcNetworks(useDevnet)[network];
|
|
273996
|
+
super({
|
|
273997
|
+
tokenContractAddress: tokenContractAddress ?? usdcContractAddress,
|
|
273998
|
+
logger: logger19,
|
|
273999
|
+
gatewayUrl: gatewayUrl ?? rpcEndpoint,
|
|
274000
|
+
pollingOptions: pollingOptions ?? defaultPollingOptions
|
|
274001
|
+
});
|
|
274002
|
+
}
|
|
274003
|
+
};
|
|
274004
|
+
|
|
273820
274005
|
// src/common/token/index.ts
|
|
273821
274006
|
var defaultTokenMap = {
|
|
273822
274007
|
arweave: (config2) => new ArweaveToken(config2),
|
|
@@ -273826,9 +274011,13 @@ var defaultTokenMap = {
|
|
|
273826
274011
|
"base-eth": (config2) => new BaseEthToken(config2),
|
|
273827
274012
|
kyve: (config2) => new KyveToken(config2),
|
|
273828
274013
|
matic: (config2) => new PolygonToken(config2),
|
|
273829
|
-
pol: (config2) => new PolygonToken(config2)
|
|
274014
|
+
pol: (config2) => new PolygonToken(config2),
|
|
274015
|
+
usdc: (config2) => new USDCToken({ network: "ethereum", ...config2 }),
|
|
274016
|
+
"base-usdc": (config2) => new USDCToken({ network: "base", ...config2 }),
|
|
274017
|
+
"polygon-usdc": (config2) => new USDCToken({ network: "polygon", ...config2 })
|
|
273830
274018
|
};
|
|
273831
274019
|
var ethExponent = 18;
|
|
274020
|
+
var usdcExponent = 6;
|
|
273832
274021
|
var exponentMap = {
|
|
273833
274022
|
arweave: 12,
|
|
273834
274023
|
ario: 6,
|
|
@@ -273837,7 +274026,10 @@ var exponentMap = {
|
|
|
273837
274026
|
"base-eth": ethExponent,
|
|
273838
274027
|
kyve: 6,
|
|
273839
274028
|
matic: ethExponent,
|
|
273840
|
-
pol: ethExponent
|
|
274029
|
+
pol: ethExponent,
|
|
274030
|
+
usdc: usdcExponent,
|
|
274031
|
+
"base-usdc": usdcExponent,
|
|
274032
|
+
"polygon-usdc": usdcExponent
|
|
273841
274033
|
};
|
|
273842
274034
|
var tokenToBaseMap = {
|
|
273843
274035
|
arweave: (a8) => ARToTokenAmount(a8),
|
|
@@ -273847,7 +274039,10 @@ var tokenToBaseMap = {
|
|
|
273847
274039
|
"base-eth": (a8) => ETHToTokenAmount(a8),
|
|
273848
274040
|
kyve: (a8) => KYVEToTokenAmount(a8),
|
|
273849
274041
|
matic: (a8) => POLToTokenAmount(a8),
|
|
273850
|
-
pol: (a8) => POLToTokenAmount(a8)
|
|
274042
|
+
pol: (a8) => POLToTokenAmount(a8),
|
|
274043
|
+
usdc: (a8) => USDCToTokenAmount(a8),
|
|
274044
|
+
"base-usdc": (a8) => USDCToTokenAmount(a8),
|
|
274045
|
+
"polygon-usdc": (a8) => USDCToTokenAmount(a8)
|
|
273851
274046
|
};
|
|
273852
274047
|
function isTokenType(token) {
|
|
273853
274048
|
return tokenTypes.includes(token);
|
|
@@ -275133,7 +275328,12 @@ var TurboAuthenticatedBaseUploadService = class extends TurboUnauthenticatedUplo
|
|
|
275133
275328
|
paymentService
|
|
275134
275329
|
}) {
|
|
275135
275330
|
super({ url, retryConfig, logger: logger19, token });
|
|
275136
|
-
this.enabledOnDemandTokens = [
|
|
275331
|
+
this.enabledOnDemandTokens = [
|
|
275332
|
+
"ario",
|
|
275333
|
+
"solana",
|
|
275334
|
+
"base-eth",
|
|
275335
|
+
"base-usdc"
|
|
275336
|
+
];
|
|
275137
275337
|
this.signer = signer;
|
|
275138
275338
|
this.paymentService = paymentService;
|
|
275139
275339
|
}
|
|
@@ -276057,8 +276257,7 @@ var TurboBaseFactory = class {
|
|
|
276057
276257
|
}
|
|
276058
276258
|
return new HexSolanaSigner(walletAdapter);
|
|
276059
276259
|
}
|
|
276060
|
-
|
|
276061
|
-
if (ethTokens.has(token)) {
|
|
276260
|
+
if (supportedEvmSignerTokens.has(token)) {
|
|
276062
276261
|
if (!isEthereumWalletAdapter(walletAdapter)) {
|
|
276063
276262
|
throw new Error(
|
|
276064
276263
|
"Unsupported wallet adapter -- must implement getSigner"
|
|
@@ -276107,6 +276306,9 @@ var TurboDataItemAbstractSigner = class {
|
|
|
276107
276306
|
case "matic":
|
|
276108
276307
|
case "pol":
|
|
276109
276308
|
case "base-eth":
|
|
276309
|
+
case "usdc":
|
|
276310
|
+
case "base-usdc":
|
|
276311
|
+
case "polygon-usdc":
|
|
276110
276312
|
return computeAddress2(computePublicKey(fromB64Url(owner)));
|
|
276111
276313
|
case "kyve":
|
|
276112
276314
|
return (0, import_amino3.pubkeyToAddress)(
|
|
@@ -276629,7 +276831,10 @@ export {
|
|
|
276629
276831
|
createStreamWithUploadEvents,
|
|
276630
276832
|
creditSharingTagNames,
|
|
276631
276833
|
currencyMap,
|
|
276834
|
+
defaultBaseNetworkPollingOptions,
|
|
276835
|
+
defaultEthereumPollingOptions,
|
|
276632
276836
|
defaultPaymentServiceURL,
|
|
276837
|
+
defaultPolygonPollingOptions,
|
|
276633
276838
|
defaultTokenMap,
|
|
276634
276839
|
defaultTurboConfiguration,
|
|
276635
276840
|
defaultUploadServiceURL,
|
|
@@ -276660,6 +276865,7 @@ export {
|
|
|
276660
276865
|
signerFromKyveMnemonic,
|
|
276661
276866
|
signerFromKyvePrivateKey2 as signerFromKyvePrivateKey,
|
|
276662
276867
|
streamSignerReadableStream,
|
|
276868
|
+
supportedEvmSignerTokens,
|
|
276663
276869
|
tokenToBaseMap,
|
|
276664
276870
|
tokenTypes,
|
|
276665
276871
|
ukyveToTokenAmount,
|
|
@@ -141,8 +141,7 @@ class TurboBaseFactory {
|
|
|
141
141
|
}
|
|
142
142
|
return new arbundles_1.HexInjectedSolanaSigner(walletAdapter);
|
|
143
143
|
}
|
|
144
|
-
|
|
145
|
-
if (ethTokens.has(token)) {
|
|
144
|
+
if (types_js_1.supportedEvmSignerTokens.has(token)) {
|
|
146
145
|
if (!(0, types_js_1.isEthereumWalletAdapter)(walletAdapter)) {
|
|
147
146
|
throw new Error('Unsupported wallet adapter -- must implement getSigner');
|
|
148
147
|
}
|
package/lib/cjs/common/signer.js
CHANGED
|
@@ -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);
|