From ad1de1e32e933fb6e08ea630d6e32b58e61cafa0 Mon Sep 17 00:00:00 2001 From: Derek Sonnenberg Date: Mon, 29 Apr 2024 16:21:06 -0500 Subject: [PATCH] feat(solana payments): MVP for SOL topup on CLI PE-5993 --- package.json | 4 +++- src/commands/crypto_fund.ts | 16 +++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index ccd030af..ed82a82c 100644 --- a/package.json +++ b/package.json @@ -8,11 +8,13 @@ }, "types": "./lib/index.d.ts", "dependencies": { - "@ardrive/turbo-sdk": "^1.5.0", + "@ardrive/turbo-sdk": "link:../ardrive-turbo-sdk", + "@solana/web3.js": "^1.91.7", "ardrive-core-js": "2.0.2", "arweave": "1.11.4", "axios": "^0.21.1", "bn.js": "^5.2.1", + "bs58": "^5.0.0", "commander": "^8.2.0", "ipfs-only-hash": "^4.0.0", "lodash": "^4.17.21", diff --git a/src/commands/crypto_fund.ts b/src/commands/crypto_fund.ts index d41704b6..ff8975df 100644 --- a/src/commands/crypto_fund.ts +++ b/src/commands/crypto_fund.ts @@ -1,4 +1,4 @@ -import { AR, JWKWallet, Winston } from 'ardrive-core-js'; +import { AR, JWKWallet } from 'ardrive-core-js'; import { CLICommand } from '../CLICommand'; import { ParametersHelper } from '../CLICommand'; import { CLIAction } from '../CLICommand/action'; @@ -10,7 +10,8 @@ import { GatewayParameter, WalletTypeParameters } from '../parameter_declarations'; -import { TurboFactory, WinstonToTokenAmount } from '@ardrive/turbo-sdk'; +import { TurboFactory, HexSolanaSigner } from '@ardrive/turbo-sdk'; +import bs58 from 'bs58'; new CLICommand({ name: 'crypto-fund', @@ -18,12 +19,17 @@ new CLICommand({ action: new CLIAction(async function action(options) { const parameters = new ParametersHelper(options); const arAmount = parameters.getRequiredParameterValue(ArAmountParameter, AR.from); - const winston: Winston = arAmount.toWinston(); + const ar = arAmount; const jwkWallet = (await parameters.getRequiredWallet()) as JWKWallet; - const turbo = TurboFactory.authenticated({ privateKey: jwkWallet.getPrivateKey() }); + const signer = new HexSolanaSigner(bs58.encode(jwkWallet['jwk'])); + const turbo = TurboFactory.authenticated({ + signer, + gatewayUrl: 'https://api.devnet.solana.com', + paymentServiceConfig: { url: 'https://payment.ardrive.dev' } + }); - const res = await turbo.topUpWithTokens({ tokenAmount: WinstonToTokenAmount(winston.valueOf()) }); + const res = await turbo.topUpWithTokens({ tokenAmount: +ar.valueOf() * 1e9 }); console.log('res', JSON.stringify(res, null, 2)); return SUCCESS_EXIT_CODE;