@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/cjs/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, Account, AlignedContract, AlignedProxyErrorCode, AlignedStream, AlignedStreamData, AlignedUnlocksContract, BatchItem, BatchItemError, BatchItemResult, BatchItemSuccess, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, ChangeOracleParams, ClientCreationOptions, Contract, ContractErrorCode, CreateParams, CreateTestOracleParams, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, DecodedStream, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, IAlignedStreamConfig, IBaseStreamConfig, ICancelData, ICreateAlignedStreamData, ICreateExt, ICreateLinearStreamData, ICreateMultiError, ICreateMultipleAlignedStreamData, ICreateMultipleLinearStreamData, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, ICreateStreamExt, ICreateStreamInstructions, IFees, IGetAllData, IGetFeesData, IGetOneData, IInteractData, IInteractStreamExt, IMultiTransactionResult, IPrepareCreateStreamExt, IPrepareStreamExt, IRecipient, ISearchStreams, ITopUpData, ITopUpStreamExt, ITransactionExtWithInstructions, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, InstructionGenerator, LinearStream, MAX_SAFE_UNIX_TIME_VALUE, MetadataRecipientHashMap, ORIGINAL_CONTRACT_SENDER_OFFSET, OracleType, OracleTypeName, 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, Stream, StreamClientOptions, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, TestOracle, TransactionSchedulingOptions, UpdateTestOracleParams, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createStreamInstruction, createUncheckedStreamInstruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveTestOraclePDA, extractSolanaErrorCode,
|
|
1
|
+
export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, Account, AlignedContract, AlignedProxyErrorCode, AlignedStream, AlignedStreamData, AlignedUnlocksContract, ApiClient, ApiClientOptions, BatchItem, BatchItemError, BatchItemResult, BatchItemSuccess, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Chain, ChangeOracleParams, ClientCreationOptions, Contract, ContractErrorCode, ContractSchema, ContractType, CreateParams, CreateTestOracleParams, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, DecodedStream, DynamicContractSchema, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, GetContractsOptions, IAlignedStreamConfig, IBaseStreamConfig, ICancelData, ICreateAlignedStreamData, ICreateExt, ICreateLinearStreamData, ICreateMultiError, ICreateMultipleAlignedStreamData, ICreateMultipleLinearStreamData, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, ICreateStreamExt, ICreateStreamInstructions, IFees, IGetAllData, IGetFeesData, IGetOneData, IInteractData, IInteractStreamExt, IMultiTransactionResult, IPrepareCreateStreamExt, IPrepareStreamExt, IRecipient, ISearchStreams, ITopUpData, ITopUpStreamExt, ITransactionExtWithInstructions, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, InstructionGenerator, LinearStream, MAX_SAFE_UNIX_TIME_VALUE, MetadataRecipientHashMap, ORIGINAL_CONTRACT_SENDER_OFFSET, OracleType, OracleTypeName, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, PriceOracleType, 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, Stream, StreamClientOptions, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, TabulariumContract, TestOracle, TransactionSchedulingOptions, UpdateTestOracleParams, 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, topupStreamInstruction, transferStreamInstruction, transformContract, updateStreamInstruction, withdrawStreamInstruction } from './solana/index.cjs';
|
|
2
2
|
export { ContractError, ICluster, getBN, getNumberFromBN } from '@streamflow/common';
|
|
3
3
|
import 'p-queue';
|
|
4
4
|
import '@solana/web3.js';
|
|
@@ -142,7 +142,7 @@ var AlignedProxyErrorCode = /* @__PURE__ */ ((AlignedProxyErrorCode2) => {
|
|
|
142
142
|
return AlignedProxyErrorCode2;
|
|
143
143
|
})(AlignedProxyErrorCode || {});
|
|
144
144
|
var Contract = class {
|
|
145
|
-
constructor(stream
|
|
145
|
+
constructor(stream) {
|
|
146
146
|
this.magic = stream.magic.toNumber();
|
|
147
147
|
this.version = stream.version.toNumber();
|
|
148
148
|
this.createdAt = stream.createdAt.toNumber();
|
|
@@ -186,7 +186,6 @@ var Contract = class {
|
|
|
186
186
|
this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
|
|
187
187
|
this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
|
|
188
188
|
this.oldMetadata = stream.oldMetadata;
|
|
189
|
-
this.metadata = metadata;
|
|
190
189
|
this.type = buildStreamType(this);
|
|
191
190
|
this.isAligned = false;
|
|
192
191
|
}
|
|
@@ -201,8 +200,8 @@ var Contract = class {
|
|
|
201
200
|
}
|
|
202
201
|
};
|
|
203
202
|
var AlignedContract = class extends Contract {
|
|
204
|
-
constructor(stream,
|
|
205
|
-
super(stream
|
|
203
|
+
constructor(stream, alignedProxy) {
|
|
204
|
+
super(stream);
|
|
206
205
|
this.minPrice = common.getNumberFromBN(alignedProxy.minPrice, ALIGNED_PRECISION_FACTOR_POW);
|
|
207
206
|
this.maxPrice = common.getNumberFromBN(alignedProxy.maxPrice, ALIGNED_PRECISION_FACTOR_POW);
|
|
208
207
|
this.minPercentage = common.getNumberFromBN(alignedProxy.minPercentage, ALIGNED_PRECISION_FACTOR_POW);
|
|
@@ -272,6 +271,7 @@ var TEST_ORACLE_DISCRIMINATOR = [198, 49, 63, 134, 232, 251, 168, 28];
|
|
|
272
271
|
var CONTRACT_SEED = buffer.Buffer.from("contract", "utf-8");
|
|
273
272
|
var ESCROW_SEED = buffer.Buffer.from("strm", "utf-8");
|
|
274
273
|
var TEST_ORACLE_SEED = buffer.Buffer.from("test-oracle", "utf-8");
|
|
274
|
+
var REPOPULATED_METADATA_SEED = buffer.Buffer.from("strm-rep", "utf-8");
|
|
275
275
|
var STREAMFLOW_TREASURY_PUBLIC_KEY = new web3_js.PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
|
|
276
276
|
var WITHDRAWOR = "wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u";
|
|
277
277
|
var WITHDRAWOR_PUBLIC_KEY = new web3_js.PublicKey(WITHDRAWOR);
|
|
@@ -496,7 +496,7 @@ var encodeUpdateStream = (values, data) => {
|
|
|
496
496
|
var topupStreamLayout = BufferLayout__namespace.struct([
|
|
497
497
|
BufferLayout__namespace.blob(8, "amount")
|
|
498
498
|
]);
|
|
499
|
-
var
|
|
499
|
+
var getMetadataKey = (streamPubkey, oldMetadata) => {
|
|
500
500
|
if (web3_js.PublicKey.default.equals(oldMetadata)) {
|
|
501
501
|
return streamPubkey;
|
|
502
502
|
}
|
|
@@ -2539,6 +2539,149 @@ var deriveEscrowPDA = (programId, streamMetadata) => {
|
|
|
2539
2539
|
var deriveTestOraclePDA = (programId, mint, creator) => {
|
|
2540
2540
|
return web3_js.PublicKey.findProgramAddressSync([TEST_ORACLE_SEED, mint.toBuffer(), creator.toBuffer()], programId)[0];
|
|
2541
2541
|
};
|
|
2542
|
+
var deriveRepopulatedMetadataPDA = (programId, streamMetadata) => {
|
|
2543
|
+
return web3_js.PublicKey.findProgramAddressSync([REPOPULATED_METADATA_SEED, streamMetadata.toBuffer()], programId)[0];
|
|
2544
|
+
};
|
|
2545
|
+
|
|
2546
|
+
// solana/api-public/client.ts
|
|
2547
|
+
var DEFAULT_API_URL = "https://api-public.streamflow.finance";
|
|
2548
|
+
var DEFAULT_DEVNET_API_URL = "https://api-public-staging.streamflow.finance";
|
|
2549
|
+
var createClient = (options) => {
|
|
2550
|
+
const apiUrl = options?.apiUrl ?? options?.cluster === "mainnet" ? DEFAULT_API_URL : DEFAULT_DEVNET_API_URL;
|
|
2551
|
+
const fetchFn = options?.fetchFn ?? fetch;
|
|
2552
|
+
const fetchResource = async (url, options2) => {
|
|
2553
|
+
const res = await fetchFn(url, {
|
|
2554
|
+
method: "GET",
|
|
2555
|
+
headers: { "Content-Type": "application/json" },
|
|
2556
|
+
...{}
|
|
2557
|
+
});
|
|
2558
|
+
if (!res.ok) {
|
|
2559
|
+
const text = await res.text().catch(() => "");
|
|
2560
|
+
throw new Error(`Tabularium API error`, {
|
|
2561
|
+
cause: new Error(`: ${res.status} ${res.statusText}${text ? ` - ${text}` : ""}`)
|
|
2562
|
+
});
|
|
2563
|
+
}
|
|
2564
|
+
return res.json();
|
|
2565
|
+
};
|
|
2566
|
+
return {
|
|
2567
|
+
getContracts: async (opts) => {
|
|
2568
|
+
const params = new URLSearchParams();
|
|
2569
|
+
if (opts?.sender) params.set("sender", opts.sender);
|
|
2570
|
+
if (opts?.recipient) params.set("recipient", opts.recipient);
|
|
2571
|
+
const url = `${apiUrl}/v2/api/contracts/tabularium/${params.toString() ? `?${params.toString()}` : ""}`;
|
|
2572
|
+
return fetchResource(url);
|
|
2573
|
+
},
|
|
2574
|
+
getContract: async (address) => {
|
|
2575
|
+
const url = `${apiUrl}/v2/api/contracts/tabularium/${encodeURIComponent(address)}`;
|
|
2576
|
+
return fetchResource(url);
|
|
2577
|
+
}
|
|
2578
|
+
};
|
|
2579
|
+
};
|
|
2580
|
+
var isoToUnix = (iso) => {
|
|
2581
|
+
if (!iso) return 0;
|
|
2582
|
+
const time = new Date(iso).getTime();
|
|
2583
|
+
return Number.isNaN(time) ? 0 : Math.floor(time / 1e3);
|
|
2584
|
+
};
|
|
2585
|
+
var toBN = (value) => new BN3__default.default(value);
|
|
2586
|
+
var mapOracleType = (apiType) => {
|
|
2587
|
+
if (!apiType) return { none: {} };
|
|
2588
|
+
const mapping = {
|
|
2589
|
+
TEST: { test: {} },
|
|
2590
|
+
PYTH: { pyth: {} },
|
|
2591
|
+
SWITCHBOARD: { switchboard: {} }
|
|
2592
|
+
};
|
|
2593
|
+
return mapping[apiType] ?? { none: {} };
|
|
2594
|
+
};
|
|
2595
|
+
async function toDecodedStream(schema) {
|
|
2596
|
+
const mint = common.pk(schema.mint);
|
|
2597
|
+
const sender = common.pk(schema.sender);
|
|
2598
|
+
const recipient = common.pk(schema.recipient);
|
|
2599
|
+
const partner = schema.partner ? common.pk(schema.partner) : sender;
|
|
2600
|
+
const [senderTokens, recipientTokens, partnerTokens, streamflowTreasuryTokens] = await Promise.all([
|
|
2601
|
+
common.ata(mint, sender),
|
|
2602
|
+
common.ata(mint, recipient),
|
|
2603
|
+
common.ata(mint, partner),
|
|
2604
|
+
common.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY)
|
|
2605
|
+
]);
|
|
2606
|
+
return {
|
|
2607
|
+
magic: toBN(4),
|
|
2608
|
+
version: toBN(4),
|
|
2609
|
+
createdAt: toBN(isoToUnix(schema.createdDt)),
|
|
2610
|
+
withdrawnAmount: toBN(schema.claimedAmount),
|
|
2611
|
+
canceledAt: toBN(isoToUnix(schema.canceledDt)),
|
|
2612
|
+
end: toBN(isoToUnix(schema.endDt)),
|
|
2613
|
+
lastWithdrawnAt: toBN(isoToUnix(schema.lastClaimedDt)),
|
|
2614
|
+
sender,
|
|
2615
|
+
senderTokens,
|
|
2616
|
+
recipient,
|
|
2617
|
+
recipientTokens,
|
|
2618
|
+
mint,
|
|
2619
|
+
escrowTokens: schema.escrow ? common.pk(schema.escrow) : web3_js.PublicKey.default,
|
|
2620
|
+
streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
2621
|
+
streamflowTreasuryTokens,
|
|
2622
|
+
streamflowFeeTotal: toBN(schema.streamflowFee),
|
|
2623
|
+
streamflowFeeWithdrawn: toBN(schema.streamflowFeeWithdrawn),
|
|
2624
|
+
streamflowFeePercent: parseFloat(schema.streamflowFeePercentage) || 0,
|
|
2625
|
+
partnerFeeTotal: toBN(schema.partnerFee),
|
|
2626
|
+
partnerFeeWithdrawn: toBN(schema.partnerFeeWithdrawn),
|
|
2627
|
+
partnerFeePercent: parseFloat(schema.partnerFeePercentage) || 0,
|
|
2628
|
+
partner,
|
|
2629
|
+
partnerTokens,
|
|
2630
|
+
start: toBN(isoToUnix(schema.startDt)),
|
|
2631
|
+
depositedAmount: toBN(schema.amount),
|
|
2632
|
+
period: toBN(schema.period),
|
|
2633
|
+
amountPerPeriod: toBN(schema.amountPerPeriod),
|
|
2634
|
+
cliff: toBN(isoToUnix(schema.startDt)),
|
|
2635
|
+
cliffAmount: toBN(schema.cliffAmount),
|
|
2636
|
+
cancelableBySender: schema.isCancelableBySender,
|
|
2637
|
+
cancelableByRecipient: schema.isCancelableByRecipient,
|
|
2638
|
+
automaticWithdrawal: schema.hasAutoClaim,
|
|
2639
|
+
transferableBySender: schema.isTransferableBySender,
|
|
2640
|
+
transferableByRecipient: schema.isTransferableByRecipient,
|
|
2641
|
+
canTopup: schema.canTopup,
|
|
2642
|
+
name: schema.name,
|
|
2643
|
+
withdrawFrequency: toBN(schema.autoClaimPeriod),
|
|
2644
|
+
closed: schema.isClosed,
|
|
2645
|
+
currentPauseStart: toBN(0),
|
|
2646
|
+
pauseCumulative: toBN(schema.pauseCumulative),
|
|
2647
|
+
lastRateChangeTime: toBN(isoToUnix(schema.lastRateUpdateDt)),
|
|
2648
|
+
fundsUnlockedAtLastRateChange: toBN(schema.amountUnlockedAtLastRateUpdate),
|
|
2649
|
+
oldMetadata: web3_js.PublicKey.default
|
|
2650
|
+
};
|
|
2651
|
+
}
|
|
2652
|
+
function toPrecisionBN(value, precision = ALIGNED_PRECISION_FACTOR_POW2) {
|
|
2653
|
+
return common.getBN(typeof value === "number" ? value : parseFloat(value), precision);
|
|
2654
|
+
}
|
|
2655
|
+
function toAlignedProxy(dynamic) {
|
|
2656
|
+
const proxy = {
|
|
2657
|
+
sender: common.pk(dynamic.sender),
|
|
2658
|
+
minPrice: toPrecisionBN(dynamic.minPrice),
|
|
2659
|
+
maxPrice: toPrecisionBN(dynamic.maxPrice),
|
|
2660
|
+
minPercentage: toPrecisionBN(dynamic.minPercentage),
|
|
2661
|
+
maxPercentage: toPrecisionBN(dynamic.maxPercentage),
|
|
2662
|
+
priceOracleType: mapOracleType(dynamic.priceOracleType),
|
|
2663
|
+
priceOracle: dynamic.priceOracleAddress ? common.pk(dynamic.priceOracleAddress) : web3_js.PublicKey.default,
|
|
2664
|
+
tickSize: toPrecisionBN(dynamic.tickSize),
|
|
2665
|
+
initialAmountPerPeriod: toBN(dynamic.initialAmountPerPeriod),
|
|
2666
|
+
initialPrice: toPrecisionBN(dynamic.initialPrice),
|
|
2667
|
+
lastPrice: toPrecisionBN(dynamic.lastPrice),
|
|
2668
|
+
lastAmountUpdateTime: toBN(isoToUnix(dynamic.expiryDt)),
|
|
2669
|
+
initialNetAmount: toBN(dynamic.initialAmount),
|
|
2670
|
+
expiryTime: toBN(isoToUnix(dynamic.expiryDt)),
|
|
2671
|
+
expiryPercentage: toPrecisionBN(dynamic.expiryPercentage),
|
|
2672
|
+
floorPrice: toPrecisionBN(dynamic.floorPrice),
|
|
2673
|
+
streamCanceledTime: dynamic.streamCanceledTime ? toBN(dynamic.streamCanceledTime) : toBN(0)
|
|
2674
|
+
};
|
|
2675
|
+
return proxy;
|
|
2676
|
+
}
|
|
2677
|
+
var transformContract = async (schema) => {
|
|
2678
|
+
const decodedStream = await toDecodedStream(schema);
|
|
2679
|
+
if (schema.dynamicContract) {
|
|
2680
|
+
const alignedProxy = toAlignedProxy(schema.dynamicContract);
|
|
2681
|
+
return new AlignedContract(decodedStream, alignedProxy);
|
|
2682
|
+
}
|
|
2683
|
+
return new Contract(decodedStream);
|
|
2684
|
+
};
|
|
2542
2685
|
|
|
2543
2686
|
// solana/StreamClient.ts
|
|
2544
2687
|
var METADATA_ACC_SIZE = 1104;
|
|
@@ -2582,6 +2725,9 @@ var SolanaStreamClient = class {
|
|
|
2582
2725
|
address: streamflow_aligned_unlocks_default.address
|
|
2583
2726
|
};
|
|
2584
2727
|
this.alignedProxyProgram = new anchor.Program(alignedUnlocksProgram, { connection: this.connection });
|
|
2728
|
+
this.apiClient = createClient(
|
|
2729
|
+
typeof optionsOrClusterUrl === "object" && optionsOrClusterUrl.cluster !== common.ICluster.Mainnet ? { cluster: "devnet" } : { cluster: "mainnet" }
|
|
2730
|
+
);
|
|
2585
2731
|
}
|
|
2586
2732
|
getConnection() {
|
|
2587
2733
|
return this.connection;
|
|
@@ -3597,14 +3743,19 @@ var SolanaStreamClient = class {
|
|
|
3597
3743
|
}
|
|
3598
3744
|
]
|
|
3599
3745
|
});
|
|
3600
|
-
if (migrated.length
|
|
3601
|
-
|
|
3746
|
+
if (migrated.length > 0) {
|
|
3747
|
+
return this.decodeStreamAccount(migrated[0].pubkey, migrated[0].account.data);
|
|
3748
|
+
}
|
|
3749
|
+
try {
|
|
3750
|
+
const contract = await this.apiClient.getContract(id);
|
|
3751
|
+
return await transformContract(contract);
|
|
3752
|
+
} catch (cause) {
|
|
3753
|
+
throw new Error(`Couldn't get account info from chain or Tabularium`, { cause });
|
|
3602
3754
|
}
|
|
3603
|
-
return this.decodeStreamAccount(migrated[0].pubkey, migrated[0].account.data);
|
|
3604
3755
|
}
|
|
3605
3756
|
async decodeStreamAccount(pubkey, data) {
|
|
3606
3757
|
const stream = decodeStream(data);
|
|
3607
|
-
const metadataKey =
|
|
3758
|
+
const metadataKey = getMetadataKey(pubkey, stream.oldMetadata);
|
|
3608
3759
|
if (this.isAlignedUnlock(pubkey, stream.sender, stream.oldMetadata)) {
|
|
3609
3760
|
const alignedProxy = await this.alignedProxyProgram.account.contract.fetch(
|
|
3610
3761
|
deriveContractPDA(this.alignedProxyProgram.programId, metadataKey)
|
|
@@ -3612,9 +3763,9 @@ var SolanaStreamClient = class {
|
|
|
3612
3763
|
if (!alignedProxy) {
|
|
3613
3764
|
throw new Error("Couldn't get proxy account info.");
|
|
3614
3765
|
}
|
|
3615
|
-
return new AlignedContract(stream,
|
|
3766
|
+
return new AlignedContract(stream, alignedProxy);
|
|
3616
3767
|
}
|
|
3617
|
-
return new Contract(stream
|
|
3768
|
+
return new Contract(stream);
|
|
3618
3769
|
}
|
|
3619
3770
|
/**
|
|
3620
3771
|
* Fetch all aligned outgoing streams/contracts by the provided public key.
|
|
@@ -3639,7 +3790,7 @@ var SolanaStreamClient = class {
|
|
|
3639
3790
|
streamAccounts.forEach((account, index) => {
|
|
3640
3791
|
if (account) {
|
|
3641
3792
|
const alignedData = alignedOutgoingProgramAccounts[index].account;
|
|
3642
|
-
streams[streamPubKeys[index].toBase58()] = new AlignedContract(decodeStream(account.data),
|
|
3793
|
+
streams[streamPubKeys[index].toBase58()] = new AlignedContract(decodeStream(account.data), alignedData);
|
|
3643
3794
|
}
|
|
3644
3795
|
});
|
|
3645
3796
|
return streams;
|
|
@@ -3649,7 +3800,7 @@ var SolanaStreamClient = class {
|
|
|
3649
3800
|
const alignedStreamsPubKeys = Object.keys(streamRecord);
|
|
3650
3801
|
const alignedProxyPDAs = alignedStreamsPubKeys.map((streamPubKey) => {
|
|
3651
3802
|
const pubkey = new web3_js.PublicKey(streamPubKey);
|
|
3652
|
-
const metadataKey =
|
|
3803
|
+
const metadataKey = getMetadataKey(pubkey, streamRecord[streamPubKey].oldMetadata);
|
|
3653
3804
|
return deriveContractPDA(this.alignedProxyProgram.programId, metadataKey);
|
|
3654
3805
|
});
|
|
3655
3806
|
const alignedProxyAccounts = await common.getMultipleAccountsInfoBatched(this.connection, alignedProxyPDAs);
|
|
@@ -3658,7 +3809,6 @@ var SolanaStreamClient = class {
|
|
|
3658
3809
|
const alignedData = streamRecord[alignedStreamsPubKeys[index]];
|
|
3659
3810
|
streams[alignedStreamsPubKeys[index]] = new AlignedContract(
|
|
3660
3811
|
alignedData,
|
|
3661
|
-
common.pk(alignedStreamsPubKeys[index]),
|
|
3662
3812
|
this.alignedProxyProgram.account.contract.coder.accounts.decode("contract", account.data)
|
|
3663
3813
|
);
|
|
3664
3814
|
}
|
|
@@ -3674,7 +3824,8 @@ var SolanaStreamClient = class {
|
|
|
3674
3824
|
async get({
|
|
3675
3825
|
address,
|
|
3676
3826
|
type = "all" /* All */,
|
|
3677
|
-
direction = "all" /* All
|
|
3827
|
+
direction = "all" /* All */,
|
|
3828
|
+
filters
|
|
3678
3829
|
}) {
|
|
3679
3830
|
const publicKey = new web3_js.PublicKey(address);
|
|
3680
3831
|
let streams = {};
|
|
@@ -3687,7 +3838,7 @@ var SolanaStreamClient = class {
|
|
|
3687
3838
|
this.programId
|
|
3688
3839
|
);
|
|
3689
3840
|
outgoingStreamAccounts.forEach((account) => {
|
|
3690
|
-
streams[account.pubkey.toBase58()] = new Contract(decodeStream(account.account.data)
|
|
3841
|
+
streams[account.pubkey.toBase58()] = new Contract(decodeStream(account.account.data));
|
|
3691
3842
|
});
|
|
3692
3843
|
if (shouldFetchAligned) {
|
|
3693
3844
|
const alignedStreams = await this.getOutgoingAlignedStreams(address);
|
|
@@ -3707,7 +3858,7 @@ var SolanaStreamClient = class {
|
|
|
3707
3858
|
if (this.isAlignedUnlock(account.pubkey, allIncomingStreams[index].sender, allIncomingStreams[index].oldMetadata)) {
|
|
3708
3859
|
alignedDecoded[account.pubkey.toBase58()] = allIncomingStreams[index];
|
|
3709
3860
|
} else {
|
|
3710
|
-
streams[account.pubkey.toBase58()] = new Contract(allIncomingStreams[index]
|
|
3861
|
+
streams[account.pubkey.toBase58()] = new Contract(allIncomingStreams[index]);
|
|
3711
3862
|
}
|
|
3712
3863
|
});
|
|
3713
3864
|
if (shouldFetchAligned) {
|
|
@@ -3715,6 +3866,10 @@ var SolanaStreamClient = class {
|
|
|
3715
3866
|
streams = { ...streams, ...incomingAlignedStreams };
|
|
3716
3867
|
}
|
|
3717
3868
|
}
|
|
3869
|
+
if (filters?.closed) {
|
|
3870
|
+
const closedStreams = await this.getClosedStreams(address, direction);
|
|
3871
|
+
streams = { ...streams, ...closedStreams };
|
|
3872
|
+
}
|
|
3718
3873
|
const sortedStreams = Object.entries(streams).sort(([, stream1], [, stream2]) => stream2.start - stream1.start);
|
|
3719
3874
|
if (type === "all" /* All */) return sortedStreams;
|
|
3720
3875
|
return sortedStreams.filter((stream) => stream[1].type === type);
|
|
@@ -3750,7 +3905,7 @@ var SolanaStreamClient = class {
|
|
|
3750
3905
|
const entries = [];
|
|
3751
3906
|
decoded.forEach(({ pubkey, stream }, index) => {
|
|
3752
3907
|
if (this.isAlignedUnlock(pubkey, stream.sender, stream.oldMetadata)) {
|
|
3753
|
-
const metadataKey =
|
|
3908
|
+
const metadataKey = getMetadataKey(pubkey, stream.oldMetadata);
|
|
3754
3909
|
entries.push({ index, pda: deriveContractPDA(this.alignedProxyProgram.programId, metadataKey) });
|
|
3755
3910
|
}
|
|
3756
3911
|
});
|
|
@@ -3767,9 +3922,9 @@ var SolanaStreamClient = class {
|
|
|
3767
3922
|
if (alignedIdx !== -1) {
|
|
3768
3923
|
const alignedProxy = alignedProxies[alignedIdx];
|
|
3769
3924
|
common.invariant(alignedProxy, "Couldn't get aligned proxy account info");
|
|
3770
|
-
return { publicKey: pubkey, account: new AlignedContract(stream,
|
|
3925
|
+
return { publicKey: pubkey, account: new AlignedContract(stream, alignedProxy) };
|
|
3771
3926
|
}
|
|
3772
|
-
return { publicKey: pubkey, account: new Contract(stream
|
|
3927
|
+
return { publicKey: pubkey, account: new Contract(stream) };
|
|
3773
3928
|
});
|
|
3774
3929
|
}
|
|
3775
3930
|
/**
|
|
@@ -3907,7 +4062,7 @@ var SolanaStreamClient = class {
|
|
|
3907
4062
|
* For migrated streams, the PDA was derived from the old metadata key.
|
|
3908
4063
|
*/
|
|
3909
4064
|
isAlignedUnlock(streamPublicKey, senderPublicKey, oldMetadata) {
|
|
3910
|
-
const metadataKey = oldMetadata ?
|
|
4065
|
+
const metadataKey = oldMetadata ? getMetadataKey(streamPublicKey, oldMetadata) : streamPublicKey;
|
|
3911
4066
|
const pda = deriveContractPDA(this.alignedProxyProgram.programId, metadataKey);
|
|
3912
4067
|
return senderPublicKey.equals(pda);
|
|
3913
4068
|
}
|
|
@@ -3926,6 +4081,40 @@ var SolanaStreamClient = class {
|
|
|
3926
4081
|
)
|
|
3927
4082
|
};
|
|
3928
4083
|
}
|
|
4084
|
+
/**
|
|
4085
|
+
* Gets closed streams for a given owner and direction
|
|
4086
|
+
* @param owner - Owner address
|
|
4087
|
+
* @param direction - Stream direction
|
|
4088
|
+
* @returns Record of closed streams
|
|
4089
|
+
*/
|
|
4090
|
+
async getClosedStreams(owner, direction = "all" /* All */) {
|
|
4091
|
+
const streams = {};
|
|
4092
|
+
try {
|
|
4093
|
+
const tabulariumContracts = await this.apiClient.getContracts({
|
|
4094
|
+
sender: direction !== "incoming" /* Incoming */ ? owner : void 0,
|
|
4095
|
+
recipient: direction !== "outgoing" /* Outgoing */ ? owner : void 0
|
|
4096
|
+
});
|
|
4097
|
+
for (const contract of tabulariumContracts) {
|
|
4098
|
+
if (!streams[contract.address]) {
|
|
4099
|
+
try {
|
|
4100
|
+
const transformed = await transformContract(contract);
|
|
4101
|
+
streams[contract.address] = transformed;
|
|
4102
|
+
} catch (cause) {
|
|
4103
|
+
if (common.isDev) {
|
|
4104
|
+
throw new Error(`Failed to transform contract ${contract.address}:`, { cause });
|
|
4105
|
+
}
|
|
4106
|
+
console.warn(new Error(`Failed to transform contract ${contract.address}:`, { cause }));
|
|
4107
|
+
}
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4110
|
+
} catch (cause) {
|
|
4111
|
+
if (common.isDev) {
|
|
4112
|
+
throw new Error("Failed to get data from the service", { cause });
|
|
4113
|
+
}
|
|
4114
|
+
console.warn(new Error("Failed to get data from the service", { cause }));
|
|
4115
|
+
}
|
|
4116
|
+
return streams;
|
|
4117
|
+
}
|
|
3929
4118
|
/**
|
|
3930
4119
|
* Utility function to generate metadata for a Contract or return existing Pubkey
|
|
3931
4120
|
*/
|
|
@@ -4425,6 +4614,7 @@ exports.PARTNERS_SCHEMA = PARTNERS_SCHEMA;
|
|
|
4425
4614
|
exports.PARTNER_ORACLE_PROGRAM_ID = PARTNER_ORACLE_PROGRAM_ID;
|
|
4426
4615
|
exports.PARTNER_SCHEMA = PARTNER_SCHEMA;
|
|
4427
4616
|
exports.PROGRAM_ID = PROGRAM_ID;
|
|
4617
|
+
exports.REPOPULATED_METADATA_SEED = REPOPULATED_METADATA_SEED;
|
|
4428
4618
|
exports.SOLANA_ERROR_MAP = SOLANA_ERROR_MAP;
|
|
4429
4619
|
exports.SOLANA_ERROR_MATCH_REGEX = SOLANA_ERROR_MATCH_REGEX;
|
|
4430
4620
|
exports.STREAMFLOW_TREASURY_PUBLIC_KEY = STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
@@ -4447,15 +4637,17 @@ exports.buildStreamType = buildStreamType;
|
|
|
4447
4637
|
exports.calculateTotalAmountToDeposit = calculateTotalAmountToDeposit;
|
|
4448
4638
|
exports.calculateUnlockedAmount = calculateUnlockedAmount;
|
|
4449
4639
|
exports.cancelStreamInstruction = cancelStreamInstruction;
|
|
4640
|
+
exports.createClient = createClient;
|
|
4450
4641
|
exports.createStreamInstruction = createStreamInstruction;
|
|
4451
4642
|
exports.createUncheckedStreamInstruction = createUncheckedStreamInstruction;
|
|
4452
4643
|
exports.decodeEndTime = decodeEndTime;
|
|
4453
4644
|
exports.decodeStream = decodeStream;
|
|
4454
4645
|
exports.deriveContractPDA = deriveContractPDA;
|
|
4455
4646
|
exports.deriveEscrowPDA = deriveEscrowPDA;
|
|
4647
|
+
exports.deriveRepopulatedMetadataPDA = deriveRepopulatedMetadataPDA;
|
|
4456
4648
|
exports.deriveTestOraclePDA = deriveTestOraclePDA;
|
|
4457
4649
|
exports.extractSolanaErrorCode = extractSolanaErrorCode;
|
|
4458
|
-
exports.
|
|
4650
|
+
exports.getMetadataKey = getMetadataKey;
|
|
4459
4651
|
exports.handleContractError = handleContractError;
|
|
4460
4652
|
exports.isAligned = isAligned;
|
|
4461
4653
|
exports.isCliffCloseToDepositedAmount = isCliffCloseToDepositedAmount;
|
|
@@ -4468,6 +4660,7 @@ exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
|
|
|
4468
4660
|
exports.timelockIDL = timelockIDL_default;
|
|
4469
4661
|
exports.topupStreamInstruction = topupStreamInstruction;
|
|
4470
4662
|
exports.transferStreamInstruction = transferStreamInstruction;
|
|
4663
|
+
exports.transformContract = transformContract;
|
|
4471
4664
|
exports.updateStreamInstruction = updateStreamInstruction;
|
|
4472
4665
|
exports.withdrawStreamInstruction = withdrawStreamInstruction;
|
|
4473
4666
|
//# sourceMappingURL=index.cjs.map
|