@streamflow/stream 11.1.0-alpha.p335.b571df3 → 11.2.0-alpha.p342.ccd18cf
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.cjs +517 -115
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/solana/index.cjs +517 -115
- package/dist/cjs/solana/index.cjs.map +1 -1
- package/dist/cjs/solana/index.d.cts +243 -6
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +514 -118
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solana/descriptor/idl/streamflow.json +1440 -0
- package/dist/esm/solana/index.d.ts +243 -6
- package/dist/esm/solana/index.js +514 -118
- package/dist/esm/solana/index.js.map +1 -1
- package/package.json +5 -4
package/dist/esm/solana/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import BN3 from 'bn.js';
|
|
|
2
2
|
import bs58 from 'bs58';
|
|
3
3
|
import { Buffer } from 'buffer';
|
|
4
4
|
import { NATIVE_MINT, ASSOCIATED_TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
5
|
-
import { PublicKey, TransactionInstruction, Connection, Keypair,
|
|
6
|
-
import { ICluster, getNumberFromBN, isSignerKeypair, isSignerWallet, executeTransaction, ContractError, buildSendThrottler, assertHasPublicKey, prepareWrappedAccount, prepareTransaction, signAndExecuteTransaction, invariant, getMintAndProgram, prepareBaseInstructions, getBN, ata, createVersionedTransaction, executeMultipleTransactions, getMultipleAccountsInfoBatched, getProgramAccounts, checkOrCreateAtaBatch } from '@streamflow/common';
|
|
5
|
+
import { PublicKey, TransactionInstruction, Connection, Keypair, SystemProgram, SYSVAR_RENT_PUBKEY, TransactionMessage, VersionedTransaction } from '@solana/web3.js';
|
|
6
|
+
import { ICluster, getNumberFromBN, isSignerKeypair, isSignerWallet, executeTransaction, ContractError, buildSendThrottler, assertHasPublicKey, prepareWrappedAccount, prepareTransaction, signAndExecuteTransaction, invariant, getMintAndProgram, prepareBaseInstructions, getBN, ata, createVersionedTransaction, executeMultipleTransactions, getMultipleAccountsInfoBatched, getProgramAccounts, isDev, checkOrCreateAtaBatch, pk } from '@streamflow/common';
|
|
7
7
|
export { ContractError, ICluster, getBN, getNumberFromBN } from '@streamflow/common';
|
|
8
8
|
import * as borsh from 'borsh';
|
|
9
9
|
import { Program } from '@coral-xyz/anchor';
|
|
@@ -154,12 +154,16 @@ var Contract = class {
|
|
|
154
154
|
this.canTopup = stream.canTopup;
|
|
155
155
|
this.name = stream.name;
|
|
156
156
|
this.withdrawalFrequency = stream.withdrawFrequency.toNumber();
|
|
157
|
+
this.isPda = stream.isPda;
|
|
158
|
+
this.nonce = stream.nonce;
|
|
157
159
|
this.closed = stream.closed;
|
|
158
160
|
this.currentPauseStart = stream.currentPauseStart.toNumber();
|
|
159
161
|
this.pauseCumulative = stream.pauseCumulative;
|
|
160
162
|
this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
|
|
161
163
|
this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
|
|
162
164
|
this.oldMetadata = stream.oldMetadata;
|
|
165
|
+
this.payer = stream.payer.toBase58();
|
|
166
|
+
this.bump = stream.bump;
|
|
163
167
|
this.type = buildStreamType(this);
|
|
164
168
|
this.isAligned = false;
|
|
165
169
|
}
|
|
@@ -214,7 +218,7 @@ var STREAM_STRUCT_OFFSETS = {
|
|
|
214
218
|
sender: STREAM_STRUCT_OFFSET_SENDER,
|
|
215
219
|
closed: STREAM_STRUCT_OFFSET_CLOSED
|
|
216
220
|
};
|
|
217
|
-
var CREATE_PARAMS_PADDING =
|
|
221
|
+
var CREATE_PARAMS_PADDING = 121;
|
|
218
222
|
var PROGRAM_ID = {
|
|
219
223
|
[ICluster.Devnet]: "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
|
|
220
224
|
[ICluster.Mainnet]: "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m",
|
|
@@ -245,6 +249,7 @@ var TEST_ORACLE_DISCRIMINATOR = [198, 49, 63, 134, 232, 251, 168, 28];
|
|
|
245
249
|
var CONTRACT_SEED = Buffer.from("contract", "utf-8");
|
|
246
250
|
var ESCROW_SEED = Buffer.from("strm", "utf-8");
|
|
247
251
|
var TEST_ORACLE_SEED = Buffer.from("test-oracle", "utf-8");
|
|
252
|
+
var METADATA_SEED = Buffer.from("strm-met", "utf-8");
|
|
248
253
|
var REPOPULATED_METADATA_SEED = Buffer.from("strm-rep", "utf-8");
|
|
249
254
|
var STREAMFLOW_TREASURY_PUBLIC_KEY = new PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
|
|
250
255
|
var WITHDRAWOR = "wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u";
|
|
@@ -348,7 +353,9 @@ var streamLayout = BufferLayout.struct([
|
|
|
348
353
|
BufferLayout.blob(4, "ghost"),
|
|
349
354
|
BufferLayout.u8("pausable"),
|
|
350
355
|
BufferLayout.u8("can_update_rate"),
|
|
351
|
-
BufferLayout.blob(4, "
|
|
356
|
+
BufferLayout.blob(4, "ghost2"),
|
|
357
|
+
BufferLayout.u8("is_pda"),
|
|
358
|
+
BufferLayout.u32("nonce"),
|
|
352
359
|
BufferLayout.seq(BufferLayout.u8(), CREATE_PARAMS_PADDING, "create_params_padding"),
|
|
353
360
|
BufferLayout.u8("closed"),
|
|
354
361
|
BufferLayout.blob(8, "current_pause_start"),
|
|
@@ -359,7 +366,9 @@ var streamLayout = BufferLayout.struct([
|
|
|
359
366
|
BufferLayout.u8("creation_fee_claimed"),
|
|
360
367
|
BufferLayout.u32("auto_claim_fee"),
|
|
361
368
|
BufferLayout.u8("auto_claim_fee_claimed"),
|
|
362
|
-
BufferLayout.blob(32, "old_metadata")
|
|
369
|
+
BufferLayout.blob(32, "old_metadata"),
|
|
370
|
+
BufferLayout.blob(32, "payer"),
|
|
371
|
+
BufferLayout.u8("bump")
|
|
363
372
|
]);
|
|
364
373
|
BufferLayout.struct([
|
|
365
374
|
BufferLayout.blob(32, "pubkey"),
|
|
@@ -388,6 +397,25 @@ var createStreamLayout = BufferLayout.struct([
|
|
|
388
397
|
BufferLayout.u8("_can_update_rate_discriminator"),
|
|
389
398
|
BufferLayout.u8("can_update_rate")
|
|
390
399
|
]);
|
|
400
|
+
var createStreamV2Layout = BufferLayout.struct([
|
|
401
|
+
BufferLayout.blob(8, "start_time"),
|
|
402
|
+
BufferLayout.blob(8, "net_amount_deposited"),
|
|
403
|
+
BufferLayout.blob(8, "period"),
|
|
404
|
+
BufferLayout.blob(8, "amount_per_period"),
|
|
405
|
+
BufferLayout.blob(8, "cliff"),
|
|
406
|
+
BufferLayout.blob(8, "cliff_amount"),
|
|
407
|
+
BufferLayout.u8("cancelable_by_sender"),
|
|
408
|
+
BufferLayout.u8("cancelable_by_recipient"),
|
|
409
|
+
BufferLayout.u8("automatic_withdrawal"),
|
|
410
|
+
BufferLayout.u8("transferable_by_sender"),
|
|
411
|
+
BufferLayout.u8("transferable_by_recipient"),
|
|
412
|
+
BufferLayout.u8("can_topup"),
|
|
413
|
+
BufferLayout.blob(64, "stream_name"),
|
|
414
|
+
BufferLayout.blob(8, "withdraw_frequency"),
|
|
415
|
+
BufferLayout.u8("pausable"),
|
|
416
|
+
BufferLayout.u8("can_update_rate"),
|
|
417
|
+
BufferLayout.blob(4, "nonce")
|
|
418
|
+
]);
|
|
391
419
|
var createUncheckedStreamLayout = BufferLayout.struct([
|
|
392
420
|
BufferLayout.blob(8, "start_time"),
|
|
393
421
|
BufferLayout.blob(8, "net_amount_deposited"),
|
|
@@ -408,6 +436,27 @@ var createUncheckedStreamLayout = BufferLayout.struct([
|
|
|
408
436
|
BufferLayout.u8("pausable"),
|
|
409
437
|
BufferLayout.u8("can_update_rate")
|
|
410
438
|
]);
|
|
439
|
+
var createUncheckedStreamV2Layout = BufferLayout.struct([
|
|
440
|
+
BufferLayout.blob(8, "start_time"),
|
|
441
|
+
BufferLayout.blob(8, "net_amount_deposited"),
|
|
442
|
+
BufferLayout.blob(8, "period"),
|
|
443
|
+
BufferLayout.blob(8, "amount_per_period"),
|
|
444
|
+
BufferLayout.blob(8, "cliff"),
|
|
445
|
+
BufferLayout.blob(8, "cliff_amount"),
|
|
446
|
+
BufferLayout.u8("cancelable_by_sender"),
|
|
447
|
+
BufferLayout.u8("cancelable_by_recipient"),
|
|
448
|
+
BufferLayout.u8("automatic_withdrawal"),
|
|
449
|
+
BufferLayout.u8("transferable_by_sender"),
|
|
450
|
+
BufferLayout.u8("transferable_by_recipient"),
|
|
451
|
+
BufferLayout.u8("can_topup"),
|
|
452
|
+
BufferLayout.blob(64, "stream_name"),
|
|
453
|
+
BufferLayout.blob(8, "withdraw_frequency"),
|
|
454
|
+
BufferLayout.blob(32, "recipient"),
|
|
455
|
+
BufferLayout.blob(32, "partner"),
|
|
456
|
+
BufferLayout.u8("pausable"),
|
|
457
|
+
BufferLayout.u8("can_update_rate"),
|
|
458
|
+
BufferLayout.blob(4, "nonce")
|
|
459
|
+
]);
|
|
411
460
|
var withdrawStreamLayout = BufferLayout.struct([
|
|
412
461
|
BufferLayout.blob(8, "amount")
|
|
413
462
|
]);
|
|
@@ -525,12 +574,16 @@ var decodeStream = (buf) => {
|
|
|
525
574
|
canTopup: Boolean(raw.can_topup),
|
|
526
575
|
name: decoder.decode(raw.stream_name),
|
|
527
576
|
withdrawFrequency: new BN3(raw.withdraw_frequency, LE),
|
|
577
|
+
isPda: Boolean(raw.is_pda),
|
|
578
|
+
nonce: raw.nonce,
|
|
528
579
|
closed: Boolean(raw.closed),
|
|
529
580
|
currentPauseStart: new BN3(raw.current_pause_start, LE),
|
|
530
581
|
pauseCumulative: new BN3(raw.pause_cumulative, LE),
|
|
531
582
|
lastRateChangeTime: new BN3(raw.last_rate_change_time, LE),
|
|
532
583
|
fundsUnlockedAtLastRateChange: new BN3(raw.funds_unlocked_at_last_rate_change, LE),
|
|
533
|
-
oldMetadata: new PublicKey(raw.old_metadata)
|
|
584
|
+
oldMetadata: new PublicKey(raw.old_metadata),
|
|
585
|
+
payer: new PublicKey(raw.payer),
|
|
586
|
+
bump: raw.bump
|
|
534
587
|
};
|
|
535
588
|
};
|
|
536
589
|
async function signAllTransactionWithRecipients(sender, items) {
|
|
@@ -721,6 +774,133 @@ var createUncheckedStreamInstruction = async (data, programId, accounts) => {
|
|
|
721
774
|
data: bufferData
|
|
722
775
|
});
|
|
723
776
|
};
|
|
777
|
+
var createStreamV2Instruction = async (data, programId, accounts) => {
|
|
778
|
+
const keys = [
|
|
779
|
+
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
780
|
+
{ pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
|
|
781
|
+
{ pubkey: accounts.recipient, isSigner: false, isWritable: true },
|
|
782
|
+
{ pubkey: accounts.metadata, isSigner: false, isWritable: true },
|
|
783
|
+
{ pubkey: accounts.escrowTokens, isSigner: false, isWritable: true },
|
|
784
|
+
{ pubkey: accounts.recipientTokens, isSigner: false, isWritable: true },
|
|
785
|
+
{
|
|
786
|
+
pubkey: accounts.streamflowTreasury,
|
|
787
|
+
isSigner: false,
|
|
788
|
+
isWritable: true
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
pubkey: accounts.streamflowTreasuryTokens,
|
|
792
|
+
isSigner: false,
|
|
793
|
+
isWritable: true
|
|
794
|
+
},
|
|
795
|
+
{ pubkey: accounts.withdrawor, isSigner: false, isWritable: true },
|
|
796
|
+
{ pubkey: accounts.partner, isSigner: false, isWritable: true },
|
|
797
|
+
{ pubkey: accounts.partnerTokens, isSigner: false, isWritable: true },
|
|
798
|
+
{ pubkey: accounts.mint, isSigner: false, isWritable: false },
|
|
799
|
+
{ pubkey: accounts.feeOracle, isSigner: false, isWritable: false },
|
|
800
|
+
{ pubkey: accounts.rent, isSigner: false, isWritable: false },
|
|
801
|
+
{ pubkey: accounts.timelockProgram, isSigner: false, isWritable: false },
|
|
802
|
+
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
|
|
803
|
+
{
|
|
804
|
+
pubkey: accounts.associatedTokenProgram,
|
|
805
|
+
isSigner: false,
|
|
806
|
+
isWritable: false
|
|
807
|
+
},
|
|
808
|
+
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
|
|
809
|
+
];
|
|
810
|
+
let bufferData = Buffer.alloc(createStreamV2Layout.span);
|
|
811
|
+
const encodedUIntArray = new TextEncoder().encode(data.name);
|
|
812
|
+
const streamNameBuffer = Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
813
|
+
const nonceBuffer = Buffer.alloc(4);
|
|
814
|
+
nonceBuffer.writeUInt32LE(data.nonce);
|
|
815
|
+
const decodedData = {
|
|
816
|
+
start_time: data.start.toArrayLike(Buffer, "le", 8),
|
|
817
|
+
net_amount_deposited: data.depositedAmount.toArrayLike(Buffer, "le", 8),
|
|
818
|
+
period: data.period.toArrayLike(Buffer, "le", 8),
|
|
819
|
+
amount_per_period: data.amountPerPeriod.toArrayLike(Buffer, "le", 8),
|
|
820
|
+
cliff: data.cliff.toArrayLike(Buffer, "le", 8),
|
|
821
|
+
cliff_amount: data.cliffAmount.toArrayLike(Buffer, "le", 8),
|
|
822
|
+
cancelable_by_sender: Number(data.cancelableBySender),
|
|
823
|
+
cancelable_by_recipient: Number(data.cancelableByRecipient),
|
|
824
|
+
automatic_withdrawal: Number(data.automaticWithdrawal),
|
|
825
|
+
transferable_by_sender: Number(data.transferableBySender),
|
|
826
|
+
transferable_by_recipient: Number(data.transferableByRecipient),
|
|
827
|
+
can_topup: Number(data.canTopup),
|
|
828
|
+
stream_name: streamNameBuffer,
|
|
829
|
+
withdraw_frequency: data.withdrawFrequency.toArrayLike(Buffer, "le", 8),
|
|
830
|
+
pausable: Number(data.canPause),
|
|
831
|
+
can_update_rate: Number(data.canUpdateRate),
|
|
832
|
+
nonce: nonceBuffer
|
|
833
|
+
};
|
|
834
|
+
const encodeLength = createStreamV2Layout.encode(decodedData, bufferData);
|
|
835
|
+
bufferData = bufferData.slice(0, encodeLength);
|
|
836
|
+
bufferData = Buffer.concat([
|
|
837
|
+
Buffer.from(await sha256.digest("global:create_v2")).slice(0, 8),
|
|
838
|
+
bufferData,
|
|
839
|
+
Buffer.alloc(10)
|
|
840
|
+
]);
|
|
841
|
+
return new TransactionInstruction({
|
|
842
|
+
keys,
|
|
843
|
+
programId,
|
|
844
|
+
data: bufferData
|
|
845
|
+
});
|
|
846
|
+
};
|
|
847
|
+
var createUncheckedStreamV2Instruction = async (data, programId, accounts) => {
|
|
848
|
+
const keys = [
|
|
849
|
+
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
850
|
+
{ pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
|
|
851
|
+
{ pubkey: accounts.metadata, isSigner: false, isWritable: true },
|
|
852
|
+
{ pubkey: accounts.escrowTokens, isSigner: false, isWritable: true },
|
|
853
|
+
{ pubkey: accounts.withdrawor, isSigner: false, isWritable: true },
|
|
854
|
+
{ pubkey: accounts.mint, isSigner: false, isWritable: false },
|
|
855
|
+
{ pubkey: accounts.feeOracle, isSigner: false, isWritable: false },
|
|
856
|
+
{ pubkey: accounts.rent, isSigner: false, isWritable: false },
|
|
857
|
+
{ pubkey: accounts.timelockProgram, isSigner: false, isWritable: false },
|
|
858
|
+
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
|
|
859
|
+
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
|
|
860
|
+
];
|
|
861
|
+
if (accounts.payer) {
|
|
862
|
+
keys.unshift({
|
|
863
|
+
pubkey: accounts.payer,
|
|
864
|
+
isSigner: true,
|
|
865
|
+
isWritable: true
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
let bufferData = Buffer.alloc(createUncheckedStreamV2Layout.span);
|
|
869
|
+
const encodedUIntArray = new TextEncoder().encode(data.name);
|
|
870
|
+
const streamNameBuffer = Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
871
|
+
const nonceBuffer = Buffer.alloc(4);
|
|
872
|
+
nonceBuffer.writeUInt32LE(data.nonce);
|
|
873
|
+
const decodedData = {
|
|
874
|
+
start_time: data.start.toArrayLike(Buffer, "le", 8),
|
|
875
|
+
net_amount_deposited: data.depositedAmount.toArrayLike(Buffer, "le", 8),
|
|
876
|
+
period: data.period.toArrayLike(Buffer, "le", 8),
|
|
877
|
+
amount_per_period: data.amountPerPeriod.toArrayLike(Buffer, "le", 8),
|
|
878
|
+
cliff: data.cliff.toArrayLike(Buffer, "le", 8),
|
|
879
|
+
cliff_amount: data.cliffAmount.toArrayLike(Buffer, "le", 8),
|
|
880
|
+
cancelable_by_sender: Number(data.cancelableBySender),
|
|
881
|
+
cancelable_by_recipient: Number(data.cancelableByRecipient),
|
|
882
|
+
automatic_withdrawal: Number(data.automaticWithdrawal),
|
|
883
|
+
transferable_by_sender: Number(data.transferableBySender),
|
|
884
|
+
transferable_by_recipient: Number(data.transferableByRecipient),
|
|
885
|
+
can_topup: Number(data.canTopup),
|
|
886
|
+
stream_name: streamNameBuffer,
|
|
887
|
+
withdraw_frequency: data.withdrawFrequency.toArrayLike(Buffer, "le", 8),
|
|
888
|
+
recipient: data.recipient.toBuffer(),
|
|
889
|
+
partner: data.partner.toBuffer(),
|
|
890
|
+
pausable: Number(data.canPause),
|
|
891
|
+
can_update_rate: Number(data.canUpdateRate),
|
|
892
|
+
nonce: nonceBuffer
|
|
893
|
+
};
|
|
894
|
+
const encodeLength = createUncheckedStreamV2Layout.encode(decodedData, bufferData);
|
|
895
|
+
bufferData = bufferData.slice(0, encodeLength);
|
|
896
|
+
const digest = accounts.payer ? await sha256.digest("global:create_unchecked_with_payer_v2") : await sha256.digest("global:create_unchecked_v2");
|
|
897
|
+
bufferData = Buffer.concat([Buffer.from(digest).slice(0, 8), bufferData, Buffer.alloc(10)]);
|
|
898
|
+
return new TransactionInstruction({
|
|
899
|
+
keys,
|
|
900
|
+
programId,
|
|
901
|
+
data: bufferData
|
|
902
|
+
});
|
|
903
|
+
};
|
|
724
904
|
var withdrawStreamInstruction = async (amount, programId, {
|
|
725
905
|
authority,
|
|
726
906
|
recipient,
|
|
@@ -2513,10 +2693,163 @@ var deriveEscrowPDA = (programId, streamMetadata) => {
|
|
|
2513
2693
|
var deriveTestOraclePDA = (programId, mint, creator) => {
|
|
2514
2694
|
return PublicKey.findProgramAddressSync([TEST_ORACLE_SEED, mint.toBuffer(), creator.toBuffer()], programId)[0];
|
|
2515
2695
|
};
|
|
2696
|
+
var deriveStreamMetadataPDA = (programId, mint, sender, nonce) => {
|
|
2697
|
+
const nonceBuffer = Buffer.alloc(4);
|
|
2698
|
+
nonceBuffer.writeUInt32BE(nonce);
|
|
2699
|
+
return PublicKey.findProgramAddressSync(
|
|
2700
|
+
[METADATA_SEED, mint.toBuffer(), sender.toBuffer(), nonceBuffer],
|
|
2701
|
+
programId
|
|
2702
|
+
);
|
|
2703
|
+
};
|
|
2516
2704
|
var deriveRepopulatedMetadataPDA = (programId, streamMetadata) => {
|
|
2517
2705
|
return PublicKey.findProgramAddressSync([REPOPULATED_METADATA_SEED, streamMetadata.toBuffer()], programId)[0];
|
|
2518
2706
|
};
|
|
2519
2707
|
|
|
2708
|
+
// solana/api-public/client.ts
|
|
2709
|
+
var DEFAULT_API_URL = "https://api-public.streamflow.finance";
|
|
2710
|
+
var DEFAULT_DEVNET_API_URL = "https://api-public-staging.streamflow.finance";
|
|
2711
|
+
var createClient = (options) => {
|
|
2712
|
+
const apiUrl = options?.apiUrl ?? options?.cluster === "mainnet" ? DEFAULT_API_URL : DEFAULT_DEVNET_API_URL;
|
|
2713
|
+
const fetchFn = options?.fetchFn ?? fetch;
|
|
2714
|
+
const fetchResource = async (url, options2) => {
|
|
2715
|
+
const res = await fetchFn(url, {
|
|
2716
|
+
method: "GET",
|
|
2717
|
+
headers: { "Content-Type": "application/json" },
|
|
2718
|
+
...{}
|
|
2719
|
+
});
|
|
2720
|
+
if (!res.ok) {
|
|
2721
|
+
const text = await res.text().catch(() => "");
|
|
2722
|
+
throw new Error(`Tabularium API error`, {
|
|
2723
|
+
cause: new Error(`: ${res.status} ${res.statusText}${text ? ` - ${text}` : ""}`)
|
|
2724
|
+
});
|
|
2725
|
+
}
|
|
2726
|
+
return res.json();
|
|
2727
|
+
};
|
|
2728
|
+
return {
|
|
2729
|
+
getContracts: async (opts) => {
|
|
2730
|
+
const params = new URLSearchParams();
|
|
2731
|
+
if (opts?.sender) params.set("sender", opts.sender);
|
|
2732
|
+
if (opts?.recipient) params.set("recipient", opts.recipient);
|
|
2733
|
+
const url = `${apiUrl}/v2/api/contracts/tabularium/${params.toString() ? `?${params.toString()}` : ""}`;
|
|
2734
|
+
return fetchResource(url);
|
|
2735
|
+
},
|
|
2736
|
+
getContract: async (address) => {
|
|
2737
|
+
const url = `${apiUrl}/v2/api/contracts/tabularium/${encodeURIComponent(address)}`;
|
|
2738
|
+
return fetchResource(url);
|
|
2739
|
+
}
|
|
2740
|
+
};
|
|
2741
|
+
};
|
|
2742
|
+
var isoToUnix = (iso) => {
|
|
2743
|
+
if (!iso) return 0;
|
|
2744
|
+
const time = new Date(iso).getTime();
|
|
2745
|
+
return Number.isNaN(time) ? 0 : Math.floor(time / 1e3);
|
|
2746
|
+
};
|
|
2747
|
+
var toBN = (value) => new BN3(value);
|
|
2748
|
+
var mapOracleType = (apiType) => {
|
|
2749
|
+
if (!apiType) return { none: {} };
|
|
2750
|
+
const mapping = {
|
|
2751
|
+
TEST: { test: {} },
|
|
2752
|
+
PYTH: { pyth: {} },
|
|
2753
|
+
SWITCHBOARD: { switchboard: {} }
|
|
2754
|
+
};
|
|
2755
|
+
return mapping[apiType] ?? { none: {} };
|
|
2756
|
+
};
|
|
2757
|
+
async function toDecodedStream(schema) {
|
|
2758
|
+
const mint = pk(schema.mint);
|
|
2759
|
+
const sender = pk(schema.sender);
|
|
2760
|
+
const recipient = pk(schema.recipient);
|
|
2761
|
+
const partner = schema.partner ? pk(schema.partner) : sender;
|
|
2762
|
+
const payer = schema.payer ? pk(schema.payer) : PublicKey.default;
|
|
2763
|
+
const [senderTokens, recipientTokens, partnerTokens, streamflowTreasuryTokens] = await Promise.all([
|
|
2764
|
+
ata(mint, sender),
|
|
2765
|
+
ata(mint, recipient),
|
|
2766
|
+
ata(mint, partner),
|
|
2767
|
+
ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY)
|
|
2768
|
+
]);
|
|
2769
|
+
return {
|
|
2770
|
+
magic: toBN(4),
|
|
2771
|
+
version: toBN(4),
|
|
2772
|
+
createdAt: toBN(isoToUnix(schema.createdDt)),
|
|
2773
|
+
withdrawnAmount: toBN(schema.claimedAmount),
|
|
2774
|
+
canceledAt: toBN(isoToUnix(schema.canceledDt)),
|
|
2775
|
+
end: toBN(isoToUnix(schema.endDt)),
|
|
2776
|
+
lastWithdrawnAt: toBN(isoToUnix(schema.lastClaimedDt)),
|
|
2777
|
+
sender,
|
|
2778
|
+
senderTokens,
|
|
2779
|
+
recipient,
|
|
2780
|
+
recipientTokens,
|
|
2781
|
+
mint,
|
|
2782
|
+
escrowTokens: schema.escrow ? pk(schema.escrow) : PublicKey.default,
|
|
2783
|
+
streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
2784
|
+
streamflowTreasuryTokens,
|
|
2785
|
+
streamflowFeeTotal: toBN(schema.streamflowFee),
|
|
2786
|
+
streamflowFeeWithdrawn: toBN(schema.streamflowFeeWithdrawn),
|
|
2787
|
+
streamflowFeePercent: parseFloat(schema.streamflowFeePercentage) || 0,
|
|
2788
|
+
partnerFeeTotal: toBN(schema.partnerFee),
|
|
2789
|
+
partnerFeeWithdrawn: toBN(schema.partnerFeeWithdrawn),
|
|
2790
|
+
partnerFeePercent: parseFloat(schema.partnerFeePercentage) || 0,
|
|
2791
|
+
partner,
|
|
2792
|
+
partnerTokens,
|
|
2793
|
+
start: toBN(isoToUnix(schema.startDt)),
|
|
2794
|
+
depositedAmount: toBN(schema.amount),
|
|
2795
|
+
period: toBN(schema.period),
|
|
2796
|
+
amountPerPeriod: toBN(schema.amountPerPeriod),
|
|
2797
|
+
cliff: toBN(isoToUnix(schema.startDt)),
|
|
2798
|
+
cliffAmount: toBN(schema.cliffAmount),
|
|
2799
|
+
cancelableBySender: schema.isCancelableBySender,
|
|
2800
|
+
cancelableByRecipient: schema.isCancelableByRecipient,
|
|
2801
|
+
automaticWithdrawal: schema.hasAutoClaim,
|
|
2802
|
+
transferableBySender: schema.isTransferableBySender,
|
|
2803
|
+
transferableByRecipient: schema.isTransferableByRecipient,
|
|
2804
|
+
canTopup: schema.canTopup,
|
|
2805
|
+
name: schema.name,
|
|
2806
|
+
withdrawFrequency: toBN(schema.autoClaimPeriod),
|
|
2807
|
+
isPda: schema.isPda,
|
|
2808
|
+
nonce: schema.nonce ? schema.nonce : 0,
|
|
2809
|
+
closed: schema.isClosed,
|
|
2810
|
+
currentPauseStart: toBN(0),
|
|
2811
|
+
pauseCumulative: toBN(schema.pauseCumulative),
|
|
2812
|
+
lastRateChangeTime: toBN(isoToUnix(schema.lastRateUpdateDt)),
|
|
2813
|
+
fundsUnlockedAtLastRateChange: toBN(schema.amountUnlockedAtLastRateUpdate),
|
|
2814
|
+
oldMetadata: PublicKey.default,
|
|
2815
|
+
payer,
|
|
2816
|
+
bump: schema.bump ? schema.bump : 0
|
|
2817
|
+
};
|
|
2818
|
+
}
|
|
2819
|
+
function toPrecisionBN(value, precision = ALIGNED_PRECISION_FACTOR_POW2) {
|
|
2820
|
+
return getBN(typeof value === "number" ? value : parseFloat(value), precision);
|
|
2821
|
+
}
|
|
2822
|
+
function toAlignedProxy(dynamic) {
|
|
2823
|
+
const proxy = {
|
|
2824
|
+
sender: pk(dynamic.sender),
|
|
2825
|
+
minPrice: toPrecisionBN(dynamic.minPrice),
|
|
2826
|
+
maxPrice: toPrecisionBN(dynamic.maxPrice),
|
|
2827
|
+
minPercentage: toPrecisionBN(dynamic.minPercentage),
|
|
2828
|
+
maxPercentage: toPrecisionBN(dynamic.maxPercentage),
|
|
2829
|
+
priceOracleType: mapOracleType(dynamic.priceOracleType),
|
|
2830
|
+
priceOracle: dynamic.priceOracleAddress ? pk(dynamic.priceOracleAddress) : PublicKey.default,
|
|
2831
|
+
tickSize: toPrecisionBN(dynamic.tickSize),
|
|
2832
|
+
initialAmountPerPeriod: toBN(dynamic.initialAmountPerPeriod),
|
|
2833
|
+
initialPrice: toPrecisionBN(dynamic.initialPrice),
|
|
2834
|
+
lastPrice: toPrecisionBN(dynamic.lastPrice),
|
|
2835
|
+
lastAmountUpdateTime: toBN(isoToUnix(dynamic.expiryDt)),
|
|
2836
|
+
initialNetAmount: toBN(dynamic.initialAmount),
|
|
2837
|
+
expiryTime: toBN(isoToUnix(dynamic.expiryDt)),
|
|
2838
|
+
expiryPercentage: toPrecisionBN(dynamic.expiryPercentage),
|
|
2839
|
+
floorPrice: toPrecisionBN(dynamic.floorPrice),
|
|
2840
|
+
streamCanceledTime: dynamic.streamCanceledTime ? toBN(dynamic.streamCanceledTime) : toBN(0)
|
|
2841
|
+
};
|
|
2842
|
+
return proxy;
|
|
2843
|
+
}
|
|
2844
|
+
var transformContract = async (schema) => {
|
|
2845
|
+
const decodedStream = await toDecodedStream(schema);
|
|
2846
|
+
if (schema.dynamicContract) {
|
|
2847
|
+
const alignedProxy = toAlignedProxy(schema.dynamicContract);
|
|
2848
|
+
return new AlignedContract(decodedStream, alignedProxy);
|
|
2849
|
+
}
|
|
2850
|
+
return new Contract(decodedStream);
|
|
2851
|
+
};
|
|
2852
|
+
|
|
2520
2853
|
// solana/StreamClient.ts
|
|
2521
2854
|
var METADATA_ACC_SIZE = 1104;
|
|
2522
2855
|
var ALIGNED_METADATA_ACC_SIZE = 320;
|
|
@@ -2559,6 +2892,9 @@ var SolanaStreamClient = class {
|
|
|
2559
2892
|
address: streamflow_aligned_unlocks_default.address
|
|
2560
2893
|
};
|
|
2561
2894
|
this.alignedProxyProgram = new Program(alignedUnlocksProgram, { connection: this.connection });
|
|
2895
|
+
this.apiClient = createClient(
|
|
2896
|
+
typeof optionsOrClusterUrl === "object" && optionsOrClusterUrl.cluster !== ICluster.Mainnet ? { cluster: "devnet" } : { cluster: "mainnet" }
|
|
2897
|
+
);
|
|
2562
2898
|
}
|
|
2563
2899
|
getConnection() {
|
|
2564
2900
|
return this.connection;
|
|
@@ -2805,7 +3141,8 @@ var SolanaStreamClient = class {
|
|
|
2805
3141
|
automaticWithdrawal = false,
|
|
2806
3142
|
withdrawalFrequency = 0,
|
|
2807
3143
|
partner,
|
|
2808
|
-
tokenProgramId: streamTokenProgramId
|
|
3144
|
+
tokenProgramId: streamTokenProgramId,
|
|
3145
|
+
nonce
|
|
2809
3146
|
}, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
|
|
2810
3147
|
assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
|
|
2811
3148
|
const ixs = prepareBaseInstructions(this.connection, {
|
|
@@ -2814,7 +3151,13 @@ var SolanaStreamClient = class {
|
|
|
2814
3151
|
});
|
|
2815
3152
|
const mintPublicKey = isNative ? NATIVE_MINT : new PublicKey(mint);
|
|
2816
3153
|
const recipientPublicKey = new PublicKey(recipient);
|
|
2817
|
-
|
|
3154
|
+
let metadata;
|
|
3155
|
+
let metadataPubKey;
|
|
3156
|
+
if (nonce != null) {
|
|
3157
|
+
[metadataPubKey] = deriveStreamMetadataPDA(this.programId, mintPublicKey, sender.publicKey, nonce);
|
|
3158
|
+
} else {
|
|
3159
|
+
({ metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys));
|
|
3160
|
+
}
|
|
2818
3161
|
const [escrowTokens] = PublicKey.findProgramAddressSync(
|
|
2819
3162
|
[Buffer.from("strm"), metadataPubKey.toBuffer()],
|
|
2820
3163
|
this.programId
|
|
@@ -2828,49 +3171,49 @@ var SolanaStreamClient = class {
|
|
|
2828
3171
|
const streamflowTreasuryTokens = await ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
2829
3172
|
const partnerPublicKey = partner ? new PublicKey(partner) : sender.publicKey;
|
|
2830
3173
|
const partnerTokens = await ata(mintPublicKey, partnerPublicKey, tokenProgramId);
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
)
|
|
2873
|
-
|
|
3174
|
+
const accounts = {
|
|
3175
|
+
sender: sender.publicKey,
|
|
3176
|
+
senderTokens,
|
|
3177
|
+
recipient: new PublicKey(recipient),
|
|
3178
|
+
metadata: metadataPubKey,
|
|
3179
|
+
escrowTokens,
|
|
3180
|
+
recipientTokens,
|
|
3181
|
+
streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
3182
|
+
streamflowTreasuryTokens,
|
|
3183
|
+
partner: partnerPublicKey,
|
|
3184
|
+
partnerTokens,
|
|
3185
|
+
mint: new PublicKey(mint),
|
|
3186
|
+
feeOracle: this.feeOraclePublicKey,
|
|
3187
|
+
rent: SYSVAR_RENT_PUBKEY,
|
|
3188
|
+
timelockProgram: this.programId,
|
|
3189
|
+
tokenProgram: tokenProgramId,
|
|
3190
|
+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
3191
|
+
withdrawor: WITHDRAWOR_PUBLIC_KEY,
|
|
3192
|
+
systemProgram: SystemProgram.programId
|
|
3193
|
+
};
|
|
3194
|
+
const baseData = {
|
|
3195
|
+
start: new BN3(start),
|
|
3196
|
+
depositedAmount,
|
|
3197
|
+
period: new BN3(period),
|
|
3198
|
+
amountPerPeriod,
|
|
3199
|
+
cliff: new BN3(cliff),
|
|
3200
|
+
cliffAmount: new BN3(cliffAmount),
|
|
3201
|
+
cancelableBySender,
|
|
3202
|
+
cancelableByRecipient,
|
|
3203
|
+
automaticWithdrawal,
|
|
3204
|
+
transferableBySender,
|
|
3205
|
+
transferableByRecipient,
|
|
3206
|
+
canTopup,
|
|
3207
|
+
canUpdateRate: !!canUpdateRate,
|
|
3208
|
+
canPause: !!canPause,
|
|
3209
|
+
name,
|
|
3210
|
+
withdrawFrequency: new BN3(automaticWithdrawal ? withdrawalFrequency : period)
|
|
3211
|
+
};
|
|
3212
|
+
if (nonce != null) {
|
|
3213
|
+
ixs.push(await createStreamV2Instruction({ ...baseData, nonce }, this.programId, accounts));
|
|
3214
|
+
} else {
|
|
3215
|
+
ixs.push(await createStreamInstruction(baseData, this.programId, accounts));
|
|
3216
|
+
}
|
|
2874
3217
|
return { ixs, metadata, metadataPubKey };
|
|
2875
3218
|
}
|
|
2876
3219
|
/**
|
|
@@ -2930,20 +3273,19 @@ var SolanaStreamClient = class {
|
|
|
2930
3273
|
transferableByRecipient,
|
|
2931
3274
|
automaticWithdrawal = false,
|
|
2932
3275
|
withdrawalFrequency = 0,
|
|
2933
|
-
partner
|
|
3276
|
+
partner,
|
|
3277
|
+
nonce
|
|
2934
3278
|
}, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
|
|
2935
3279
|
assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
|
|
2936
3280
|
const mintPublicKey = new PublicKey(mint);
|
|
2937
3281
|
const recipientPublicKey = new PublicKey(recipient);
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
newAccountPubkey: metadataPubKey
|
|
2946
|
-
});
|
|
3282
|
+
let metadata;
|
|
3283
|
+
let metadataPubKey;
|
|
3284
|
+
if (nonce != null) {
|
|
3285
|
+
[metadataPubKey] = deriveStreamMetadataPDA(this.programId, mintPublicKey, sender.publicKey, nonce);
|
|
3286
|
+
} else {
|
|
3287
|
+
({ metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys));
|
|
3288
|
+
}
|
|
2947
3289
|
const [escrowTokens] = PublicKey.findProgramAddressSync(
|
|
2948
3290
|
[Buffer.from("strm"), metadataPubKey.toBuffer()],
|
|
2949
3291
|
this.programId
|
|
@@ -2960,43 +3302,58 @@ var SolanaStreamClient = class {
|
|
|
2960
3302
|
const totalAmount = calculateTotalAmountToDeposit(depositedAmount, totalFee);
|
|
2961
3303
|
ixs.push(...await prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
|
|
2962
3304
|
}
|
|
2963
|
-
const
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3305
|
+
const accounts = {
|
|
3306
|
+
sender: sender.publicKey,
|
|
3307
|
+
senderTokens,
|
|
3308
|
+
metadata: metadataPubKey,
|
|
3309
|
+
escrowTokens,
|
|
3310
|
+
mint: new PublicKey(mint),
|
|
3311
|
+
feeOracle: this.feeOraclePublicKey,
|
|
3312
|
+
rent: SYSVAR_RENT_PUBKEY,
|
|
3313
|
+
timelockProgram: this.programId,
|
|
3314
|
+
tokenProgram: tokenProgramId,
|
|
3315
|
+
withdrawor: WITHDRAWOR_PUBLIC_KEY,
|
|
3316
|
+
systemProgram: SystemProgram.programId
|
|
3317
|
+
};
|
|
3318
|
+
const baseData = {
|
|
3319
|
+
start: new BN3(start),
|
|
3320
|
+
depositedAmount,
|
|
3321
|
+
period: new BN3(period),
|
|
3322
|
+
amountPerPeriod,
|
|
3323
|
+
cliff: new BN3(cliff),
|
|
3324
|
+
cliffAmount: new BN3(cliffAmount),
|
|
3325
|
+
cancelableBySender,
|
|
3326
|
+
cancelableByRecipient,
|
|
3327
|
+
automaticWithdrawal,
|
|
3328
|
+
transferableBySender,
|
|
3329
|
+
transferableByRecipient,
|
|
3330
|
+
canTopup,
|
|
3331
|
+
canUpdateRate: !!canUpdateRate,
|
|
3332
|
+
canPause: !!canPause,
|
|
3333
|
+
name,
|
|
3334
|
+
withdrawFrequency: new BN3(automaticWithdrawal ? withdrawalFrequency : period),
|
|
3335
|
+
recipient: recipientPublicKey,
|
|
3336
|
+
partner: partnerPublicKey
|
|
3337
|
+
};
|
|
3338
|
+
if (nonce != null) {
|
|
3339
|
+
const createInstruction = await createUncheckedStreamV2Instruction(
|
|
3340
|
+
{ ...baseData, nonce },
|
|
3341
|
+
this.programId,
|
|
3342
|
+
accounts
|
|
3343
|
+
);
|
|
3344
|
+
ixs.push(createInstruction);
|
|
3345
|
+
} else {
|
|
3346
|
+
const rentToExempt = await this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE);
|
|
3347
|
+
const createMetadataInstruction = SystemProgram.createAccount({
|
|
3348
|
+
programId: this.programId,
|
|
3349
|
+
space: METADATA_ACC_SIZE,
|
|
3350
|
+
lamports: rentToExempt,
|
|
3351
|
+
fromPubkey: sender.publicKey,
|
|
3352
|
+
newAccountPubkey: metadataPubKey
|
|
3353
|
+
});
|
|
3354
|
+
const createInstruction = await createUncheckedStreamInstruction(baseData, this.programId, accounts);
|
|
3355
|
+
ixs.push(createMetadataInstruction, createInstruction);
|
|
3356
|
+
}
|
|
3000
3357
|
return { ixs, metadata, metadataPubKey };
|
|
3001
3358
|
}
|
|
3002
3359
|
/**
|
|
@@ -3338,7 +3695,7 @@ var SolanaStreamClient = class {
|
|
|
3338
3695
|
throw new Error("Impossible to cancel a stream contract that does not exist");
|
|
3339
3696
|
}
|
|
3340
3697
|
const decoded = decodeStream(account.data);
|
|
3341
|
-
const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, decoded.sender
|
|
3698
|
+
const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, decoded.sender);
|
|
3342
3699
|
const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelLinearStream(cancelData, extParams);
|
|
3343
3700
|
return ixs;
|
|
3344
3701
|
}
|
|
@@ -3574,17 +3931,21 @@ var SolanaStreamClient = class {
|
|
|
3574
3931
|
}
|
|
3575
3932
|
]
|
|
3576
3933
|
});
|
|
3577
|
-
if (migrated.length
|
|
3578
|
-
|
|
3934
|
+
if (migrated.length > 0) {
|
|
3935
|
+
return this.decodeStreamAccount(migrated[0].pubkey, migrated[0].account.data);
|
|
3936
|
+
}
|
|
3937
|
+
try {
|
|
3938
|
+
const contract = await this.apiClient.getContract(id);
|
|
3939
|
+
return await transformContract(contract);
|
|
3940
|
+
} catch (cause) {
|
|
3941
|
+
throw new Error(`Couldn't get account info from chain or Tabularium`, { cause });
|
|
3579
3942
|
}
|
|
3580
|
-
return this.decodeStreamAccount(migrated[0].pubkey, migrated[0].account.data);
|
|
3581
3943
|
}
|
|
3582
3944
|
async decodeStreamAccount(pubkey, data) {
|
|
3583
3945
|
const stream = decodeStream(data);
|
|
3584
|
-
|
|
3585
|
-
if (this.isAlignedUnlock(pubkey, stream.sender, stream.oldMetadata)) {
|
|
3946
|
+
if (this.isAlignedUnlock(pubkey, stream.sender)) {
|
|
3586
3947
|
const alignedProxy = await this.alignedProxyProgram.account.contract.fetch(
|
|
3587
|
-
deriveContractPDA(this.alignedProxyProgram.programId,
|
|
3948
|
+
deriveContractPDA(this.alignedProxyProgram.programId, pubkey)
|
|
3588
3949
|
);
|
|
3589
3950
|
if (!alignedProxy) {
|
|
3590
3951
|
throw new Error("Couldn't get proxy account info.");
|
|
@@ -3625,9 +3986,7 @@ var SolanaStreamClient = class {
|
|
|
3625
3986
|
const streams = {};
|
|
3626
3987
|
const alignedStreamsPubKeys = Object.keys(streamRecord);
|
|
3627
3988
|
const alignedProxyPDAs = alignedStreamsPubKeys.map((streamPubKey) => {
|
|
3628
|
-
|
|
3629
|
-
const metadataKey = getMetadataKey(pubkey, streamRecord[streamPubKey].oldMetadata);
|
|
3630
|
-
return deriveContractPDA(this.alignedProxyProgram.programId, metadataKey);
|
|
3989
|
+
return deriveContractPDA(this.alignedProxyProgram.programId, new PublicKey(streamPubKey));
|
|
3631
3990
|
});
|
|
3632
3991
|
const alignedProxyAccounts = await getMultipleAccountsInfoBatched(this.connection, alignedProxyPDAs);
|
|
3633
3992
|
alignedProxyAccounts.forEach((account, index) => {
|
|
@@ -3650,7 +4009,8 @@ var SolanaStreamClient = class {
|
|
|
3650
4009
|
async get({
|
|
3651
4010
|
address,
|
|
3652
4011
|
type = "all" /* All */,
|
|
3653
|
-
direction = "all" /* All
|
|
4012
|
+
direction = "all" /* All */,
|
|
4013
|
+
filters
|
|
3654
4014
|
}) {
|
|
3655
4015
|
const publicKey = new PublicKey(address);
|
|
3656
4016
|
let streams = {};
|
|
@@ -3680,7 +4040,7 @@ var SolanaStreamClient = class {
|
|
|
3680
4040
|
const allIncomingStreams = allIncomingAccounts.map((account) => decodeStream(account.account.data));
|
|
3681
4041
|
const alignedDecoded = {};
|
|
3682
4042
|
allIncomingAccounts.forEach((account, index) => {
|
|
3683
|
-
if (this.isAlignedUnlock(account.pubkey, allIncomingStreams[index].sender
|
|
4043
|
+
if (this.isAlignedUnlock(account.pubkey, allIncomingStreams[index].sender)) {
|
|
3684
4044
|
alignedDecoded[account.pubkey.toBase58()] = allIncomingStreams[index];
|
|
3685
4045
|
} else {
|
|
3686
4046
|
streams[account.pubkey.toBase58()] = new Contract(allIncomingStreams[index]);
|
|
@@ -3691,6 +4051,10 @@ var SolanaStreamClient = class {
|
|
|
3691
4051
|
streams = { ...streams, ...incomingAlignedStreams };
|
|
3692
4052
|
}
|
|
3693
4053
|
}
|
|
4054
|
+
if (filters?.closed) {
|
|
4055
|
+
const closedStreams = await this.getClosedStreams(address, direction);
|
|
4056
|
+
streams = { ...streams, ...closedStreams };
|
|
4057
|
+
}
|
|
3694
4058
|
const sortedStreams = Object.entries(streams).sort(([, stream1], [, stream2]) => stream2.start - stream1.start);
|
|
3695
4059
|
if (type === "all" /* All */) return sortedStreams;
|
|
3696
4060
|
return sortedStreams.filter((stream) => stream[1].type === type);
|
|
@@ -3725,9 +4089,8 @@ var SolanaStreamClient = class {
|
|
|
3725
4089
|
collectAlignedEntries(decoded) {
|
|
3726
4090
|
const entries = [];
|
|
3727
4091
|
decoded.forEach(({ pubkey, stream }, index) => {
|
|
3728
|
-
if (this.isAlignedUnlock(pubkey, stream.sender
|
|
3729
|
-
|
|
3730
|
-
entries.push({ index, pda: deriveContractPDA(this.alignedProxyProgram.programId, metadataKey) });
|
|
4092
|
+
if (this.isAlignedUnlock(pubkey, stream.sender)) {
|
|
4093
|
+
entries.push({ index, pda: deriveContractPDA(this.alignedProxyProgram.programId, pubkey) });
|
|
3731
4094
|
}
|
|
3732
4095
|
});
|
|
3733
4096
|
return entries;
|
|
@@ -3788,7 +4151,7 @@ var SolanaStreamClient = class {
|
|
|
3788
4151
|
const escrow = await this.connection.getAccountInfo(streamPublicKey);
|
|
3789
4152
|
invariant(escrow, "Couldn't get account info");
|
|
3790
4153
|
const decoded = decodeStream(escrow.data);
|
|
3791
|
-
const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, decoded.sender
|
|
4154
|
+
const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, decoded.sender);
|
|
3792
4155
|
if (isAlignedUnlock && (data.enableAutomaticWithdrawal !== void 0 || data.amountPerPeriod !== void 0)) {
|
|
3793
4156
|
throw new Error("Automatic withdrawal and rate update are not possible in price-based vesting!");
|
|
3794
4157
|
}
|
|
@@ -3882,9 +4245,8 @@ var SolanaStreamClient = class {
|
|
|
3882
4245
|
* Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA.
|
|
3883
4246
|
* For migrated streams, the PDA was derived from the old metadata key.
|
|
3884
4247
|
*/
|
|
3885
|
-
isAlignedUnlock(streamPublicKey, senderPublicKey
|
|
3886
|
-
const
|
|
3887
|
-
const pda = deriveContractPDA(this.alignedProxyProgram.programId, metadataKey);
|
|
4248
|
+
isAlignedUnlock(streamPublicKey, senderPublicKey) {
|
|
4249
|
+
const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
|
|
3888
4250
|
return senderPublicKey.equals(pda);
|
|
3889
4251
|
}
|
|
3890
4252
|
async flatBuildCreateMultipleTransactionInstructions(data, extParams) {
|
|
@@ -3902,6 +4264,40 @@ var SolanaStreamClient = class {
|
|
|
3902
4264
|
)
|
|
3903
4265
|
};
|
|
3904
4266
|
}
|
|
4267
|
+
/**
|
|
4268
|
+
* Gets closed streams for a given owner and direction
|
|
4269
|
+
* @param owner - Owner address
|
|
4270
|
+
* @param direction - Stream direction
|
|
4271
|
+
* @returns Record of closed streams
|
|
4272
|
+
*/
|
|
4273
|
+
async getClosedStreams(owner, direction = "all" /* All */) {
|
|
4274
|
+
const streams = {};
|
|
4275
|
+
try {
|
|
4276
|
+
const tabulariumContracts = await this.apiClient.getContracts({
|
|
4277
|
+
sender: direction !== "incoming" /* Incoming */ ? owner : void 0,
|
|
4278
|
+
recipient: direction !== "outgoing" /* Outgoing */ ? owner : void 0
|
|
4279
|
+
});
|
|
4280
|
+
for (const contract of tabulariumContracts) {
|
|
4281
|
+
if (!streams[contract.address]) {
|
|
4282
|
+
try {
|
|
4283
|
+
const transformed = await transformContract(contract);
|
|
4284
|
+
streams[contract.address] = transformed;
|
|
4285
|
+
} catch (cause) {
|
|
4286
|
+
if (isDev) {
|
|
4287
|
+
throw new Error(`Failed to transform contract ${contract.address}:`, { cause });
|
|
4288
|
+
}
|
|
4289
|
+
console.warn(new Error(`Failed to transform contract ${contract.address}:`, { cause }));
|
|
4290
|
+
}
|
|
4291
|
+
}
|
|
4292
|
+
}
|
|
4293
|
+
} catch (cause) {
|
|
4294
|
+
if (isDev) {
|
|
4295
|
+
throw new Error("Failed to get data from the service", { cause });
|
|
4296
|
+
}
|
|
4297
|
+
console.warn(new Error("Failed to get data from the service", { cause }));
|
|
4298
|
+
}
|
|
4299
|
+
return streams;
|
|
4300
|
+
}
|
|
3905
4301
|
/**
|
|
3906
4302
|
* Utility function to generate metadata for a Contract or return existing Pubkey
|
|
3907
4303
|
*/
|
|
@@ -4361,6 +4757,6 @@ var timelockIDL_default = {
|
|
|
4361
4757
|
]
|
|
4362
4758
|
};
|
|
4363
4759
|
|
|
4364
|
-
export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW2 as ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, AlignedContract, AlignedProxyErrorCode, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Contract, ContractErrorCode, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, MAX_SAFE_UNIX_TIME_VALUE2 as MAX_SAFE_UNIX_TIME_VALUE, ORIGINAL_CONTRACT_SENDER_OFFSET, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, REPOPULATED_METADATA_SEED, SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSETS, STREAM_STRUCT_OFFSET_CLOSED, STREAM_STRUCT_OFFSET_MINT, STREAM_STRUCT_OFFSET_OLD_METADATA_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, SolanaStreamClient, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createStreamInstruction, createUncheckedStreamInstruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveRepopulatedMetadataPDA, deriveTestOraclePDA, extractSolanaErrorCode, getMetadataKey, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL_default as timelockIDL, topupStreamInstruction, transferStreamInstruction, updateStreamInstruction, withdrawStreamInstruction };
|
|
4760
|
+
export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW2 as ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, AlignedContract, AlignedProxyErrorCode, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Contract, ContractErrorCode, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, MAX_SAFE_UNIX_TIME_VALUE2 as MAX_SAFE_UNIX_TIME_VALUE, METADATA_SEED, ORIGINAL_CONTRACT_SENDER_OFFSET, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, REPOPULATED_METADATA_SEED, SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSETS, STREAM_STRUCT_OFFSET_CLOSED, STREAM_STRUCT_OFFSET_MINT, STREAM_STRUCT_OFFSET_OLD_METADATA_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, SolanaStreamClient, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createClient, createStreamInstruction, createStreamV2Instruction, createUncheckedStreamInstruction, createUncheckedStreamV2Instruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveRepopulatedMetadataPDA, deriveStreamMetadataPDA, deriveTestOraclePDA, extractSolanaErrorCode, getMetadataKey, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL_default as timelockIDL, topupStreamInstruction, transferStreamInstruction, transformContract, updateStreamInstruction, withdrawStreamInstruction };
|
|
4365
4761
|
//# sourceMappingURL=index.js.map
|
|
4366
4762
|
//# sourceMappingURL=index.js.map
|