Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bundlr funding issue for small files #1970

Merged
merged 1 commit into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions js/packages/cli/src/candy-machine-v2-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ programCommand('upload')
rateLimit,
collectionMintPubkey,
setCollectionMint,
rpcUrl,
});
} catch (err) {
log.warn('upload was not successful, please re-run.', err);
Expand Down
3 changes: 3 additions & 0 deletions js/packages/cli/src/commands/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export async function uploadV2({
rateLimit,
collectionMintPubkey,
setCollectionMint,
rpcUrl,
}: {
files: string[];
cacheName: string;
Expand Down Expand Up @@ -99,6 +100,7 @@ export async function uploadV2({
rateLimit: number;
collectionMintPubkey: null | PublicKey;
setCollectionMint: boolean;
rpcUrl: null | string;
}): Promise<boolean> {
const savedContent = loadCache(cacheName, env);
const cacheContent = savedContent || {};
Expand Down Expand Up @@ -234,6 +236,7 @@ export async function uploadV2({
: undefined,
storage === StorageType.ArweaveSol ? walletKeyPair : undefined,
batchSize,
rpcUrl,
);

let result = arweaveBundleUploadGenerator.next();
Expand Down
12 changes: 9 additions & 3 deletions js/packages/cli/src/helpers/upload/arweave-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ export function* makeArweaveBundleUploadGenerator(
jwk?: any,
walletKeyPair?: Keypair,
batchSize?: number,
rpcUrl?: string,
): Generator<Promise<UploadGeneratorResult>> {
let signer: ArweaveSigner;
const storageType: StorageType = storage;
Expand All @@ -487,6 +488,10 @@ export function* makeArweaveBundleUploadGenerator(
'https://node1.bundlr.network',
'solana',
walletKeyPair.secretKey,
{
timeout: 60000,
providerUrl: rpcUrl ?? 'https://api.metaplex.rpcpool.com',
},
)
: new Bundlr(
'https://devnet.bundlr.network',
Expand Down Expand Up @@ -603,16 +608,17 @@ export function* makeArweaveBundleUploadGenerator(
] as unknown as BundlrTransaction[];
log.info('Uploading bundle via Bundlr... in multiple transactions');
const bytes = (dataItems as unknown as BundlrTransaction[]).reduce(
(c, d) => c + d.getRaw().length,
(c, d) => c + Math.max(d.getRaw().length, 12000),
0,
);
const cost = await bundlr.utils.getPrice('solana', bytes);
const bufferCost = cost.multipliedBy(3).dividedToIntegerBy(2);
log.info(
`${(cost.toNumber() * 2) / LAMPORTS} SOL to upload ${sizeMB(
`${bufferCost.toNumber() / LAMPORTS} SOL to upload ${sizeMB(
bytes,
)}MB with buffer. Sending fund txn...`,
);
await bundlr.fund(cost.multipliedBy(2));
await bundlr.fund(bufferCost);
log.info(`Successfully funded Arweave Bundler, starting upload`);

const progressBar = new cliProgress.SingleBar(
Expand Down
5 changes: 5 additions & 0 deletions js/packages/cli/test/run-test-v2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ SRC_DIR=$PARENT_DIR/src
CMD_CMV2="ts-node ${SRC_DIR}/candy-machine-v2-cli.ts"

# Remote files to test the upload
PNG_MIN="https://arweave.net/N3LqmO6yURUK1JxV9MJtH8YeqppEtZhKuy3RB0Tqm3A/?ext=png"
PNG="https://arweave.net/izpWaFnueKtbRg4TY-CkUYQtwSzPNit3ZvQPY5hOK7E/?ext=png"
GIF="https://arweave.net/3I50hy1dHhRwyxtKPL60WIl4kV0rqjnl7t_DcZPAp2o/?ext=gif"
JPG="https://arweave.net/-KqqzJLtD8Pug-aCjbV6RWbGhfB74MBT71afqGFKYHA/?ext=jpg"
Expand Down Expand Up @@ -257,6 +258,10 @@ else
png)
IMAGE=$PNG
;;
png_min)
IMAGE=$PNG_MIN
EXT="png"
;;
jpg)
IMAGE=$JPG
;;
Expand Down