@streamflow/stream 11.0.3 → 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 +193 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/solana/index.cjs +193 -4
- package/dist/cjs/solana/index.cjs.map +1 -1
- package/dist/cjs/solana/index.d.cts +178 -2
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +193 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solana/index.d.ts +178 -2
- package/dist/esm/solana/index.js +193 -6
- package/dist/esm/solana/index.js.map +1 -1
- package/package.json +5 -4
package/dist/cjs/index.cjs
CHANGED
|
@@ -2543,6 +2543,146 @@ var deriveRepopulatedMetadataPDA = (programId, streamMetadata) => {
|
|
|
2543
2543
|
return web3_js.PublicKey.findProgramAddressSync([REPOPULATED_METADATA_SEED, streamMetadata.toBuffer()], programId)[0];
|
|
2544
2544
|
};
|
|
2545
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
|
+
};
|
|
2685
|
+
|
|
2546
2686
|
// solana/StreamClient.ts
|
|
2547
2687
|
var METADATA_ACC_SIZE = 1104;
|
|
2548
2688
|
var ALIGNED_METADATA_ACC_SIZE = 320;
|
|
@@ -2585,6 +2725,9 @@ var SolanaStreamClient = class {
|
|
|
2585
2725
|
address: streamflow_aligned_unlocks_default.address
|
|
2586
2726
|
};
|
|
2587
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
|
+
);
|
|
2588
2731
|
}
|
|
2589
2732
|
getConnection() {
|
|
2590
2733
|
return this.connection;
|
|
@@ -3600,10 +3743,15 @@ var SolanaStreamClient = class {
|
|
|
3600
3743
|
}
|
|
3601
3744
|
]
|
|
3602
3745
|
});
|
|
3603
|
-
if (migrated.length
|
|
3604
|
-
|
|
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 });
|
|
3605
3754
|
}
|
|
3606
|
-
return this.decodeStreamAccount(migrated[0].pubkey, migrated[0].account.data);
|
|
3607
3755
|
}
|
|
3608
3756
|
async decodeStreamAccount(pubkey, data) {
|
|
3609
3757
|
const stream = decodeStream(data);
|
|
@@ -3676,7 +3824,8 @@ var SolanaStreamClient = class {
|
|
|
3676
3824
|
async get({
|
|
3677
3825
|
address,
|
|
3678
3826
|
type = "all" /* All */,
|
|
3679
|
-
direction = "all" /* All
|
|
3827
|
+
direction = "all" /* All */,
|
|
3828
|
+
filters
|
|
3680
3829
|
}) {
|
|
3681
3830
|
const publicKey = new web3_js.PublicKey(address);
|
|
3682
3831
|
let streams = {};
|
|
@@ -3717,6 +3866,10 @@ var SolanaStreamClient = class {
|
|
|
3717
3866
|
streams = { ...streams, ...incomingAlignedStreams };
|
|
3718
3867
|
}
|
|
3719
3868
|
}
|
|
3869
|
+
if (filters?.closed) {
|
|
3870
|
+
const closedStreams = await this.getClosedStreams(address, direction);
|
|
3871
|
+
streams = { ...streams, ...closedStreams };
|
|
3872
|
+
}
|
|
3720
3873
|
const sortedStreams = Object.entries(streams).sort(([, stream1], [, stream2]) => stream2.start - stream1.start);
|
|
3721
3874
|
if (type === "all" /* All */) return sortedStreams;
|
|
3722
3875
|
return sortedStreams.filter((stream) => stream[1].type === type);
|
|
@@ -3928,6 +4081,40 @@ var SolanaStreamClient = class {
|
|
|
3928
4081
|
)
|
|
3929
4082
|
};
|
|
3930
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
|
+
}
|
|
3931
4118
|
/**
|
|
3932
4119
|
* Utility function to generate metadata for a Contract or return existing Pubkey
|
|
3933
4120
|
*/
|
|
@@ -4450,6 +4637,7 @@ exports.buildStreamType = buildStreamType;
|
|
|
4450
4637
|
exports.calculateTotalAmountToDeposit = calculateTotalAmountToDeposit;
|
|
4451
4638
|
exports.calculateUnlockedAmount = calculateUnlockedAmount;
|
|
4452
4639
|
exports.cancelStreamInstruction = cancelStreamInstruction;
|
|
4640
|
+
exports.createClient = createClient;
|
|
4453
4641
|
exports.createStreamInstruction = createStreamInstruction;
|
|
4454
4642
|
exports.createUncheckedStreamInstruction = createUncheckedStreamInstruction;
|
|
4455
4643
|
exports.decodeEndTime = decodeEndTime;
|
|
@@ -4472,6 +4660,7 @@ exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
|
|
|
4472
4660
|
exports.timelockIDL = timelockIDL_default;
|
|
4473
4661
|
exports.topupStreamInstruction = topupStreamInstruction;
|
|
4474
4662
|
exports.transferStreamInstruction = transferStreamInstruction;
|
|
4663
|
+
exports.transformContract = transformContract;
|
|
4475
4664
|
exports.updateStreamInstruction = updateStreamInstruction;
|
|
4476
4665
|
exports.withdrawStreamInstruction = withdrawStreamInstruction;
|
|
4477
4666
|
//# sourceMappingURL=index.cjs.map
|