Skip to content

Commit

Permalink
feat(solana payments): MVP for SOL topup on CLI PE-5993
Browse files Browse the repository at this point in the history
  • Loading branch information
fedellen committed Apr 29, 2024
1 parent 751dfd3 commit ad1de1e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 11 additions & 5 deletions src/commands/crypto_fund.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -10,20 +10,26 @@ 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',
parameters: [ArAmountParameter, BoostParameter, DryRunParameter, ...WalletTypeParameters, GatewayParameter],
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;
Expand Down

0 comments on commit ad1de1e

Please sign in to comment.