Skip to content

Commit

Permalink
Merge pull request #176 from ardriveapp/PE-6722-pol-crypto-fund
Browse files Browse the repository at this point in the history
feat(pol): add support for matic/pol crypto fund PE-6722
  • Loading branch information
fedellen authored Sep 13, 2024
2 parents 8dcdae7 + a48d902 commit 032db83
Show file tree
Hide file tree
Showing 14 changed files with 423 additions and 267 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ coverage:
threshold: 1%
ignore:
- 'src/cli/*'
- 'src/common/token/*'
6 changes: 3 additions & 3 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down
260 changes: 0 additions & 260 deletions src/cli/commands.ts

This file was deleted.

53 changes: 53 additions & 0 deletions src/cli/commands/balance.ts
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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
}`,
);
}
Loading

0 comments on commit 032db83

Please sign in to comment.