@streamflow/stream 13.4.0 → 13.5.0
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-BqHEM38f.d.cts → index-BLL6w66C.d.cts} +10 -1
- package/dist/cjs/index.cjs +89 -25
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -2
- package/dist/cjs/solana/api/index.cjs +88 -25
- package/dist/cjs/solana/api/index.cjs.map +1 -1
- package/dist/cjs/solana/api/index.d.cts +1 -1
- package/dist/cjs/solana/index.cjs +89 -25
- package/dist/cjs/solana/index.cjs.map +1 -1
- package/dist/cjs/solana/index.d.cts +10 -3
- package/dist/esm/{index-CYAitoQO.d.ts → index-FDwxtRYV.d.ts} +10 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +90 -27
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solana/api/index.d.ts +1 -1
- package/dist/esm/solana/api/index.js +89 -26
- package/dist/esm/solana/api/index.js.map +1 -1
- package/dist/esm/solana/index.d.ts +10 -3
- package/dist/esm/solana/index.js +90 -27
- package/dist/esm/solana/index.js.map +1 -1
- package/package.json +4 -4
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, ApiClient, ApiClientOptions, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Chain, ContractSchema, ContractType, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, DynamicContractSchema, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, GetContractsOptions, MAX_SAFE_UNIX_TIME_VALUE, METADATA_SEED, ORIGINAL_CONTRACT_SENDER_OFFSET, 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, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, TabulariumContract, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, claimRoutedFeeStreamInstruction, createClient, createStreamInstruction, createStreamV2Instruction, createUncheckedStreamInstruction, createUncheckedStreamV2Instruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveRepopulatedMetadataPDA, deriveStreamMetadataPDA, deriveTestOraclePDA, encodeStreamName, encodeStreamNameAsArray, extractSolanaErrorCode, getMetadataKey, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL, topupStreamInstruction, transferStreamInstruction, transformContract, updateStreamInstruction, withdrawStreamInstruction } from './solana/index.cjs';
|
|
1
|
+
export { g as Account, h as AlignedContract, i as AlignedProxyErrorCode, A as AlignedStream, j as AlignedStreamData, k as AlignedUnlocksContract, l as BatchCreationItem, m as BatchExecuteResult, n as BatchInstructionResult, B as BatchItem, o as BatchItemError, a as BatchItemResult, p as BatchItemSuccess, q as BuildTransactionFn, r as BuildTransactionOptions, s as BuiltTransaction, C as CancelFn, t as ChangeOracleParams, u as ClientCreationOptions, v as Contract, w as ContractErrorCode, x as CreateBatchFn, y as CreateFn, z as CreateInstructionResult, E as CreateParams, F as CreateTestOracleParams, D as DecodedStream, G as Env, H as ExecuteBatchFn, J as ExecuteBatchSequentialFn, K as ExecuteFn, L as ExecutionEnv, M as IAlignedStreamConfig, N as IBaseStreamConfig, O as ICancelData, P as IClaimRoutedFeeData, d as ICreateAlignedStreamData, Q as ICreateExt, e as ICreateLinearStreamData, T as ICreateLockBatchParams, U as ICreateLockParams, V as ICreateMultiError, W as ICreateMultipleAlignedStreamData, X as ICreateMultipleLinearStreamData, Y as ICreateMultipleStreamData, Z as ICreateResult, c as ICreateStreamData, _ as ICreateStreamExt, $ as ICreateStreamInstructions, a0 as ICreateVestingBatchParams, a1 as ICreateVestingParams, a2 as IFees, a3 as IGetAllData, a4 as IGetFeesData, a5 as IGetOneData, a6 as IInteractData, a7 as IInteractStreamExt, a8 as ILockBatchRecipient, a9 as IMultiTransactionResult, aa as IPrepareCreateStreamExt, ab as IPrepareStreamExt, ac as IPrepareTopUpstreamExt, ad as IRecipient, f as ISearchStreams, ae as ITopUpData, af as ITopUpStreamExt, ag as ITransactionExtWithInstructions, ah as ITransactionResult, ai as ITransferData, I as IUpdateData, aj as IVestingBatchRecipient, ak as IWithdrawData, al as InstructionGenerator, am as InstructionResult, an as Invoker, ao as LinearStream, ap as MetadataRecipientHashMap, aq as NativeOptions, ar as OracleType, as as OracleTypeName, R as RoutedFeeDestination, at as SignFn, au as SolanaStreamClient, b as Stream, av as StreamClientOptions, aw as StreamClientOptionsWithConnection, ax as StreamDirection, S as StreamType, ay as TestOracle, az as TopupFn, aA as TransactionSchedulingOptions, aB as TransferFn, aC as UpdateFn, aD as UpdateTestOracleParams, aE as WithdrawFn, aF as buildLockBatchParams, aG as buildLockParams, aH as buildTransaction, aI as buildVestingBatchParams, aJ as buildVestingParams, aK as cancel, aL as computeAmountPerPeriod, aM as create, aN as createBatch, aO as createClientFromEnv, aP as createLock, aQ as createLockBatch, aR as createVesting, aS as createVestingBatch, aT as execute, aU as executeBatch, aV as executeBatchSequential, aW as resolveConnection, aX as resolveDuration, aY as sign, aZ as topup, a_ as transfer, a$ as update, b0 as withdraw } from './index-BLL6w66C.cjs';
|
|
2
|
+
export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, ApiClient, ApiClientOptions, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Chain, ContractSchema, ContractType, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, DynamicContractSchema, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, GetContractsOptions, MAX_SAFE_UNIX_TIME_VALUE, METADATA_SEED, ORIGINAL_CONTRACT_SENDER_OFFSET, 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, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, TabulariumContract, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, claimRoutedFeeStreamInstruction, createClient, createStreamInstruction, createStreamV2Instruction, createUncheckedStreamInstruction, createUncheckedStreamV2Instruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveRepopulatedMetadataPDA, deriveStreamMetadataPDA, deriveTestOraclePDA, encodeStreamName, encodeStreamNameAsArray, extractSolanaErrorCode, getMetadataKey, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isStrictTokenLockCreate, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL, topupStreamInstruction, transferStreamInstruction, transformContract, updateStreamInstruction, withdrawStreamInstruction } from './solana/index.cjs';
|
|
3
3
|
export { ContractError, ICluster, getBN, getNumberFromBN } from '@streamflow/common';
|
|
4
4
|
import '@solana/wallet-adapter-base';
|
|
5
5
|
import '@solana/web3.js';
|
|
@@ -81,6 +81,24 @@ var isTokenLock = (streamData) => {
|
|
|
81
81
|
}
|
|
82
82
|
return false;
|
|
83
83
|
};
|
|
84
|
+
var isStrictTokenLockCreate = (data, now = Math.floor(Date.now() / 1e3)) => {
|
|
85
|
+
if (data.canTopup || data.automaticWithdrawal || data.cancelableBySender || data.cancelableByRecipient || data.transferableBySender) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
if (!isCliffCloseToDepositedAmount({ depositedAmount: data.amount, cliffAmount: data.cliffAmount })) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
if (data.cliffAmount.gt(data.amount) || data.amountPerPeriod.isZero()) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
const remaining = data.amount.sub(data.cliffAmount);
|
|
95
|
+
const periodsLeft = remaining.add(data.amountPerPeriod).subn(1).div(data.amountPerPeriod);
|
|
96
|
+
const cliff = data.start === 0 ? now : data.cliff;
|
|
97
|
+
const unlockStart = cliff > 0 ? cliff : data.start;
|
|
98
|
+
const end = new BN3__default.default(unlockStart).add(periodsLeft.mul(new BN3__default.default(data.period)));
|
|
99
|
+
const cliffEndGap = end.sub(new BN3__default.default(cliff));
|
|
100
|
+
return !cliffEndGap.isNeg() && cliffEndGap.lten(MAX_CLIFF_END_GAP_SECONDS);
|
|
101
|
+
};
|
|
84
102
|
var buildStreamType = (streamData) => {
|
|
85
103
|
if (isTokenLock(streamData)) {
|
|
86
104
|
return "lock" /* Lock */;
|
|
@@ -3278,6 +3296,27 @@ var transformContract = async (schema) => {
|
|
|
3278
3296
|
// solana/StreamClient.ts
|
|
3279
3297
|
var METADATA_ACC_SIZE = 1104;
|
|
3280
3298
|
var ALIGNED_METADATA_ACC_SIZE = 320;
|
|
3299
|
+
var PARTNER_LINK_DISCRIMINATOR = buffer.Buffer.from([114, 220, 250, 94, 181, 182, 195, 222]);
|
|
3300
|
+
var PARTNER_LINK_SIZE = 8 + 32 + 32 + 32;
|
|
3301
|
+
var decodePartnerLink = (data) => data.length >= PARTNER_LINK_SIZE && data.subarray(0, 8).equals(PARTNER_LINK_DISCRIMINATOR) ? { partnerPubkey: new web3_js.PublicKey(data.subarray(8, 40)), linkedPubkey: new web3_js.PublicKey(data.subarray(40, 72)) } : null;
|
|
3302
|
+
var findFees = (partners, address) => {
|
|
3303
|
+
const filteredPartners = partners.filter((partner2) => new web3_js.PublicKey(partner2.pubkey).toString() === address);
|
|
3304
|
+
if (filteredPartners.length === 0) {
|
|
3305
|
+
return null;
|
|
3306
|
+
}
|
|
3307
|
+
if (filteredPartners.length > 1) {
|
|
3308
|
+
throw new Error("More than one partner found, fees fetching is not possible.");
|
|
3309
|
+
}
|
|
3310
|
+
const partner = filteredPartners[0];
|
|
3311
|
+
return {
|
|
3312
|
+
creationFeeSol: Number(partner.creation_fee),
|
|
3313
|
+
autoClaimFeeSol: Number(partner.auto_claim_fee),
|
|
3314
|
+
streamflowFee: Number(partner.token_fee_percent.toFixed(4)),
|
|
3315
|
+
streamflowLockFee: Number(partner.token_lock_token_fee_percent.toFixed(4)),
|
|
3316
|
+
partnerFee: 0
|
|
3317
|
+
};
|
|
3318
|
+
};
|
|
3319
|
+
var getWrapFeePercent = (rates, data) => isStrictTokenLockCreate(data) ? rates.streamflowLockFee : rates.streamflowFee;
|
|
3281
3320
|
var SolanaStreamClient = class {
|
|
3282
3321
|
/**
|
|
3283
3322
|
* Create Stream instance
|
|
@@ -3371,10 +3410,8 @@ var SolanaStreamClient = class {
|
|
|
3371
3410
|
tokenProgramId ? new web3_js.PublicKey(tokenProgramId) : void 0
|
|
3372
3411
|
);
|
|
3373
3412
|
if (isNative) {
|
|
3374
|
-
const
|
|
3375
|
-
|
|
3376
|
-
});
|
|
3377
|
-
const totalAmount = calculateTotalAmountToDeposit(amount, totalFee);
|
|
3413
|
+
const rates = await this.getCreateFeeRates(data.partnerLink, sender.publicKey);
|
|
3414
|
+
const totalAmount = calculateTotalAmountToDeposit(amount, getWrapFeePercent(rates, data));
|
|
3378
3415
|
ixs.push(...await common.prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
|
|
3379
3416
|
}
|
|
3380
3417
|
const {
|
|
@@ -3761,7 +3798,20 @@ var SolanaStreamClient = class {
|
|
|
3761
3798
|
computeLimit
|
|
3762
3799
|
});
|
|
3763
3800
|
if (isNative) {
|
|
3764
|
-
const
|
|
3801
|
+
const rates = await this.getCreateFeeRates(partnerLink, sender.publicKey);
|
|
3802
|
+
const totalFee = getWrapFeePercent(rates, {
|
|
3803
|
+
start,
|
|
3804
|
+
amount: depositedAmount,
|
|
3805
|
+
period,
|
|
3806
|
+
cliff,
|
|
3807
|
+
cliffAmount,
|
|
3808
|
+
amountPerPeriod,
|
|
3809
|
+
canTopup,
|
|
3810
|
+
automaticWithdrawal,
|
|
3811
|
+
cancelableBySender,
|
|
3812
|
+
cancelableByRecipient,
|
|
3813
|
+
transferableBySender
|
|
3814
|
+
});
|
|
3765
3815
|
const totalAmount = calculateTotalAmountToDeposit(depositedAmount, totalFee);
|
|
3766
3816
|
ixs.push(...await common.prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
|
|
3767
3817
|
}
|
|
@@ -3851,6 +3901,7 @@ var SolanaStreamClient = class {
|
|
|
3851
3901
|
if (recipients.length === 0) {
|
|
3852
3902
|
throw new Error("Recipients array is empty!");
|
|
3853
3903
|
}
|
|
3904
|
+
const wrapFeeRates = isNative ? await this.getCreateFeeRates(data.partnerLink, sender.publicKey) : void 0;
|
|
3854
3905
|
for (let i = 0; i < recipients.length; i++) {
|
|
3855
3906
|
const recipientData = recipients[i];
|
|
3856
3907
|
const createStreamData = { ...streamParams, ...recipientData };
|
|
@@ -3859,8 +3910,8 @@ var SolanaStreamClient = class {
|
|
|
3859
3910
|
metadataPubKeys: metadataPubKeysExt?.[i] ? [metadataPubKeysExt[i]] : void 0
|
|
3860
3911
|
};
|
|
3861
3912
|
const wrapInstructions = [];
|
|
3862
|
-
if (
|
|
3863
|
-
const totalFee =
|
|
3913
|
+
if (wrapFeeRates) {
|
|
3914
|
+
const totalFee = getWrapFeePercent(wrapFeeRates, createStreamData);
|
|
3864
3915
|
const recipientAmount = calculateTotalAmountToDeposit(recipientData.amount, totalFee);
|
|
3865
3916
|
wrapInstructions.push(...await common.prepareWrappedAccount(this.connection, sender.publicKey, recipientAmount));
|
|
3866
3917
|
}
|
|
@@ -4771,26 +4822,38 @@ var SolanaStreamClient = class {
|
|
|
4771
4822
|
* @returns Fees
|
|
4772
4823
|
*/
|
|
4773
4824
|
async getFees({ address }) {
|
|
4825
|
+
const partners = await this.getFeeRows();
|
|
4826
|
+
return partners ? findFees(partners, address) : null;
|
|
4827
|
+
}
|
|
4828
|
+
async getFeeRows() {
|
|
4774
4829
|
const data = await this.connection.getAccountInfo(this.feeOraclePublicKey);
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4830
|
+
return data ? borsh__namespace.deserialize(PARTNERS_SCHEMA, data.data) : null;
|
|
4831
|
+
}
|
|
4832
|
+
/**
|
|
4833
|
+
* Fee rates the program applies to a create from `sender` with `partnerLink`, used to size the WSOL wrap.
|
|
4834
|
+
* Mirrors `resolve_vesting_partner`: a `partnerLink` counts if it signs or the partner oracle owns it, and a
|
|
4835
|
+
* PartnerLink account stands for its partner. A link to another wallet fails the program's lookup, which then
|
|
4836
|
+
* charges its hardcoded fallback and skips the sender's own row. Otherwise the sender's own row, then the
|
|
4837
|
+
* partner's, then the default row. `partner` only takes a share and never picks the row.
|
|
4838
|
+
*/
|
|
4839
|
+
async getCreateFeeRates(partnerLink, sender) {
|
|
4840
|
+
const fallback = { streamflowFee: DEFAULT_STREAMFLOW_FEE, streamflowLockFee: DEFAULT_STREAMFLOW_FEE };
|
|
4841
|
+
let linkedPartner;
|
|
4842
|
+
if (partnerLink?.isSigner) {
|
|
4843
|
+
linkedPartner = common.pk(partnerLink.address).toBase58();
|
|
4844
|
+
} else if (partnerLink) {
|
|
4845
|
+
const address = common.pk(partnerLink.address);
|
|
4846
|
+
const account = await this.connection.getAccountInfo(address);
|
|
4847
|
+
if (account?.owner.equals(this.partnerOracleProgramId)) {
|
|
4848
|
+
const link = decodePartnerLink(account.data);
|
|
4849
|
+
if (link && !link.linkedPubkey.equals(sender)) {
|
|
4850
|
+
return fallback;
|
|
4851
|
+
}
|
|
4852
|
+
linkedPartner = (link?.partnerPubkey ?? address).toBase58();
|
|
4853
|
+
}
|
|
4785
4854
|
}
|
|
4786
|
-
const
|
|
4787
|
-
return
|
|
4788
|
-
creationFeeSol: Number(partner.creation_fee),
|
|
4789
|
-
autoClaimFeeSol: Number(partner.auto_claim_fee),
|
|
4790
|
-
streamflowFee: Number(partner.token_fee_percent.toFixed(4)),
|
|
4791
|
-
streamflowLockFee: Number(partner.token_lock_token_fee_percent.toFixed(4)),
|
|
4792
|
-
partnerFee: 0
|
|
4793
|
-
};
|
|
4855
|
+
const partners = await this.getFeeRows() ?? [];
|
|
4856
|
+
return findFees(partners, sender.toBase58()) ?? (linkedPartner ? findFees(partners, linkedPartner) : null) ?? findFees(partners, WITHDRAWOR) ?? fallback;
|
|
4794
4857
|
}
|
|
4795
4858
|
/**
|
|
4796
4859
|
* Gets default streamflow fee
|