@streamflow/stream 11.0.2 → 11.0.4-alpha.p341.d4e1f95
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 +215 -22
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/solana/index.cjs +215 -22
- package/dist/cjs/solana/index.cjs.map +1 -1
- package/dist/cjs/solana/index.d.cts +183 -7
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +212 -23
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solana/index.d.ts +183 -7
- package/dist/esm/solana/index.js +212 -23
- package/dist/esm/solana/index.js.map +1 -1
- package/package.json +5 -4
package/dist/esm/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import bs58 from 'bs58';
|
|
|
3
3
|
import { Buffer } from 'buffer';
|
|
4
4
|
import { NATIVE_MINT, ASSOCIATED_TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
5
5
|
import { PublicKey, TransactionInstruction, Connection, Keypair, SYSVAR_RENT_PUBKEY, SystemProgram, 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,
|
|
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';
|
|
@@ -116,7 +116,7 @@ var AlignedProxyErrorCode = /* @__PURE__ */ ((AlignedProxyErrorCode2) => {
|
|
|
116
116
|
return AlignedProxyErrorCode2;
|
|
117
117
|
})(AlignedProxyErrorCode || {});
|
|
118
118
|
var Contract = class {
|
|
119
|
-
constructor(stream
|
|
119
|
+
constructor(stream) {
|
|
120
120
|
this.magic = stream.magic.toNumber();
|
|
121
121
|
this.version = stream.version.toNumber();
|
|
122
122
|
this.createdAt = stream.createdAt.toNumber();
|
|
@@ -160,7 +160,6 @@ var Contract = class {
|
|
|
160
160
|
this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
|
|
161
161
|
this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
|
|
162
162
|
this.oldMetadata = stream.oldMetadata;
|
|
163
|
-
this.metadata = metadata;
|
|
164
163
|
this.type = buildStreamType(this);
|
|
165
164
|
this.isAligned = false;
|
|
166
165
|
}
|
|
@@ -175,8 +174,8 @@ var Contract = class {
|
|
|
175
174
|
}
|
|
176
175
|
};
|
|
177
176
|
var AlignedContract = class extends Contract {
|
|
178
|
-
constructor(stream,
|
|
179
|
-
super(stream
|
|
177
|
+
constructor(stream, alignedProxy) {
|
|
178
|
+
super(stream);
|
|
180
179
|
this.minPrice = getNumberFromBN(alignedProxy.minPrice, ALIGNED_PRECISION_FACTOR_POW);
|
|
181
180
|
this.maxPrice = getNumberFromBN(alignedProxy.maxPrice, ALIGNED_PRECISION_FACTOR_POW);
|
|
182
181
|
this.minPercentage = getNumberFromBN(alignedProxy.minPercentage, ALIGNED_PRECISION_FACTOR_POW);
|
|
@@ -246,6 +245,7 @@ var TEST_ORACLE_DISCRIMINATOR = [198, 49, 63, 134, 232, 251, 168, 28];
|
|
|
246
245
|
var CONTRACT_SEED = Buffer.from("contract", "utf-8");
|
|
247
246
|
var ESCROW_SEED = Buffer.from("strm", "utf-8");
|
|
248
247
|
var TEST_ORACLE_SEED = Buffer.from("test-oracle", "utf-8");
|
|
248
|
+
var REPOPULATED_METADATA_SEED = Buffer.from("strm-rep", "utf-8");
|
|
249
249
|
var STREAMFLOW_TREASURY_PUBLIC_KEY = new PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
|
|
250
250
|
var WITHDRAWOR = "wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u";
|
|
251
251
|
var WITHDRAWOR_PUBLIC_KEY = new PublicKey(WITHDRAWOR);
|
|
@@ -470,7 +470,7 @@ var encodeUpdateStream = (values, data) => {
|
|
|
470
470
|
var topupStreamLayout = BufferLayout.struct([
|
|
471
471
|
BufferLayout.blob(8, "amount")
|
|
472
472
|
]);
|
|
473
|
-
var
|
|
473
|
+
var getMetadataKey = (streamPubkey, oldMetadata) => {
|
|
474
474
|
if (PublicKey.default.equals(oldMetadata)) {
|
|
475
475
|
return streamPubkey;
|
|
476
476
|
}
|
|
@@ -2513,6 +2513,149 @@ var deriveEscrowPDA = (programId, streamMetadata) => {
|
|
|
2513
2513
|
var deriveTestOraclePDA = (programId, mint, creator) => {
|
|
2514
2514
|
return PublicKey.findProgramAddressSync([TEST_ORACLE_SEED, mint.toBuffer(), creator.toBuffer()], programId)[0];
|
|
2515
2515
|
};
|
|
2516
|
+
var deriveRepopulatedMetadataPDA = (programId, streamMetadata) => {
|
|
2517
|
+
return PublicKey.findProgramAddressSync([REPOPULATED_METADATA_SEED, streamMetadata.toBuffer()], programId)[0];
|
|
2518
|
+
};
|
|
2519
|
+
|
|
2520
|
+
// solana/api-public/client.ts
|
|
2521
|
+
var DEFAULT_API_URL = "https://api-public.streamflow.finance";
|
|
2522
|
+
var DEFAULT_DEVNET_API_URL = "https://api-public-staging.streamflow.finance";
|
|
2523
|
+
var createClient = (options) => {
|
|
2524
|
+
const apiUrl = options?.apiUrl ?? options?.cluster === "mainnet" ? DEFAULT_API_URL : DEFAULT_DEVNET_API_URL;
|
|
2525
|
+
const fetchFn = options?.fetchFn ?? fetch;
|
|
2526
|
+
const fetchResource = async (url, options2) => {
|
|
2527
|
+
const res = await fetchFn(url, {
|
|
2528
|
+
method: "GET",
|
|
2529
|
+
headers: { "Content-Type": "application/json" },
|
|
2530
|
+
...{}
|
|
2531
|
+
});
|
|
2532
|
+
if (!res.ok) {
|
|
2533
|
+
const text = await res.text().catch(() => "");
|
|
2534
|
+
throw new Error(`Tabularium API error`, {
|
|
2535
|
+
cause: new Error(`: ${res.status} ${res.statusText}${text ? ` - ${text}` : ""}`)
|
|
2536
|
+
});
|
|
2537
|
+
}
|
|
2538
|
+
return res.json();
|
|
2539
|
+
};
|
|
2540
|
+
return {
|
|
2541
|
+
getContracts: async (opts) => {
|
|
2542
|
+
const params = new URLSearchParams();
|
|
2543
|
+
if (opts?.sender) params.set("sender", opts.sender);
|
|
2544
|
+
if (opts?.recipient) params.set("recipient", opts.recipient);
|
|
2545
|
+
const url = `${apiUrl}/v2/api/contracts/tabularium/${params.toString() ? `?${params.toString()}` : ""}`;
|
|
2546
|
+
return fetchResource(url);
|
|
2547
|
+
},
|
|
2548
|
+
getContract: async (address) => {
|
|
2549
|
+
const url = `${apiUrl}/v2/api/contracts/tabularium/${encodeURIComponent(address)}`;
|
|
2550
|
+
return fetchResource(url);
|
|
2551
|
+
}
|
|
2552
|
+
};
|
|
2553
|
+
};
|
|
2554
|
+
var isoToUnix = (iso) => {
|
|
2555
|
+
if (!iso) return 0;
|
|
2556
|
+
const time = new Date(iso).getTime();
|
|
2557
|
+
return Number.isNaN(time) ? 0 : Math.floor(time / 1e3);
|
|
2558
|
+
};
|
|
2559
|
+
var toBN = (value) => new BN3(value);
|
|
2560
|
+
var mapOracleType = (apiType) => {
|
|
2561
|
+
if (!apiType) return { none: {} };
|
|
2562
|
+
const mapping = {
|
|
2563
|
+
TEST: { test: {} },
|
|
2564
|
+
PYTH: { pyth: {} },
|
|
2565
|
+
SWITCHBOARD: { switchboard: {} }
|
|
2566
|
+
};
|
|
2567
|
+
return mapping[apiType] ?? { none: {} };
|
|
2568
|
+
};
|
|
2569
|
+
async function toDecodedStream(schema) {
|
|
2570
|
+
const mint = pk(schema.mint);
|
|
2571
|
+
const sender = pk(schema.sender);
|
|
2572
|
+
const recipient = pk(schema.recipient);
|
|
2573
|
+
const partner = schema.partner ? pk(schema.partner) : sender;
|
|
2574
|
+
const [senderTokens, recipientTokens, partnerTokens, streamflowTreasuryTokens] = await Promise.all([
|
|
2575
|
+
ata(mint, sender),
|
|
2576
|
+
ata(mint, recipient),
|
|
2577
|
+
ata(mint, partner),
|
|
2578
|
+
ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY)
|
|
2579
|
+
]);
|
|
2580
|
+
return {
|
|
2581
|
+
magic: toBN(4),
|
|
2582
|
+
version: toBN(4),
|
|
2583
|
+
createdAt: toBN(isoToUnix(schema.createdDt)),
|
|
2584
|
+
withdrawnAmount: toBN(schema.claimedAmount),
|
|
2585
|
+
canceledAt: toBN(isoToUnix(schema.canceledDt)),
|
|
2586
|
+
end: toBN(isoToUnix(schema.endDt)),
|
|
2587
|
+
lastWithdrawnAt: toBN(isoToUnix(schema.lastClaimedDt)),
|
|
2588
|
+
sender,
|
|
2589
|
+
senderTokens,
|
|
2590
|
+
recipient,
|
|
2591
|
+
recipientTokens,
|
|
2592
|
+
mint,
|
|
2593
|
+
escrowTokens: schema.escrow ? pk(schema.escrow) : PublicKey.default,
|
|
2594
|
+
streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
2595
|
+
streamflowTreasuryTokens,
|
|
2596
|
+
streamflowFeeTotal: toBN(schema.streamflowFee),
|
|
2597
|
+
streamflowFeeWithdrawn: toBN(schema.streamflowFeeWithdrawn),
|
|
2598
|
+
streamflowFeePercent: parseFloat(schema.streamflowFeePercentage) || 0,
|
|
2599
|
+
partnerFeeTotal: toBN(schema.partnerFee),
|
|
2600
|
+
partnerFeeWithdrawn: toBN(schema.partnerFeeWithdrawn),
|
|
2601
|
+
partnerFeePercent: parseFloat(schema.partnerFeePercentage) || 0,
|
|
2602
|
+
partner,
|
|
2603
|
+
partnerTokens,
|
|
2604
|
+
start: toBN(isoToUnix(schema.startDt)),
|
|
2605
|
+
depositedAmount: toBN(schema.amount),
|
|
2606
|
+
period: toBN(schema.period),
|
|
2607
|
+
amountPerPeriod: toBN(schema.amountPerPeriod),
|
|
2608
|
+
cliff: toBN(isoToUnix(schema.startDt)),
|
|
2609
|
+
cliffAmount: toBN(schema.cliffAmount),
|
|
2610
|
+
cancelableBySender: schema.isCancelableBySender,
|
|
2611
|
+
cancelableByRecipient: schema.isCancelableByRecipient,
|
|
2612
|
+
automaticWithdrawal: schema.hasAutoClaim,
|
|
2613
|
+
transferableBySender: schema.isTransferableBySender,
|
|
2614
|
+
transferableByRecipient: schema.isTransferableByRecipient,
|
|
2615
|
+
canTopup: schema.canTopup,
|
|
2616
|
+
name: schema.name,
|
|
2617
|
+
withdrawFrequency: toBN(schema.autoClaimPeriod),
|
|
2618
|
+
closed: schema.isClosed,
|
|
2619
|
+
currentPauseStart: toBN(0),
|
|
2620
|
+
pauseCumulative: toBN(schema.pauseCumulative),
|
|
2621
|
+
lastRateChangeTime: toBN(isoToUnix(schema.lastRateUpdateDt)),
|
|
2622
|
+
fundsUnlockedAtLastRateChange: toBN(schema.amountUnlockedAtLastRateUpdate),
|
|
2623
|
+
oldMetadata: PublicKey.default
|
|
2624
|
+
};
|
|
2625
|
+
}
|
|
2626
|
+
function toPrecisionBN(value, precision = ALIGNED_PRECISION_FACTOR_POW2) {
|
|
2627
|
+
return getBN(typeof value === "number" ? value : parseFloat(value), precision);
|
|
2628
|
+
}
|
|
2629
|
+
function toAlignedProxy(dynamic) {
|
|
2630
|
+
const proxy = {
|
|
2631
|
+
sender: pk(dynamic.sender),
|
|
2632
|
+
minPrice: toPrecisionBN(dynamic.minPrice),
|
|
2633
|
+
maxPrice: toPrecisionBN(dynamic.maxPrice),
|
|
2634
|
+
minPercentage: toPrecisionBN(dynamic.minPercentage),
|
|
2635
|
+
maxPercentage: toPrecisionBN(dynamic.maxPercentage),
|
|
2636
|
+
priceOracleType: mapOracleType(dynamic.priceOracleType),
|
|
2637
|
+
priceOracle: dynamic.priceOracleAddress ? pk(dynamic.priceOracleAddress) : PublicKey.default,
|
|
2638
|
+
tickSize: toPrecisionBN(dynamic.tickSize),
|
|
2639
|
+
initialAmountPerPeriod: toBN(dynamic.initialAmountPerPeriod),
|
|
2640
|
+
initialPrice: toPrecisionBN(dynamic.initialPrice),
|
|
2641
|
+
lastPrice: toPrecisionBN(dynamic.lastPrice),
|
|
2642
|
+
lastAmountUpdateTime: toBN(isoToUnix(dynamic.expiryDt)),
|
|
2643
|
+
initialNetAmount: toBN(dynamic.initialAmount),
|
|
2644
|
+
expiryTime: toBN(isoToUnix(dynamic.expiryDt)),
|
|
2645
|
+
expiryPercentage: toPrecisionBN(dynamic.expiryPercentage),
|
|
2646
|
+
floorPrice: toPrecisionBN(dynamic.floorPrice),
|
|
2647
|
+
streamCanceledTime: dynamic.streamCanceledTime ? toBN(dynamic.streamCanceledTime) : toBN(0)
|
|
2648
|
+
};
|
|
2649
|
+
return proxy;
|
|
2650
|
+
}
|
|
2651
|
+
var transformContract = async (schema) => {
|
|
2652
|
+
const decodedStream = await toDecodedStream(schema);
|
|
2653
|
+
if (schema.dynamicContract) {
|
|
2654
|
+
const alignedProxy = toAlignedProxy(schema.dynamicContract);
|
|
2655
|
+
return new AlignedContract(decodedStream, alignedProxy);
|
|
2656
|
+
}
|
|
2657
|
+
return new Contract(decodedStream);
|
|
2658
|
+
};
|
|
2516
2659
|
|
|
2517
2660
|
// solana/StreamClient.ts
|
|
2518
2661
|
var METADATA_ACC_SIZE = 1104;
|
|
@@ -2556,6 +2699,9 @@ var SolanaStreamClient = class {
|
|
|
2556
2699
|
address: streamflow_aligned_unlocks_default.address
|
|
2557
2700
|
};
|
|
2558
2701
|
this.alignedProxyProgram = new Program(alignedUnlocksProgram, { connection: this.connection });
|
|
2702
|
+
this.apiClient = createClient(
|
|
2703
|
+
typeof optionsOrClusterUrl === "object" && optionsOrClusterUrl.cluster !== ICluster.Mainnet ? { cluster: "devnet" } : { cluster: "mainnet" }
|
|
2704
|
+
);
|
|
2559
2705
|
}
|
|
2560
2706
|
getConnection() {
|
|
2561
2707
|
return this.connection;
|
|
@@ -3571,14 +3717,19 @@ var SolanaStreamClient = class {
|
|
|
3571
3717
|
}
|
|
3572
3718
|
]
|
|
3573
3719
|
});
|
|
3574
|
-
if (migrated.length
|
|
3575
|
-
|
|
3720
|
+
if (migrated.length > 0) {
|
|
3721
|
+
return this.decodeStreamAccount(migrated[0].pubkey, migrated[0].account.data);
|
|
3722
|
+
}
|
|
3723
|
+
try {
|
|
3724
|
+
const contract = await this.apiClient.getContract(id);
|
|
3725
|
+
return await transformContract(contract);
|
|
3726
|
+
} catch (cause) {
|
|
3727
|
+
throw new Error(`Couldn't get account info from chain or Tabularium`, { cause });
|
|
3576
3728
|
}
|
|
3577
|
-
return this.decodeStreamAccount(migrated[0].pubkey, migrated[0].account.data);
|
|
3578
3729
|
}
|
|
3579
3730
|
async decodeStreamAccount(pubkey, data) {
|
|
3580
3731
|
const stream = decodeStream(data);
|
|
3581
|
-
const metadataKey =
|
|
3732
|
+
const metadataKey = getMetadataKey(pubkey, stream.oldMetadata);
|
|
3582
3733
|
if (this.isAlignedUnlock(pubkey, stream.sender, stream.oldMetadata)) {
|
|
3583
3734
|
const alignedProxy = await this.alignedProxyProgram.account.contract.fetch(
|
|
3584
3735
|
deriveContractPDA(this.alignedProxyProgram.programId, metadataKey)
|
|
@@ -3586,9 +3737,9 @@ var SolanaStreamClient = class {
|
|
|
3586
3737
|
if (!alignedProxy) {
|
|
3587
3738
|
throw new Error("Couldn't get proxy account info.");
|
|
3588
3739
|
}
|
|
3589
|
-
return new AlignedContract(stream,
|
|
3740
|
+
return new AlignedContract(stream, alignedProxy);
|
|
3590
3741
|
}
|
|
3591
|
-
return new Contract(stream
|
|
3742
|
+
return new Contract(stream);
|
|
3592
3743
|
}
|
|
3593
3744
|
/**
|
|
3594
3745
|
* Fetch all aligned outgoing streams/contracts by the provided public key.
|
|
@@ -3613,7 +3764,7 @@ var SolanaStreamClient = class {
|
|
|
3613
3764
|
streamAccounts.forEach((account, index) => {
|
|
3614
3765
|
if (account) {
|
|
3615
3766
|
const alignedData = alignedOutgoingProgramAccounts[index].account;
|
|
3616
|
-
streams[streamPubKeys[index].toBase58()] = new AlignedContract(decodeStream(account.data),
|
|
3767
|
+
streams[streamPubKeys[index].toBase58()] = new AlignedContract(decodeStream(account.data), alignedData);
|
|
3617
3768
|
}
|
|
3618
3769
|
});
|
|
3619
3770
|
return streams;
|
|
@@ -3623,7 +3774,7 @@ var SolanaStreamClient = class {
|
|
|
3623
3774
|
const alignedStreamsPubKeys = Object.keys(streamRecord);
|
|
3624
3775
|
const alignedProxyPDAs = alignedStreamsPubKeys.map((streamPubKey) => {
|
|
3625
3776
|
const pubkey = new PublicKey(streamPubKey);
|
|
3626
|
-
const metadataKey =
|
|
3777
|
+
const metadataKey = getMetadataKey(pubkey, streamRecord[streamPubKey].oldMetadata);
|
|
3627
3778
|
return deriveContractPDA(this.alignedProxyProgram.programId, metadataKey);
|
|
3628
3779
|
});
|
|
3629
3780
|
const alignedProxyAccounts = await getMultipleAccountsInfoBatched(this.connection, alignedProxyPDAs);
|
|
@@ -3632,7 +3783,6 @@ var SolanaStreamClient = class {
|
|
|
3632
3783
|
const alignedData = streamRecord[alignedStreamsPubKeys[index]];
|
|
3633
3784
|
streams[alignedStreamsPubKeys[index]] = new AlignedContract(
|
|
3634
3785
|
alignedData,
|
|
3635
|
-
pk(alignedStreamsPubKeys[index]),
|
|
3636
3786
|
this.alignedProxyProgram.account.contract.coder.accounts.decode("contract", account.data)
|
|
3637
3787
|
);
|
|
3638
3788
|
}
|
|
@@ -3648,7 +3798,8 @@ var SolanaStreamClient = class {
|
|
|
3648
3798
|
async get({
|
|
3649
3799
|
address,
|
|
3650
3800
|
type = "all" /* All */,
|
|
3651
|
-
direction = "all" /* All
|
|
3801
|
+
direction = "all" /* All */,
|
|
3802
|
+
filters
|
|
3652
3803
|
}) {
|
|
3653
3804
|
const publicKey = new PublicKey(address);
|
|
3654
3805
|
let streams = {};
|
|
@@ -3661,7 +3812,7 @@ var SolanaStreamClient = class {
|
|
|
3661
3812
|
this.programId
|
|
3662
3813
|
);
|
|
3663
3814
|
outgoingStreamAccounts.forEach((account) => {
|
|
3664
|
-
streams[account.pubkey.toBase58()] = new Contract(decodeStream(account.account.data)
|
|
3815
|
+
streams[account.pubkey.toBase58()] = new Contract(decodeStream(account.account.data));
|
|
3665
3816
|
});
|
|
3666
3817
|
if (shouldFetchAligned) {
|
|
3667
3818
|
const alignedStreams = await this.getOutgoingAlignedStreams(address);
|
|
@@ -3681,7 +3832,7 @@ var SolanaStreamClient = class {
|
|
|
3681
3832
|
if (this.isAlignedUnlock(account.pubkey, allIncomingStreams[index].sender, allIncomingStreams[index].oldMetadata)) {
|
|
3682
3833
|
alignedDecoded[account.pubkey.toBase58()] = allIncomingStreams[index];
|
|
3683
3834
|
} else {
|
|
3684
|
-
streams[account.pubkey.toBase58()] = new Contract(allIncomingStreams[index]
|
|
3835
|
+
streams[account.pubkey.toBase58()] = new Contract(allIncomingStreams[index]);
|
|
3685
3836
|
}
|
|
3686
3837
|
});
|
|
3687
3838
|
if (shouldFetchAligned) {
|
|
@@ -3689,6 +3840,10 @@ var SolanaStreamClient = class {
|
|
|
3689
3840
|
streams = { ...streams, ...incomingAlignedStreams };
|
|
3690
3841
|
}
|
|
3691
3842
|
}
|
|
3843
|
+
if (filters?.closed) {
|
|
3844
|
+
const closedStreams = await this.getClosedStreams(address, direction);
|
|
3845
|
+
streams = { ...streams, ...closedStreams };
|
|
3846
|
+
}
|
|
3692
3847
|
const sortedStreams = Object.entries(streams).sort(([, stream1], [, stream2]) => stream2.start - stream1.start);
|
|
3693
3848
|
if (type === "all" /* All */) return sortedStreams;
|
|
3694
3849
|
return sortedStreams.filter((stream) => stream[1].type === type);
|
|
@@ -3724,7 +3879,7 @@ var SolanaStreamClient = class {
|
|
|
3724
3879
|
const entries = [];
|
|
3725
3880
|
decoded.forEach(({ pubkey, stream }, index) => {
|
|
3726
3881
|
if (this.isAlignedUnlock(pubkey, stream.sender, stream.oldMetadata)) {
|
|
3727
|
-
const metadataKey =
|
|
3882
|
+
const metadataKey = getMetadataKey(pubkey, stream.oldMetadata);
|
|
3728
3883
|
entries.push({ index, pda: deriveContractPDA(this.alignedProxyProgram.programId, metadataKey) });
|
|
3729
3884
|
}
|
|
3730
3885
|
});
|
|
@@ -3741,9 +3896,9 @@ var SolanaStreamClient = class {
|
|
|
3741
3896
|
if (alignedIdx !== -1) {
|
|
3742
3897
|
const alignedProxy = alignedProxies[alignedIdx];
|
|
3743
3898
|
invariant(alignedProxy, "Couldn't get aligned proxy account info");
|
|
3744
|
-
return { publicKey: pubkey, account: new AlignedContract(stream,
|
|
3899
|
+
return { publicKey: pubkey, account: new AlignedContract(stream, alignedProxy) };
|
|
3745
3900
|
}
|
|
3746
|
-
return { publicKey: pubkey, account: new Contract(stream
|
|
3901
|
+
return { publicKey: pubkey, account: new Contract(stream) };
|
|
3747
3902
|
});
|
|
3748
3903
|
}
|
|
3749
3904
|
/**
|
|
@@ -3881,7 +4036,7 @@ var SolanaStreamClient = class {
|
|
|
3881
4036
|
* For migrated streams, the PDA was derived from the old metadata key.
|
|
3882
4037
|
*/
|
|
3883
4038
|
isAlignedUnlock(streamPublicKey, senderPublicKey, oldMetadata) {
|
|
3884
|
-
const metadataKey = oldMetadata ?
|
|
4039
|
+
const metadataKey = oldMetadata ? getMetadataKey(streamPublicKey, oldMetadata) : streamPublicKey;
|
|
3885
4040
|
const pda = deriveContractPDA(this.alignedProxyProgram.programId, metadataKey);
|
|
3886
4041
|
return senderPublicKey.equals(pda);
|
|
3887
4042
|
}
|
|
@@ -3900,6 +4055,40 @@ var SolanaStreamClient = class {
|
|
|
3900
4055
|
)
|
|
3901
4056
|
};
|
|
3902
4057
|
}
|
|
4058
|
+
/**
|
|
4059
|
+
* Gets closed streams for a given owner and direction
|
|
4060
|
+
* @param owner - Owner address
|
|
4061
|
+
* @param direction - Stream direction
|
|
4062
|
+
* @returns Record of closed streams
|
|
4063
|
+
*/
|
|
4064
|
+
async getClosedStreams(owner, direction = "all" /* All */) {
|
|
4065
|
+
const streams = {};
|
|
4066
|
+
try {
|
|
4067
|
+
const tabulariumContracts = await this.apiClient.getContracts({
|
|
4068
|
+
sender: direction !== "incoming" /* Incoming */ ? owner : void 0,
|
|
4069
|
+
recipient: direction !== "outgoing" /* Outgoing */ ? owner : void 0
|
|
4070
|
+
});
|
|
4071
|
+
for (const contract of tabulariumContracts) {
|
|
4072
|
+
if (!streams[contract.address]) {
|
|
4073
|
+
try {
|
|
4074
|
+
const transformed = await transformContract(contract);
|
|
4075
|
+
streams[contract.address] = transformed;
|
|
4076
|
+
} catch (cause) {
|
|
4077
|
+
if (isDev) {
|
|
4078
|
+
throw new Error(`Failed to transform contract ${contract.address}:`, { cause });
|
|
4079
|
+
}
|
|
4080
|
+
console.warn(new Error(`Failed to transform contract ${contract.address}:`, { cause }));
|
|
4081
|
+
}
|
|
4082
|
+
}
|
|
4083
|
+
}
|
|
4084
|
+
} catch (cause) {
|
|
4085
|
+
if (isDev) {
|
|
4086
|
+
throw new Error("Failed to get data from the service", { cause });
|
|
4087
|
+
}
|
|
4088
|
+
console.warn(new Error("Failed to get data from the service", { cause }));
|
|
4089
|
+
}
|
|
4090
|
+
return streams;
|
|
4091
|
+
}
|
|
3903
4092
|
/**
|
|
3904
4093
|
* Utility function to generate metadata for a Contract or return existing Pubkey
|
|
3905
4094
|
*/
|
|
@@ -4359,6 +4548,6 @@ var timelockIDL_default = {
|
|
|
4359
4548
|
]
|
|
4360
4549
|
};
|
|
4361
4550
|
|
|
4362
|
-
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, 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, deriveTestOraclePDA, extractSolanaErrorCode,
|
|
4551
|
+
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, createClient, 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, transformContract, updateStreamInstruction, withdrawStreamInstruction };
|
|
4363
4552
|
//# sourceMappingURL=index.js.map
|
|
4364
4553
|
//# sourceMappingURL=index.js.map
|