@streamflow/stream 12.1.1 → 12.2.1-alpha.p361.abedd84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index-CjMTLhxa.d.cts +1114 -0
- package/dist/cjs/index.cjs +486 -21
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +5 -4
- package/dist/cjs/solana/api/index.cjs +5402 -0
- package/dist/cjs/solana/api/index.cjs.map +1 -0
- package/dist/cjs/solana/api/index.d.cts +8 -0
- package/dist/cjs/solana/index.cjs +486 -21
- package/dist/cjs/solana/index.cjs.map +1 -1
- package/dist/cjs/solana/index.d.cts +8 -902
- package/dist/esm/index-Cu0If4Dd.d.ts +1114 -0
- package/dist/esm/index.d.ts +5 -4
- package/dist/esm/index.js +463 -22
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solana/api/index.d.ts +8 -0
- package/dist/esm/solana/api/index.js +5352 -0
- package/dist/esm/solana/api/index.js.map +1 -0
- package/dist/esm/solana/index.d.ts +8 -902
- package/dist/esm/solana/index.js +463 -22
- package/dist/esm/solana/index.js.map +1 -1
- package/package.json +19 -6
package/dist/cjs/index.cjs
CHANGED
|
@@ -632,9 +632,9 @@ var decodeStream = (buf) => {
|
|
|
632
632
|
};
|
|
633
633
|
};
|
|
634
634
|
async function signAllTransactionWithRecipients(sender, items) {
|
|
635
|
-
const
|
|
635
|
+
const isKeypair2 = common.isSignerKeypair(sender);
|
|
636
636
|
const isWallet = common.isSignerWallet(sender);
|
|
637
|
-
if (
|
|
637
|
+
if (isKeypair2) {
|
|
638
638
|
return items.map((t) => {
|
|
639
639
|
t.tx.sign([sender]);
|
|
640
640
|
return { tx: t.tx, recipient: t.recipient };
|
|
@@ -3349,6 +3349,19 @@ var SolanaStreamClient = class {
|
|
|
3349
3349
|
this.schedulingParams = {
|
|
3350
3350
|
sendThrottler: sendThrottler ?? common.buildSendThrottler(sendRate)
|
|
3351
3351
|
};
|
|
3352
|
+
} else if ("connection" in optionsOrClusterUrl) {
|
|
3353
|
+
const { connection, cluster: cluster2, commitment: commitment2, programId: programId2 = "", sendScheduler } = optionsOrClusterUrl;
|
|
3354
|
+
this.connection = connection;
|
|
3355
|
+
this.commitment = commitment2 ?? "confirmed";
|
|
3356
|
+
this.programId = programId2 !== "" ? new web3_js.PublicKey(programId2) : new web3_js.PublicKey(PROGRAM_ID[cluster2]);
|
|
3357
|
+
this.partnerOracleProgramId = new web3_js.PublicKey(PARTNER_ORACLE_PROGRAM_ID[cluster2]);
|
|
3358
|
+
this.feeOraclePublicKey = new web3_js.PublicKey(FEE_ORACLE_PUBLIC_KEY[cluster2]);
|
|
3359
|
+
const schedulingOptions = sendScheduler && "sendRate" in sendScheduler ? sendScheduler : void 0;
|
|
3360
|
+
const sendThrottler2 = !sendScheduler ? common.buildSendThrottler(1) : "sendRate" in sendScheduler ? common.buildSendThrottler(sendScheduler.sendRate ?? 1, sendScheduler.sendInterval) : sendScheduler;
|
|
3361
|
+
this.schedulingParams = {
|
|
3362
|
+
...schedulingOptions,
|
|
3363
|
+
sendThrottler: sendThrottler2
|
|
3364
|
+
};
|
|
3352
3365
|
} else {
|
|
3353
3366
|
const {
|
|
3354
3367
|
clusterUrl,
|
|
@@ -3375,7 +3388,7 @@ var SolanaStreamClient = class {
|
|
|
3375
3388
|
};
|
|
3376
3389
|
this.alignedProxyProgram = new anchor.Program(alignedUnlocksProgram, { connection: this.connection });
|
|
3377
3390
|
this.apiClient = createClient(
|
|
3378
|
-
typeof optionsOrClusterUrl === "object" && optionsOrClusterUrl.cluster !== common.ICluster.Mainnet ? { cluster: "devnet" } : { cluster: "mainnet" }
|
|
3391
|
+
typeof optionsOrClusterUrl === "object" && ("connection" in optionsOrClusterUrl ? optionsOrClusterUrl.cluster !== common.ICluster.Mainnet : optionsOrClusterUrl.cluster !== common.ICluster.Mainnet) ? { cluster: "devnet" } : { cluster: "mainnet" }
|
|
3379
3392
|
);
|
|
3380
3393
|
}
|
|
3381
3394
|
getConnection() {
|
|
@@ -4088,7 +4101,7 @@ var SolanaStreamClient = class {
|
|
|
4088
4101
|
}
|
|
4089
4102
|
const signedBatch = await signAllTransactionWithRecipients(sender, batch);
|
|
4090
4103
|
if (prepareInstructions.length > 0) {
|
|
4091
|
-
const prepareTx = signedBatch.
|
|
4104
|
+
const prepareTx = signedBatch.pop();
|
|
4092
4105
|
await sendAndConfirmStreamRawTransaction(this.connection, prepareTx, { hash, context }, this.schedulingParams);
|
|
4093
4106
|
}
|
|
4094
4107
|
const responses = [];
|
|
@@ -4183,9 +4196,9 @@ var SolanaStreamClient = class {
|
|
|
4183
4196
|
mintAccount,
|
|
4184
4197
|
tokenProgramId,
|
|
4185
4198
|
potentialTransfers: [
|
|
4186
|
-
{ source: escrowTokens, destination: recipientTokens, owner:
|
|
4187
|
-
{ source: escrowTokens, destination: streamflowTreasuryTokens, owner:
|
|
4188
|
-
{ source: escrowTokens, destination: partnerTokens, owner:
|
|
4199
|
+
{ source: escrowTokens, destination: recipientTokens, owner: escrowTokens },
|
|
4200
|
+
{ source: escrowTokens, destination: streamflowTreasuryTokens, owner: escrowTokens },
|
|
4201
|
+
{ source: escrowTokens, destination: partnerTokens, owner: escrowTokens }
|
|
4189
4202
|
]
|
|
4190
4203
|
});
|
|
4191
4204
|
ixs.push(...ataIx, withdrawIx);
|
|
@@ -4277,10 +4290,10 @@ var SolanaStreamClient = class {
|
|
|
4277
4290
|
mintAccount,
|
|
4278
4291
|
tokenProgramId,
|
|
4279
4292
|
potentialTransfers: [
|
|
4280
|
-
{ source: escrowTokens, destination: recipientTokens, owner:
|
|
4281
|
-
{ source: escrowTokens, destination: streamflowTreasuryTokens, owner:
|
|
4282
|
-
{ source: escrowTokens, destination: partnerTokens, owner:
|
|
4283
|
-
{ source: escrowTokens, destination: proxyTokens, owner:
|
|
4293
|
+
{ source: escrowTokens, destination: recipientTokens, owner: escrowTokens },
|
|
4294
|
+
{ source: escrowTokens, destination: streamflowTreasuryTokens, owner: escrowTokens },
|
|
4295
|
+
{ source: escrowTokens, destination: partnerTokens, owner: escrowTokens },
|
|
4296
|
+
{ source: escrowTokens, destination: proxyTokens, owner: escrowTokens },
|
|
4284
4297
|
{ source: proxyTokens, destination: senderTokens, owner: proxyMetadata }
|
|
4285
4298
|
]
|
|
4286
4299
|
});
|
|
@@ -4334,10 +4347,10 @@ var SolanaStreamClient = class {
|
|
|
4334
4347
|
mintAccount,
|
|
4335
4348
|
tokenProgramId,
|
|
4336
4349
|
potentialTransfers: [
|
|
4337
|
-
{ source: escrowTokens, destination: recipientTokens, owner:
|
|
4338
|
-
{ source: escrowTokens, destination: streamflowTreasuryTokens, owner:
|
|
4339
|
-
{ source: escrowTokens, destination: partnerTokens, owner:
|
|
4340
|
-
{ source: escrowTokens, destination: senderTokens, owner:
|
|
4350
|
+
{ source: escrowTokens, destination: recipientTokens, owner: escrowTokens },
|
|
4351
|
+
{ source: escrowTokens, destination: streamflowTreasuryTokens, owner: escrowTokens },
|
|
4352
|
+
{ source: escrowTokens, destination: partnerTokens, owner: escrowTokens },
|
|
4353
|
+
{ source: escrowTokens, destination: senderTokens, owner: escrowTokens }
|
|
4341
4354
|
]
|
|
4342
4355
|
});
|
|
4343
4356
|
ixs.push(...ixsAta, cancelIx);
|
|
@@ -4526,11 +4539,13 @@ var SolanaStreamClient = class {
|
|
|
4526
4539
|
if (!escrow?.data) {
|
|
4527
4540
|
throw new Error("Couldn't get account info");
|
|
4528
4541
|
}
|
|
4529
|
-
const { mint, partner, senderTokens, escrowTokens } = decodeStream(
|
|
4542
|
+
const { mint, partner, senderTokens, escrowTokens, partnerFeePercent, streamflowFeePercent } = decodeStream(
|
|
4543
|
+
escrow?.data
|
|
4544
|
+
);
|
|
4530
4545
|
const { mint: mintAccount, tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
|
|
4531
4546
|
const streamflowTreasuryTokens = await common.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
4532
4547
|
const partnerTokens = await common.ata(mint, partner, tokenProgramId);
|
|
4533
|
-
const totalFee =
|
|
4548
|
+
const totalFee = partnerFeePercent + streamflowFeePercent;
|
|
4534
4549
|
const totalAmountToTransfer = calculateTotalAmountToDeposit(amount, totalFee);
|
|
4535
4550
|
if (isNative) {
|
|
4536
4551
|
ixs.push(...await common.prepareWrappedAccount(this.connection, invoker.publicKey, totalAmountToTransfer));
|
|
@@ -4981,15 +4996,15 @@ var SolanaStreamClient = class {
|
|
|
4981
4996
|
if (!transferHookProgramId) {
|
|
4982
4997
|
return;
|
|
4983
4998
|
}
|
|
4984
|
-
for (const
|
|
4999
|
+
for (const transfer2 of potentialTransfers) {
|
|
4985
5000
|
await splToken.addExtraAccountMetasForExecute(
|
|
4986
5001
|
this.connection,
|
|
4987
5002
|
instruction,
|
|
4988
5003
|
transferHookProgramId,
|
|
4989
|
-
|
|
5004
|
+
transfer2.source,
|
|
4990
5005
|
mint,
|
|
4991
|
-
|
|
4992
|
-
|
|
5006
|
+
transfer2.destination,
|
|
5007
|
+
transfer2.owner,
|
|
4993
5008
|
1n,
|
|
4994
5009
|
this.getCommitment()
|
|
4995
5010
|
);
|
|
@@ -5439,6 +5454,432 @@ var timelockIDL_default = {
|
|
|
5439
5454
|
}
|
|
5440
5455
|
]
|
|
5441
5456
|
};
|
|
5457
|
+
function normalizeInvoker(invoker) {
|
|
5458
|
+
if (typeof invoker.publicKey === "string") {
|
|
5459
|
+
return { ...invoker, publicKey: common.pk(invoker.publicKey) };
|
|
5460
|
+
}
|
|
5461
|
+
return invoker;
|
|
5462
|
+
}
|
|
5463
|
+
function resolveConnection(env) {
|
|
5464
|
+
if ("connection" in env) {
|
|
5465
|
+
return env.connection;
|
|
5466
|
+
}
|
|
5467
|
+
return new web3_js.Connection(env.rpcUrl, {
|
|
5468
|
+
commitment: env.commitment
|
|
5469
|
+
});
|
|
5470
|
+
}
|
|
5471
|
+
function createClientFromEnv(env) {
|
|
5472
|
+
if (env.client) return env.client;
|
|
5473
|
+
if ("connection" in env) {
|
|
5474
|
+
return new SolanaStreamClient({
|
|
5475
|
+
connection: env.connection,
|
|
5476
|
+
cluster: env.cluster,
|
|
5477
|
+
commitment: env.commitment,
|
|
5478
|
+
programId: env.programId.toBase58()
|
|
5479
|
+
});
|
|
5480
|
+
}
|
|
5481
|
+
return new SolanaStreamClient(env.rpcUrl, env.cluster ?? common.ICluster.Mainnet, env.commitment, env.programId.toBase58());
|
|
5482
|
+
}
|
|
5483
|
+
|
|
5484
|
+
// solana/api/create.ts
|
|
5485
|
+
async function create(params, invoker, env) {
|
|
5486
|
+
const client = createClientFromEnv(env);
|
|
5487
|
+
const { ixs, metadataId, metadata } = await client.buildCreateTransactionInstructions(params, {
|
|
5488
|
+
sender: normalizeInvoker(invoker),
|
|
5489
|
+
isNative: env.isNative ?? false
|
|
5490
|
+
});
|
|
5491
|
+
return {
|
|
5492
|
+
instructions: ixs,
|
|
5493
|
+
signers: metadata ? [metadata] : void 0,
|
|
5494
|
+
metadata,
|
|
5495
|
+
metadataPubKey: new web3_js.PublicKey(metadataId)
|
|
5496
|
+
};
|
|
5497
|
+
}
|
|
5498
|
+
|
|
5499
|
+
// solana/api/withdraw.ts
|
|
5500
|
+
async function withdraw(params, invoker, env) {
|
|
5501
|
+
const client = createClientFromEnv(env);
|
|
5502
|
+
const ixs = await client.prepareWithdrawInstructions(params, {
|
|
5503
|
+
invoker: normalizeInvoker(invoker)
|
|
5504
|
+
});
|
|
5505
|
+
return { instructions: ixs };
|
|
5506
|
+
}
|
|
5507
|
+
|
|
5508
|
+
// solana/api/topup.ts
|
|
5509
|
+
async function topup(params, invoker, env) {
|
|
5510
|
+
const client = createClientFromEnv(env);
|
|
5511
|
+
const ixs = await client.prepareTopupInstructions(params, {
|
|
5512
|
+
invoker: normalizeInvoker(invoker),
|
|
5513
|
+
isNative: env.isNative ?? false
|
|
5514
|
+
});
|
|
5515
|
+
return { instructions: ixs };
|
|
5516
|
+
}
|
|
5517
|
+
|
|
5518
|
+
// solana/api/cancel.ts
|
|
5519
|
+
async function cancel(params, invoker, env) {
|
|
5520
|
+
const client = createClientFromEnv(env);
|
|
5521
|
+
const ixs = await client.prepareCancelInstructions(params, {
|
|
5522
|
+
invoker: normalizeInvoker(invoker)
|
|
5523
|
+
});
|
|
5524
|
+
return { instructions: ixs };
|
|
5525
|
+
}
|
|
5526
|
+
|
|
5527
|
+
// solana/api/transfer.ts
|
|
5528
|
+
async function transfer(params, invoker, env) {
|
|
5529
|
+
const client = createClientFromEnv(env);
|
|
5530
|
+
const ixs = await client.prepareTransferInstructions(params, {
|
|
5531
|
+
invoker: normalizeInvoker(invoker)
|
|
5532
|
+
});
|
|
5533
|
+
return { instructions: ixs };
|
|
5534
|
+
}
|
|
5535
|
+
|
|
5536
|
+
// solana/api/update.ts
|
|
5537
|
+
async function update(params, invoker, env) {
|
|
5538
|
+
const client = createClientFromEnv(env);
|
|
5539
|
+
const ixs = await client.prepareUpdateInstructions(params, {
|
|
5540
|
+
invoker: normalizeInvoker(invoker)
|
|
5541
|
+
});
|
|
5542
|
+
return { instructions: ixs };
|
|
5543
|
+
}
|
|
5544
|
+
async function createBatch(params, invoker, env) {
|
|
5545
|
+
const client = createClientFromEnv(env);
|
|
5546
|
+
const result = await client.buildCreateMultipleTransactionInstructions(params, {
|
|
5547
|
+
sender: normalizeInvoker(invoker),
|
|
5548
|
+
isNative: env.isNative ?? false
|
|
5549
|
+
});
|
|
5550
|
+
return {
|
|
5551
|
+
setupInstructions: result.prepareInstructions,
|
|
5552
|
+
creationBatches: result.instructionsBatch.map((batch, i) => ({
|
|
5553
|
+
instructions: batch.ixs,
|
|
5554
|
+
signers: batch.metadata ? [batch.metadata] : void 0,
|
|
5555
|
+
recipient: batch.recipient,
|
|
5556
|
+
metadataPubKey: new web3_js.PublicKey(result.metadatas[i])
|
|
5557
|
+
}))
|
|
5558
|
+
};
|
|
5559
|
+
}
|
|
5560
|
+
function buildLockParams(params) {
|
|
5561
|
+
if (params.amount.ltn(1)) {
|
|
5562
|
+
throw new Error("Lock amount must be greater than or equal to 1");
|
|
5563
|
+
}
|
|
5564
|
+
return {
|
|
5565
|
+
recipient: params.recipient,
|
|
5566
|
+
tokenId: params.tokenId,
|
|
5567
|
+
amount: params.amount,
|
|
5568
|
+
start: params.unlockDate,
|
|
5569
|
+
cliff: params.unlockDate,
|
|
5570
|
+
period: 1,
|
|
5571
|
+
cliffAmount: params.amount,
|
|
5572
|
+
amountPerPeriod: new BN3__default.default(1),
|
|
5573
|
+
name: params.name,
|
|
5574
|
+
canTopup: false,
|
|
5575
|
+
cancelableBySender: false,
|
|
5576
|
+
cancelableByRecipient: false,
|
|
5577
|
+
transferableBySender: false,
|
|
5578
|
+
transferableByRecipient: params.transferableByRecipient ?? false,
|
|
5579
|
+
automaticWithdrawal: false,
|
|
5580
|
+
withdrawalFrequency: 0,
|
|
5581
|
+
...params.partner !== void 0 && { partner: params.partner },
|
|
5582
|
+
...params.tokenProgramId !== void 0 && { tokenProgramId: params.tokenProgramId }
|
|
5583
|
+
};
|
|
5584
|
+
}
|
|
5585
|
+
async function createLock(params, invoker, env) {
|
|
5586
|
+
return create(buildLockParams(params), invoker, env);
|
|
5587
|
+
}
|
|
5588
|
+
function buildLockBatchParams(params) {
|
|
5589
|
+
return {
|
|
5590
|
+
tokenId: params.tokenId,
|
|
5591
|
+
start: params.unlockDate,
|
|
5592
|
+
cliff: params.unlockDate,
|
|
5593
|
+
period: 1,
|
|
5594
|
+
canTopup: false,
|
|
5595
|
+
cancelableBySender: false,
|
|
5596
|
+
cancelableByRecipient: false,
|
|
5597
|
+
transferableBySender: false,
|
|
5598
|
+
transferableByRecipient: params.transferableByRecipient ?? false,
|
|
5599
|
+
automaticWithdrawal: false,
|
|
5600
|
+
withdrawalFrequency: 0,
|
|
5601
|
+
...params.partner !== void 0 && { partner: params.partner },
|
|
5602
|
+
...params.tokenProgramId !== void 0 && { tokenProgramId: params.tokenProgramId },
|
|
5603
|
+
recipients: params.recipients.map(
|
|
5604
|
+
(r) => ({
|
|
5605
|
+
recipient: r.recipient,
|
|
5606
|
+
amount: r.amount,
|
|
5607
|
+
name: r.name,
|
|
5608
|
+
cliffAmount: r.amount,
|
|
5609
|
+
amountPerPeriod: new BN3__default.default(1)
|
|
5610
|
+
})
|
|
5611
|
+
)
|
|
5612
|
+
};
|
|
5613
|
+
}
|
|
5614
|
+
async function createLockBatch(params, invoker, env) {
|
|
5615
|
+
if (params.recipients.length === 0) {
|
|
5616
|
+
throw new Error("At least one recipient required");
|
|
5617
|
+
}
|
|
5618
|
+
for (const r of params.recipients) {
|
|
5619
|
+
if (r.amount.ltn(1)) {
|
|
5620
|
+
throw new Error("Lock amount must be greater than or equal to 1");
|
|
5621
|
+
}
|
|
5622
|
+
}
|
|
5623
|
+
return createBatch(buildLockBatchParams(params), invoker, env);
|
|
5624
|
+
}
|
|
5625
|
+
function resolveDuration(params) {
|
|
5626
|
+
if (params.endDate !== void 0 && params.duration !== void 0) {
|
|
5627
|
+
throw new Error("Provide either endDate or duration, not both");
|
|
5628
|
+
}
|
|
5629
|
+
if (params.endDate === void 0 && params.duration === void 0) {
|
|
5630
|
+
throw new Error("Must provide either endDate or duration");
|
|
5631
|
+
}
|
|
5632
|
+
const duration = params.endDate !== void 0 ? params.endDate - params.start : params.duration;
|
|
5633
|
+
if (duration <= 0) {
|
|
5634
|
+
throw new Error("Duration must be positive");
|
|
5635
|
+
}
|
|
5636
|
+
return duration;
|
|
5637
|
+
}
|
|
5638
|
+
function computeAmountPerPeriod(amount, cliffAmount, duration, period) {
|
|
5639
|
+
const remaining = amount.sub(cliffAmount);
|
|
5640
|
+
if (remaining.lten(0)) {
|
|
5641
|
+
throw new Error("cliffAmount must be less than total amount");
|
|
5642
|
+
}
|
|
5643
|
+
const numPeriods = Math.floor(duration / period);
|
|
5644
|
+
if (numPeriods <= 0) {
|
|
5645
|
+
throw new Error("Duration must be at least equal to period");
|
|
5646
|
+
}
|
|
5647
|
+
return remaining.addn(numPeriods - 1).divn(numPeriods);
|
|
5648
|
+
}
|
|
5649
|
+
function buildVestingParams(params) {
|
|
5650
|
+
const cliffAmount = params.cliffAmount ?? new BN3__default.default(0);
|
|
5651
|
+
const duration = resolveDuration(params);
|
|
5652
|
+
return {
|
|
5653
|
+
recipient: params.recipient,
|
|
5654
|
+
tokenId: params.tokenId,
|
|
5655
|
+
amount: params.amount,
|
|
5656
|
+
start: params.start,
|
|
5657
|
+
cliff: params.start,
|
|
5658
|
+
period: params.period,
|
|
5659
|
+
name: params.name,
|
|
5660
|
+
cliffAmount,
|
|
5661
|
+
amountPerPeriod: params.amountPerPeriod ?? computeAmountPerPeriod(params.amount, cliffAmount, duration, params.period),
|
|
5662
|
+
canTopup: params.canTopup ?? false,
|
|
5663
|
+
cancelableByRecipient: false,
|
|
5664
|
+
cancelableBySender: params.cancelableBySender ?? false,
|
|
5665
|
+
transferableBySender: params.transferableBySender ?? false,
|
|
5666
|
+
transferableByRecipient: params.transferableByRecipient ?? false,
|
|
5667
|
+
automaticWithdrawal: params.automaticWithdrawal ?? false,
|
|
5668
|
+
withdrawalFrequency: params.withdrawalFrequency ?? (params.automaticWithdrawal ? params.period : 0),
|
|
5669
|
+
...params.partner !== void 0 && { partner: params.partner },
|
|
5670
|
+
...params.tokenProgramId !== void 0 && { tokenProgramId: params.tokenProgramId }
|
|
5671
|
+
};
|
|
5672
|
+
}
|
|
5673
|
+
async function createVesting(params, invoker, env) {
|
|
5674
|
+
if (!params.initialAllocation) {
|
|
5675
|
+
return create(buildVestingParams(params), invoker, env);
|
|
5676
|
+
}
|
|
5677
|
+
if (!params.initialAllocation.amount.gtn(1)) {
|
|
5678
|
+
throw new Error("Initial allocation amount must be greater than 1");
|
|
5679
|
+
}
|
|
5680
|
+
const client = createClientFromEnv(env);
|
|
5681
|
+
const mainData = buildVestingParams(params);
|
|
5682
|
+
const cancelableBySender = params.cancelableBySender ?? false;
|
|
5683
|
+
const allocData = {
|
|
5684
|
+
recipient: params.recipient,
|
|
5685
|
+
tokenId: params.tokenId,
|
|
5686
|
+
amount: params.initialAllocation.amount,
|
|
5687
|
+
start: params.start,
|
|
5688
|
+
cliff: params.start,
|
|
5689
|
+
period: 1,
|
|
5690
|
+
cliffAmount: params.initialAllocation.amount.subn(2),
|
|
5691
|
+
amountPerPeriod: new BN3__default.default(2),
|
|
5692
|
+
name: params.name,
|
|
5693
|
+
canTopup: false,
|
|
5694
|
+
cancelableBySender,
|
|
5695
|
+
cancelableByRecipient: false,
|
|
5696
|
+
transferableBySender: false,
|
|
5697
|
+
transferableByRecipient: false,
|
|
5698
|
+
automaticWithdrawal: false,
|
|
5699
|
+
withdrawalFrequency: 0,
|
|
5700
|
+
...params.partner !== void 0 && { partner: params.partner },
|
|
5701
|
+
...params.tokenProgramId !== void 0 && { tokenProgramId: params.tokenProgramId }
|
|
5702
|
+
};
|
|
5703
|
+
const normalizedInvoker = normalizeInvoker(invoker);
|
|
5704
|
+
const [mainResult, allocResult] = await Promise.all([
|
|
5705
|
+
client.buildCreateTransactionInstructions(mainData, {
|
|
5706
|
+
sender: normalizedInvoker,
|
|
5707
|
+
isNative: env.isNative ?? false
|
|
5708
|
+
}),
|
|
5709
|
+
client.buildCreateTransactionInstructions(allocData, {
|
|
5710
|
+
sender: normalizedInvoker,
|
|
5711
|
+
isNative: env.isNative ?? false
|
|
5712
|
+
})
|
|
5713
|
+
]);
|
|
5714
|
+
return {
|
|
5715
|
+
setupInstructions: [...mainResult.ixs.slice(0, -1), ...allocResult.ixs.slice(0, -1)],
|
|
5716
|
+
creationBatches: [
|
|
5717
|
+
{
|
|
5718
|
+
instructions: [mainResult.ixs[mainResult.ixs.length - 1]],
|
|
5719
|
+
signers: mainResult.metadata ? [mainResult.metadata] : void 0,
|
|
5720
|
+
recipient: params.recipient,
|
|
5721
|
+
metadataPubKey: new web3_js.PublicKey(mainResult.metadataId)
|
|
5722
|
+
},
|
|
5723
|
+
{
|
|
5724
|
+
instructions: [allocResult.ixs[allocResult.ixs.length - 1]],
|
|
5725
|
+
signers: allocResult.metadata ? [allocResult.metadata] : void 0,
|
|
5726
|
+
recipient: params.recipient,
|
|
5727
|
+
metadataPubKey: new web3_js.PublicKey(allocResult.metadataId)
|
|
5728
|
+
}
|
|
5729
|
+
]
|
|
5730
|
+
};
|
|
5731
|
+
}
|
|
5732
|
+
function buildVestingBatchParams(params) {
|
|
5733
|
+
const duration = resolveDuration(params);
|
|
5734
|
+
return {
|
|
5735
|
+
tokenId: params.tokenId,
|
|
5736
|
+
start: params.start,
|
|
5737
|
+
cliff: params.start,
|
|
5738
|
+
period: params.period,
|
|
5739
|
+
canTopup: false,
|
|
5740
|
+
cancelableByRecipient: false,
|
|
5741
|
+
cancelableBySender: params.cancelableBySender ?? false,
|
|
5742
|
+
transferableBySender: params.transferableBySender ?? false,
|
|
5743
|
+
transferableByRecipient: params.transferableByRecipient ?? false,
|
|
5744
|
+
automaticWithdrawal: params.automaticWithdrawal ?? false,
|
|
5745
|
+
withdrawalFrequency: params.withdrawalFrequency ?? (params.automaticWithdrawal ? params.period : 0),
|
|
5746
|
+
...params.partner !== void 0 && { partner: params.partner },
|
|
5747
|
+
...params.tokenProgramId !== void 0 && { tokenProgramId: params.tokenProgramId },
|
|
5748
|
+
recipients: params.recipients.map(
|
|
5749
|
+
(r) => ({
|
|
5750
|
+
recipient: r.recipient,
|
|
5751
|
+
amount: r.amount,
|
|
5752
|
+
name: r.name,
|
|
5753
|
+
cliffAmount: r.cliffAmount ?? new BN3__default.default(0),
|
|
5754
|
+
amountPerPeriod: r.amountPerPeriod ?? computeAmountPerPeriod(r.amount, r.cliffAmount ?? new BN3__default.default(0), duration, params.period)
|
|
5755
|
+
})
|
|
5756
|
+
)
|
|
5757
|
+
};
|
|
5758
|
+
}
|
|
5759
|
+
async function createVestingBatch(params, invoker, env) {
|
|
5760
|
+
if (params.recipients.length === 0) {
|
|
5761
|
+
throw new Error("At least one recipient required");
|
|
5762
|
+
}
|
|
5763
|
+
for (const r of params.recipients) {
|
|
5764
|
+
if (r.amount.lte(new BN3__default.default(0))) {
|
|
5765
|
+
throw new Error("Amount must be greater than zero");
|
|
5766
|
+
}
|
|
5767
|
+
}
|
|
5768
|
+
return createBatch(buildVestingBatchParams(params), invoker, env);
|
|
5769
|
+
}
|
|
5770
|
+
async function buildTransaction(instructions, options, env) {
|
|
5771
|
+
const connection = resolveConnection(env);
|
|
5772
|
+
const computeBudgetIxs = common.prepareBaseInstructions(connection, {
|
|
5773
|
+
computePrice: typeof options.computePrice === "function" ? void 0 : options.computePrice,
|
|
5774
|
+
computeLimit: typeof options.computeLimit !== "number" ? void 0 : options.computeLimit
|
|
5775
|
+
});
|
|
5776
|
+
const allIxs = [...computeBudgetIxs, ...instructions];
|
|
5777
|
+
const { tx, hash, context } = await common.prepareTransaction(connection, allIxs, options.feePayer, env.commitment);
|
|
5778
|
+
return {
|
|
5779
|
+
transaction: tx,
|
|
5780
|
+
blockhashWithExpiryBlockHeight: hash,
|
|
5781
|
+
context
|
|
5782
|
+
};
|
|
5783
|
+
}
|
|
5784
|
+
|
|
5785
|
+
// solana/api/sign.ts
|
|
5786
|
+
function isKeypair(signer) {
|
|
5787
|
+
return "secretKey" in signer;
|
|
5788
|
+
}
|
|
5789
|
+
function isWalletAdapter(signer) {
|
|
5790
|
+
return "signTransaction" in signer;
|
|
5791
|
+
}
|
|
5792
|
+
async function sign(transaction, signers) {
|
|
5793
|
+
for (const signer of signers) {
|
|
5794
|
+
if (isKeypair(signer)) {
|
|
5795
|
+
transaction.sign([signer]);
|
|
5796
|
+
} else if (isWalletAdapter(signer)) {
|
|
5797
|
+
await signer.signTransaction(transaction);
|
|
5798
|
+
}
|
|
5799
|
+
}
|
|
5800
|
+
return transaction;
|
|
5801
|
+
}
|
|
5802
|
+
async function execute(builtTx, env) {
|
|
5803
|
+
const connection = resolveConnection(env);
|
|
5804
|
+
return common.executeTransaction(
|
|
5805
|
+
connection,
|
|
5806
|
+
builtTx.transaction,
|
|
5807
|
+
{
|
|
5808
|
+
hash: builtTx.blockhashWithExpiryBlockHeight,
|
|
5809
|
+
context: builtTx.context,
|
|
5810
|
+
commitment: env.commitment
|
|
5811
|
+
},
|
|
5812
|
+
{
|
|
5813
|
+
sendRate: env.sendRate,
|
|
5814
|
+
sendThrottler: env.throttler,
|
|
5815
|
+
skipSimulation: env.skipPreflight
|
|
5816
|
+
}
|
|
5817
|
+
);
|
|
5818
|
+
}
|
|
5819
|
+
async function executeBatch(builtTransactions, env) {
|
|
5820
|
+
if (builtTransactions.length === 0) {
|
|
5821
|
+
return { signatures: [], errors: [] };
|
|
5822
|
+
}
|
|
5823
|
+
const first = builtTransactions[0];
|
|
5824
|
+
const firstBlockhash = first.blockhashWithExpiryBlockHeight.blockhash;
|
|
5825
|
+
for (const btx of builtTransactions) {
|
|
5826
|
+
if (btx.blockhashWithExpiryBlockHeight.blockhash !== firstBlockhash) {
|
|
5827
|
+
throw new Error("All transactions in executeBatch must share the same blockhash");
|
|
5828
|
+
}
|
|
5829
|
+
}
|
|
5830
|
+
const connection = resolveConnection(env);
|
|
5831
|
+
const results = await common.executeMultipleTransactions(
|
|
5832
|
+
connection,
|
|
5833
|
+
builtTransactions.map((btx) => btx.transaction),
|
|
5834
|
+
{
|
|
5835
|
+
hash: first.blockhashWithExpiryBlockHeight,
|
|
5836
|
+
context: first.context,
|
|
5837
|
+
commitment: env.commitment
|
|
5838
|
+
},
|
|
5839
|
+
{
|
|
5840
|
+
sendRate: env.sendRate,
|
|
5841
|
+
sendThrottler: env.throttler,
|
|
5842
|
+
skipSimulation: env.skipPreflight
|
|
5843
|
+
}
|
|
5844
|
+
);
|
|
5845
|
+
const signatures = [];
|
|
5846
|
+
const errors = [];
|
|
5847
|
+
for (const result of results) {
|
|
5848
|
+
if (result.status === "fulfilled") {
|
|
5849
|
+
signatures.push(result.value);
|
|
5850
|
+
} else {
|
|
5851
|
+
errors.push(result.reason instanceof Error ? result.reason : new Error(String(result.reason)));
|
|
5852
|
+
}
|
|
5853
|
+
}
|
|
5854
|
+
return { signatures, errors };
|
|
5855
|
+
}
|
|
5856
|
+
async function executeBatchSequential(builtTransactions, env) {
|
|
5857
|
+
const connection = resolveConnection(env);
|
|
5858
|
+
const signatures = [];
|
|
5859
|
+
const errors = [];
|
|
5860
|
+
for (const btx of builtTransactions) {
|
|
5861
|
+
try {
|
|
5862
|
+
const sig = await common.executeTransaction(
|
|
5863
|
+
connection,
|
|
5864
|
+
btx.transaction,
|
|
5865
|
+
{
|
|
5866
|
+
hash: btx.blockhashWithExpiryBlockHeight,
|
|
5867
|
+
context: btx.context,
|
|
5868
|
+
commitment: env.commitment
|
|
5869
|
+
},
|
|
5870
|
+
{
|
|
5871
|
+
sendRate: env.sendRate,
|
|
5872
|
+
sendThrottler: env.throttler,
|
|
5873
|
+
skipSimulation: env.skipPreflight
|
|
5874
|
+
}
|
|
5875
|
+
);
|
|
5876
|
+
signatures.push(sig);
|
|
5877
|
+
} catch (err) {
|
|
5878
|
+
errors.push(err instanceof Error ? err : new Error(String(err)));
|
|
5879
|
+
}
|
|
5880
|
+
}
|
|
5881
|
+
return { signatures, errors };
|
|
5882
|
+
}
|
|
5442
5883
|
|
|
5443
5884
|
Object.defineProperty(exports, "ContractError", {
|
|
5444
5885
|
enumerable: true,
|
|
@@ -5500,15 +5941,29 @@ exports.TX_FINALITY_CONFIRMED = TX_FINALITY_CONFIRMED;
|
|
|
5500
5941
|
exports.WITHDRAWOR = WITHDRAWOR;
|
|
5501
5942
|
exports.WITHDRAWOR_PUBLIC_KEY = WITHDRAWOR_PUBLIC_KEY;
|
|
5502
5943
|
exports.WITHDRAW_AVAILABLE_AMOUNT = WITHDRAW_AVAILABLE_AMOUNT;
|
|
5944
|
+
exports.buildLockBatchParams = buildLockBatchParams;
|
|
5945
|
+
exports.buildLockParams = buildLockParams;
|
|
5503
5946
|
exports.buildStreamType = buildStreamType;
|
|
5947
|
+
exports.buildTransaction = buildTransaction;
|
|
5948
|
+
exports.buildVestingBatchParams = buildVestingBatchParams;
|
|
5949
|
+
exports.buildVestingParams = buildVestingParams;
|
|
5504
5950
|
exports.calculateTotalAmountToDeposit = calculateTotalAmountToDeposit;
|
|
5505
5951
|
exports.calculateUnlockedAmount = calculateUnlockedAmount;
|
|
5952
|
+
exports.cancel = cancel;
|
|
5506
5953
|
exports.cancelStreamInstruction = cancelStreamInstruction;
|
|
5954
|
+
exports.computeAmountPerPeriod = computeAmountPerPeriod;
|
|
5955
|
+
exports.create = create;
|
|
5956
|
+
exports.createBatch = createBatch;
|
|
5507
5957
|
exports.createClient = createClient;
|
|
5958
|
+
exports.createClientFromEnv = createClientFromEnv;
|
|
5959
|
+
exports.createLock = createLock;
|
|
5960
|
+
exports.createLockBatch = createLockBatch;
|
|
5508
5961
|
exports.createStreamInstruction = createStreamInstruction;
|
|
5509
5962
|
exports.createStreamV2Instruction = createStreamV2Instruction;
|
|
5510
5963
|
exports.createUncheckedStreamInstruction = createUncheckedStreamInstruction;
|
|
5511
5964
|
exports.createUncheckedStreamV2Instruction = createUncheckedStreamV2Instruction;
|
|
5965
|
+
exports.createVesting = createVesting;
|
|
5966
|
+
exports.createVestingBatch = createVestingBatch;
|
|
5512
5967
|
exports.decodeEndTime = decodeEndTime;
|
|
5513
5968
|
exports.decodeStream = decodeStream;
|
|
5514
5969
|
exports.deriveContractPDA = deriveContractPDA;
|
|
@@ -5516,6 +5971,9 @@ exports.deriveEscrowPDA = deriveEscrowPDA;
|
|
|
5516
5971
|
exports.deriveRepopulatedMetadataPDA = deriveRepopulatedMetadataPDA;
|
|
5517
5972
|
exports.deriveStreamMetadataPDA = deriveStreamMetadataPDA;
|
|
5518
5973
|
exports.deriveTestOraclePDA = deriveTestOraclePDA;
|
|
5974
|
+
exports.execute = execute;
|
|
5975
|
+
exports.executeBatch = executeBatch;
|
|
5976
|
+
exports.executeBatchSequential = executeBatchSequential;
|
|
5519
5977
|
exports.extractSolanaErrorCode = extractSolanaErrorCode;
|
|
5520
5978
|
exports.getMetadataKey = getMetadataKey;
|
|
5521
5979
|
exports.handleContractError = handleContractError;
|
|
@@ -5526,13 +5984,20 @@ exports.isDynamicLock = isDynamicLock;
|
|
|
5526
5984
|
exports.isTokenLock = isTokenLock;
|
|
5527
5985
|
exports.isVesting = isVesting;
|
|
5528
5986
|
exports.requestCancelStreamInstruction = requestCancelStreamInstruction;
|
|
5987
|
+
exports.resolveConnection = resolveConnection;
|
|
5988
|
+
exports.resolveDuration = resolveDuration;
|
|
5529
5989
|
exports.sendAndConfirmStreamRawTransaction = sendAndConfirmStreamRawTransaction;
|
|
5990
|
+
exports.sign = sign;
|
|
5530
5991
|
exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
|
|
5531
5992
|
exports.timelockIDL = timelockIDL_default;
|
|
5993
|
+
exports.topup = topup;
|
|
5532
5994
|
exports.topupStreamInstruction = topupStreamInstruction;
|
|
5995
|
+
exports.transfer = transfer;
|
|
5533
5996
|
exports.transferStreamInstruction = transferStreamInstruction;
|
|
5534
5997
|
exports.transformContract = transformContract;
|
|
5998
|
+
exports.update = update;
|
|
5535
5999
|
exports.updateStreamInstruction = updateStreamInstruction;
|
|
6000
|
+
exports.withdraw = withdraw;
|
|
5536
6001
|
exports.withdrawCancelRequestInstruction = withdrawCancelRequestInstruction;
|
|
5537
6002
|
exports.withdrawStreamInstruction = withdrawStreamInstruction;
|
|
5538
6003
|
//# sourceMappingURL=index.cjs.map
|