diff --git a/README.md b/README.md index ec50fb1a..b65e79ec 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionality for interac - [`topUpWithTokens({ tokenAmount, feeMultiplier })`](#topupwithtokens-tokenamount-feemultiplier-) - [Arweave (AR) Crypto Top Up](#arweave-ar-crypto-top-up) - [Ethereum (ETH) Crypto Top Up](#ethereum-eth-crypto-top-up) + - [Polygon (POL / MATIC) Crypto Top Up](#polygon-pol--matic-crypto-top-up) - [Solana (SOL) Crypto Top Up](#solana-sol-crypto-top-up) - [KYVE Crypto Top Up](#kyve-crypto-top-up) - [CLI](#cli) @@ -645,6 +646,16 @@ const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({ }); ``` +##### Polygon (POL / MATIC) Crypto Top Up + +```ts +const turbo = TurboFactory.authenticated({ signer, token: 'pol' }); + +const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({ + tokenAmount: POLToTokenAmount(0.00001), // 0.00001 POL +}); +``` + ##### Solana (SOL) Crypto Top Up ```ts diff --git a/codecov.yml b/codecov.yml index 2c71dae7..25b2c554 100644 --- a/codecov.yml +++ b/codecov.yml @@ -6,3 +6,4 @@ coverage: threshold: 1% ignore: - 'src/cli/*' + - 'src/common/token/*' diff --git a/src/cli/cli.ts b/src/cli/cli.ts index b8e47a8d..00aed79b 100644 --- a/src/cli/cli.ts +++ b/src/cli/cli.ts @@ -21,12 +21,12 @@ import { Command, program } from 'commander'; import { version } from '../version.js'; import { + balance, cryptoFund, - getBalance, topUp, uploadFile, uploadFolder, -} from './commands.js'; +} from './commands/index.js'; import { globalOptions, optionMap, @@ -50,7 +50,7 @@ applyOptions( program.command('balance').description('Get balance of a Turbo address'), [optionMap.address, ...walletOptions], ).action(async (_commandOptions, command: Command) => { - await runCommand(command, getBalance); + await runCommand(command, balance); }); applyOptions( diff --git a/src/cli/commands.ts b/src/cli/commands.ts deleted file mode 100644 index 4ea849fb..00000000 --- a/src/cli/commands.ts +++ /dev/null @@ -1,260 +0,0 @@ -/** - * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -import { exec } from 'node:child_process'; -import { createReadStream, statSync } from 'node:fs'; -import prompts from 'prompts'; - -import { - TurboFactory, - currencyMap, - fiatCurrencyTypes, - isCurrency, - tokenToBaseMap, -} from '../node/index.js'; -import { sleep } from '../utils/common.js'; -import { version } from '../version.js'; -import { - AddressOptions, - CryptoFundOptions, - TopUpOptions, - UploadFileOptions, - UploadFolderOptions, -} from './types.js'; -import { - addressOrPrivateKeyFromOptions, - configFromOptions, - getUploadFolderOptions, - tokenFromOptions, - turboFromOptions, -} from './utils.js'; - -export async function getBalance(options: AddressOptions) { - const config = configFromOptions(options); - - const { address, privateKey } = await addressOrPrivateKeyFromOptions(options); - - if (address !== undefined) { - const turbo = TurboFactory.unauthenticated(config); - const { winc } = await turbo.getBalance(address); - - console.log( - `Turbo Balance for Native Address "${address}"\nCredits: ${ - +winc / 1_000_000_000_000 - }`, - ); - return; - } - - if (privateKey === undefined) { - throw new Error('Must provide an (--address) or use a valid wallet'); - } - - const turbo = TurboFactory.authenticated({ - ...config, - privateKey, - }); - - const { winc } = await turbo.getBalance(); - console.log( - `Turbo Balance for Wallet Address "${await turbo.signer.getNativeAddress()}"\nCredits: ${ - +winc / 1_000_000_000_000 - }`, - ); -} - -/** Fund the connected signer with crypto */ -export async function cryptoFund(options: CryptoFundOptions) { - const value = options.value; - const txId = options.txId; - - if (txId !== undefined) { - const turbo = TurboFactory.unauthenticated(configFromOptions(options)); - const result = await turbo.submitFundTransaction({ txId: txId }); - - console.log( - 'Submitted existing crypto fund transaction to payment service: \n', - JSON.stringify(result, null, 2), - ); - return; - } - - if (value === undefined) { - throw new Error( - 'Must provide a --value or --transaction-id for crypto-fund command', - ); - } - - const turbo = await turboFromOptions(options); - - const token = tokenFromOptions(options); - const tokenAmount = tokenToBaseMap[token](value); - - if (!options.skipConfirmation) { - const { winc } = await turbo.getWincForToken({ tokenAmount }); - const targetWallet = (await turbo.getTurboCryptoWallets())[token]; - - const credits = (+winc / 1_000_000_000_000).toFixed(12); - - const { confirm } = await prompts({ - type: 'confirm', - name: 'confirm', - message: `\nTransaction details:\n\n Amount: ${value} ${token}\n Target: ${targetWallet}\n Credits received: ${credits}\n Credit recipient: ${await turbo.signer.getNativeAddress()}\n Network fees: (Gas fees apply)\n\nThis payment is non-refundable. Proceed with transaction?`, - initial: true, - }); - - if (!confirm) { - console.log('Aborted crypto fund transaction'); - return; - } - } - - const result = await turbo.topUpWithTokens({ - tokenAmount, - }); - - console.log( - 'Sent crypto fund transaction: \n', - JSON.stringify(result, null, 2), - ); -} - -export async function topUp(options: TopUpOptions) { - const config = configFromOptions(options); - - const { address, privateKey } = await addressOrPrivateKeyFromOptions(options); - - const value = options.value; - if (value === undefined) { - throw new Error('Must provide a --value to top up'); - } - - const currency = (options.currency ?? 'usd').toLowerCase(); - - if (!isCurrency(currency)) { - throw new Error( - `Invalid fiat currency type ${currency}!\nPlease use one of these:\n${JSON.stringify( - fiatCurrencyTypes, - null, - 2, - )}`, - ); - } - - // TODO: Pay in CLI prompts via --cli options - - const { url, paymentAmount, winc } = await (async () => { - const amount = currencyMap[currency](+value); - - if (address !== undefined) { - const turbo = TurboFactory.unauthenticated(config); - return turbo.createCheckoutSession({ - amount, - owner: address, - }); - } - - if (privateKey === undefined) { - throw new Error('Must provide a wallet to top up'); - } - - const turbo = TurboFactory.authenticated({ - ...config, - privateKey, - }); - return turbo.createCheckoutSession({ - amount, - owner: await turbo.signer.getNativeAddress(), - }); - })(); - - if (url === undefined) { - throw new Error('Failed to create checkout session'); - } - - console.log( - 'Got Checkout Session\n' + JSON.stringify({ url, paymentAmount, winc }), - ); - console.log('Opening checkout session in browser...'); - await sleep(2000); - - openUrl(url); -} - -export function openUrl(url: string) { - if (process.platform === 'darwin') { - // macOS - exec(`open ${url}`); - } else if (process.platform === 'win32') { - // Windows - exec(`start "" "${url}"`, { windowsHide: true }); - } else { - // Linux/Unix - open(url); - } -} - -const turboCliTags: { name: string; value: string }[] = [ - { name: 'App-Name', value: 'Turbo-CLI' }, - { name: 'App-Version', value: version }, - { name: 'App-Platform', value: process.platform }, -]; - -export async function uploadFolder( - options: UploadFolderOptions, -): Promise { - const turbo = await turboFromOptions(options); - - const { - disableManifest, - fallbackFile, - folderPath, - indexFile, - maxConcurrentUploads, - } = getUploadFolderOptions(options); - - const result = await turbo.uploadFolder({ - folderPath: folderPath, - dataItemOpts: { tags: [...turboCliTags] }, // TODO: Inject user tags - manifestOptions: { - disableManifest, - indexFile, - fallbackFile, - }, - maxConcurrentUploads, - }); - - console.log('Uploaded folder:', JSON.stringify(result, null, 2)); -} - -export async function uploadFile(options: UploadFileOptions): Promise { - const { filePath } = options; - if (filePath === undefined) { - throw new Error('Must provide a --file-path to upload'); - } - - const turbo = await turboFromOptions(options); - - const fileSize = statSync(filePath).size; - - const result = await turbo.uploadFile({ - fileStreamFactory: () => createReadStream(filePath), - fileSizeFactory: () => fileSize, - dataItemOpts: { tags: [...turboCliTags] }, // TODO: Inject user tags - }); - - console.log('Uploaded file:', JSON.stringify(result, null, 2)); -} diff --git a/src/cli/commands/balance.ts b/src/cli/commands/balance.ts new file mode 100644 index 00000000..cd30a2eb --- /dev/null +++ b/src/cli/commands/balance.ts @@ -0,0 +1,53 @@ +/** + * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +import { TurboFactory } from '../../node/factory.js'; +import { AddressOptions } from '../types.js'; +import { addressOrPrivateKeyFromOptions, configFromOptions } from '../utils.js'; + +export async function balance(options: AddressOptions) { + const config = configFromOptions(options); + + const { address, privateKey } = await addressOrPrivateKeyFromOptions(options); + + if (address !== undefined) { + const turbo = TurboFactory.unauthenticated(config); + const { winc } = await turbo.getBalance(address); + + console.log( + `Turbo Balance for Native Address "${address}"\nCredits: ${ + +winc / 1_000_000_000_000 + }`, + ); + return; + } + + if (privateKey === undefined) { + throw new Error('Must provide an (--address) or use a valid wallet'); + } + + const turbo = TurboFactory.authenticated({ + ...config, + privateKey, + }); + + const { winc } = await turbo.getBalance(); + console.log( + `Turbo Balance for Wallet Address "${await turbo.signer.getNativeAddress()}"\nCredits: ${ + +winc / 1_000_000_000_000 + }`, + ); +} diff --git a/src/cli/commands/cryptoFund.ts b/src/cli/commands/cryptoFund.ts new file mode 100644 index 00000000..943f2b96 --- /dev/null +++ b/src/cli/commands/cryptoFund.ts @@ -0,0 +1,81 @@ +/** + * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +import prompts from 'prompts'; + +import { tokenToBaseMap } from '../../common/index.js'; +import { TurboFactory } from '../../node/factory.js'; +import { CryptoFundOptions } from '../types.js'; +import { + configFromOptions, + tokenFromOptions, + turboFromOptions, +} from '../utils.js'; + +export async function cryptoFund(options: CryptoFundOptions) { + const value = options.value; + const txId = options.txId; + + if (txId !== undefined) { + const turbo = TurboFactory.unauthenticated(configFromOptions(options)); + const result = await turbo.submitFundTransaction({ txId: txId }); + + console.log( + 'Submitted existing crypto fund transaction to payment service: \n', + JSON.stringify(result, null, 2), + ); + return; + } + + if (value === undefined) { + throw new Error( + 'Must provide a --value or --transaction-id for crypto-fund command', + ); + } + + const turbo = await turboFromOptions(options); + + const token = tokenFromOptions(options); + const tokenAmount = tokenToBaseMap[token](value); + + if (!options.skipConfirmation) { + const { winc } = await turbo.getWincForToken({ tokenAmount }); + const targetWallet = (await turbo.getTurboCryptoWallets())[token]; + + const credits = (+winc / 1_000_000_000_000).toFixed(12); + + const { confirm } = await prompts({ + type: 'confirm', + name: 'confirm', + message: `\nTransaction details:\n\n Amount: ${value} ${token}\n Target: ${targetWallet}\n Credits received: ${credits}\n Credit recipient: ${await turbo.signer.getNativeAddress()}\n Network fees: (Gas fees apply)\n\nThis payment is non-refundable. Proceed with transaction?`, + initial: true, + }); + + if (!confirm) { + console.log('Aborted crypto fund transaction'); + return; + } + } + + const result = await turbo.topUpWithTokens({ + tokenAmount, + }); + + console.log( + 'Sent crypto fund transaction: \n', + JSON.stringify(result, null, 2), + ); +} diff --git a/src/cli/commands/index.ts b/src/cli/commands/index.ts new file mode 100644 index 00000000..45f49fa5 --- /dev/null +++ b/src/cli/commands/index.ts @@ -0,0 +1,22 @@ +/** + * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +export * from './balance.js'; +export * from './cryptoFund.js'; +export * from './topUp.js'; +export * from './uploadFile.js'; +export * from './uploadFolder.js'; diff --git a/src/cli/commands/topUp.ts b/src/cli/commands/topUp.ts new file mode 100644 index 00000000..31113124 --- /dev/null +++ b/src/cli/commands/topUp.ts @@ -0,0 +1,99 @@ +/** + * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +import { exec } from 'child_process'; + +import { currencyMap } from '../../common/currency.js'; +import { TurboFactory } from '../../node/factory.js'; +import { fiatCurrencyTypes, isCurrency } from '../../types.js'; +import { sleep } from '../../utils/common.js'; +import { TopUpOptions } from '../types.js'; +import { addressOrPrivateKeyFromOptions, configFromOptions } from '../utils.js'; + +function openUrl(url: string) { + if (process.platform === 'darwin') { + // macOS + exec(`open ${url}`); + } else if (process.platform === 'win32') { + // Windows + exec(`start "" "${url}"`, { windowsHide: true }); + } else { + // Linux/Unix + open(url); + } +} + +export async function topUp(options: TopUpOptions) { + const config = configFromOptions(options); + + const { address, privateKey } = await addressOrPrivateKeyFromOptions(options); + + const value = options.value; + if (value === undefined) { + throw new Error('Must provide a --value to top up'); + } + + const currency = (options.currency ?? 'usd').toLowerCase(); + + if (!isCurrency(currency)) { + throw new Error( + `Invalid fiat currency type ${currency}!\nPlease use one of these:\n${JSON.stringify( + fiatCurrencyTypes, + null, + 2, + )}`, + ); + } + + // TODO: Pay in CLI prompts via --cli options + + const { url, paymentAmount, winc } = await (async () => { + const amount = currencyMap[currency](+value); + + if (address !== undefined) { + const turbo = TurboFactory.unauthenticated(config); + return turbo.createCheckoutSession({ + amount, + owner: address, + }); + } + + if (privateKey === undefined) { + throw new Error('Must provide a wallet to top up'); + } + + const turbo = TurboFactory.authenticated({ + ...config, + privateKey, + }); + return turbo.createCheckoutSession({ + amount, + owner: await turbo.signer.getNativeAddress(), + }); + })(); + + if (url === undefined) { + throw new Error('Failed to create checkout session'); + } + + console.log( + 'Got Checkout Session\n' + JSON.stringify({ url, paymentAmount, winc }), + ); + console.log('Opening checkout session in browser...'); + await sleep(2000); + + openUrl(url); +} diff --git a/src/cli/commands/uploadFile.ts b/src/cli/commands/uploadFile.ts new file mode 100644 index 00000000..0fe2631e --- /dev/null +++ b/src/cli/commands/uploadFile.ts @@ -0,0 +1,40 @@ +/** + * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +import { createReadStream, statSync } from 'fs'; + +import { turboCliTags } from '../constants.js'; +import { UploadFileOptions } from '../types.js'; +import { turboFromOptions } from '../utils.js'; + +export async function uploadFile(options: UploadFileOptions): Promise { + const { filePath } = options; + if (filePath === undefined) { + throw new Error('Must provide a --file-path to upload'); + } + + const turbo = await turboFromOptions(options); + + const fileSize = statSync(filePath).size; + + const result = await turbo.uploadFile({ + fileStreamFactory: () => createReadStream(filePath), + fileSizeFactory: () => fileSize, + dataItemOpts: { tags: [...turboCliTags] }, // TODO: Inject user tags + }); + + console.log('Uploaded file:', JSON.stringify(result, null, 2)); +} diff --git a/src/cli/commands/uploadFolder.ts b/src/cli/commands/uploadFolder.ts new file mode 100644 index 00000000..385cdbc9 --- /dev/null +++ b/src/cli/commands/uploadFolder.ts @@ -0,0 +1,46 @@ +/** + * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +import { turboCliTags } from '../constants.js'; +import { UploadFolderOptions } from '../types.js'; +import { getUploadFolderOptions, turboFromOptions } from '../utils.js'; + +export async function uploadFolder( + options: UploadFolderOptions, +): Promise { + const turbo = await turboFromOptions(options); + + const { + disableManifest, + fallbackFile, + folderPath, + indexFile, + maxConcurrentUploads, + } = getUploadFolderOptions(options); + + const result = await turbo.uploadFolder({ + folderPath: folderPath, + dataItemOpts: { tags: [...turboCliTags] }, // TODO: Inject user tags + manifestOptions: { + disableManifest, + indexFile, + fallbackFile, + }, + maxConcurrentUploads, + }); + + console.log('Uploaded folder:', JSON.stringify(result, null, 2)); +} diff --git a/src/cli/constants.ts b/src/cli/constants.ts new file mode 100644 index 00000000..e3a13ddf --- /dev/null +++ b/src/cli/constants.ts @@ -0,0 +1,23 @@ +/** + * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +import { version } from '../version.js'; + +export const turboCliTags: { name: string; value: string }[] = [ + { name: 'App-Name', value: 'Turbo-CLI' }, + { name: 'App-Version', value: version }, + { name: 'App-Platform', value: process.platform }, +]; diff --git a/src/common/token/index.ts b/src/common/token/index.ts index 50bd56f1..f57fb91d 100644 --- a/src/common/token/index.ts +++ b/src/common/token/index.ts @@ -25,6 +25,7 @@ import { import { ARToTokenAmount, ArweaveToken } from './arweave.js'; import { ETHToTokenAmount, EthereumToken } from './ethereum.js'; import { KYVEToTokenAmount, KyveToken } from './kyve.js'; +import { POLToTokenAmount, PolygonToken } from './polygon.js'; import { SOLToTokenAmount, SolanaToken } from './solana.js'; export const defaultTokenMap: TokenFactory = { @@ -32,6 +33,8 @@ export const defaultTokenMap: TokenFactory = { solana: (config: TokenConfig) => new SolanaToken(config), ethereum: (config: TokenConfig) => new EthereumToken(config), kyve: (config: TokenConfig) => new KyveToken(config), + matic: (config: TokenConfig) => new PolygonToken(config), + pol: (config: TokenConfig) => new PolygonToken(config), } as const; export const tokenToBaseMap: Record< @@ -42,8 +45,8 @@ export const tokenToBaseMap: Record< solana: (a: BigNumber.Value) => SOLToTokenAmount(a), ethereum: (a: BigNumber.Value) => ETHToTokenAmount(a), kyve: (a: BigNumber.Value) => KYVEToTokenAmount(a), - matic: (a: BigNumber.Value) => ETHToTokenAmount(a), - pol: (a: BigNumber.Value) => ETHToTokenAmount(a), + matic: (a: BigNumber.Value) => POLToTokenAmount(a), + pol: (a: BigNumber.Value) => POLToTokenAmount(a), } as const; export function isTokenType(token: string): token is TokenType { diff --git a/src/common/token/polygon.ts b/src/common/token/polygon.ts new file mode 100644 index 00000000..82217ffc --- /dev/null +++ b/src/common/token/polygon.ts @@ -0,0 +1,35 @@ +/** + * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +import { TokenConfig } from '../../types.js'; +import { TurboWinstonLogger } from '../logger.js'; +import { ETHToTokenAmount, EthereumToken } from './ethereum.js'; + +export const POLToTokenAmount = ETHToTokenAmount; + +export class PolygonToken extends EthereumToken { + constructor({ + logger = TurboWinstonLogger.default, + gatewayUrl = 'https://polygon-rpc.com/', + pollingOptions = { + maxAttempts: 10, + pollingIntervalMs: 4_000, + initialBackoffMs: 5_000, + }, + }: TokenConfig = {}) { + super({ logger, gatewayUrl, pollingOptions }); + } +} diff --git a/src/common/turbo.ts b/src/common/turbo.ts index c622fb49..bb44a6cb 100644 --- a/src/common/turbo.ts +++ b/src/common/turbo.ts @@ -203,8 +203,10 @@ export class TurboUnauthenticatedClient /** * Returns the connected target Turbo wallet addresses for all supported tokens. */ - getTurboCryptoWallets(): Promise> { - return this.paymentService.getTurboCryptoWallets(); + async getTurboCryptoWallets(): Promise> { + const wallets = await this.paymentService.getTurboCryptoWallets(); + wallets.pol = wallets.matic; + return wallets; } }