@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { l as BatchCreationItem, m as BatchExecuteResult, n as BatchInstructionResult, q as BuildTransactionFn, r as BuildTransactionOptions, s as BuiltTransaction, C as CancelFn, x as CreateBatchFn, y as CreateFn, z as CreateInstructionResult, G as Env, H as ExecuteBatchFn, J as ExecuteBatchSequentialFn, K as ExecuteFn, L as ExecutionEnv, T as ICreateLockBatchParams, U as ICreateLockParams, a0 as ICreateVestingBatchParams, a1 as ICreateVestingParams, a8 as ILockBatchRecipient, aj as IVestingBatchRecipient, am as InstructionResult, an as Invoker, aq as NativeOptions, at as SignFn, az as TopupFn, aB as TransferFn, aC as UpdateFn, 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-FDwxtRYV.js';
|
|
2
2
|
import '@solana/wallet-adapter-base';
|
|
3
3
|
import '@solana/web3.js';
|
|
4
4
|
import '@streamflow/common';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PublicKey, Connection, Keypair, SystemProgram, TransactionMessage, VersionedTransaction, TransactionInstruction, SYSVAR_RENT_PUBKEY } from '@solana/web3.js';
|
|
2
|
-
import { ICluster, prepareBaseInstructions, prepareTransaction, executeTransaction, executeMultipleTransactions, buildSendThrottler, assertHasPublicKey, prepareWrappedAccount, signAndExecuteTransaction, invariant, getMintAndProgram, ata, getBN, createVersionedTransaction, getMultipleAccountsInfoBatched, getProgramAccounts, isDev, checkOrCreateAtaBatch,
|
|
2
|
+
import { ICluster, prepareBaseInstructions, prepareTransaction, executeTransaction, executeMultipleTransactions, buildSendThrottler, assertHasPublicKey, prepareWrappedAccount, signAndExecuteTransaction, invariant, getMintAndProgram, ata, getBN, createVersionedTransaction, getMultipleAccountsInfoBatched, getProgramAccounts, pk, isDev, checkOrCreateAtaBatch, isSignerKeypair, isSignerWallet, getNumberFromBN } from '@streamflow/common';
|
|
3
3
|
import BN3 from 'bn.js';
|
|
4
4
|
import bs58 from 'bs58';
|
|
5
5
|
import { Buffer as Buffer$1 } from 'buffer';
|
|
@@ -54,6 +54,24 @@ var isTokenLock = (streamData) => {
|
|
|
54
54
|
}
|
|
55
55
|
return false;
|
|
56
56
|
};
|
|
57
|
+
var isStrictTokenLockCreate = (data, now = Math.floor(Date.now() / 1e3)) => {
|
|
58
|
+
if (data.canTopup || data.automaticWithdrawal || data.cancelableBySender || data.cancelableByRecipient || data.transferableBySender) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (!isCliffCloseToDepositedAmount({ depositedAmount: data.amount, cliffAmount: data.cliffAmount })) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
if (data.cliffAmount.gt(data.amount) || data.amountPerPeriod.isZero()) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const remaining = data.amount.sub(data.cliffAmount);
|
|
68
|
+
const periodsLeft = remaining.add(data.amountPerPeriod).subn(1).div(data.amountPerPeriod);
|
|
69
|
+
const cliff = data.start === 0 ? now : data.cliff;
|
|
70
|
+
const unlockStart = cliff > 0 ? cliff : data.start;
|
|
71
|
+
const end = new BN3(unlockStart).add(periodsLeft.mul(new BN3(data.period)));
|
|
72
|
+
const cliffEndGap = end.sub(new BN3(cliff));
|
|
73
|
+
return !cliffEndGap.isNeg() && cliffEndGap.lten(MAX_CLIFF_END_GAP_SECONDS);
|
|
74
|
+
};
|
|
57
75
|
var buildStreamType = (streamData) => {
|
|
58
76
|
if (isTokenLock(streamData)) {
|
|
59
77
|
return "lock" /* Lock */;
|
|
@@ -3251,6 +3269,27 @@ var transformContract = async (schema) => {
|
|
|
3251
3269
|
// solana/StreamClient.ts
|
|
3252
3270
|
var METADATA_ACC_SIZE = 1104;
|
|
3253
3271
|
var ALIGNED_METADATA_ACC_SIZE = 320;
|
|
3272
|
+
var PARTNER_LINK_DISCRIMINATOR = Buffer$1.from([114, 220, 250, 94, 181, 182, 195, 222]);
|
|
3273
|
+
var PARTNER_LINK_SIZE = 8 + 32 + 32 + 32;
|
|
3274
|
+
var decodePartnerLink = (data) => data.length >= PARTNER_LINK_SIZE && data.subarray(0, 8).equals(PARTNER_LINK_DISCRIMINATOR) ? { partnerPubkey: new PublicKey(data.subarray(8, 40)), linkedPubkey: new PublicKey(data.subarray(40, 72)) } : null;
|
|
3275
|
+
var findFees = (partners, address) => {
|
|
3276
|
+
const filteredPartners = partners.filter((partner2) => new PublicKey(partner2.pubkey).toString() === address);
|
|
3277
|
+
if (filteredPartners.length === 0) {
|
|
3278
|
+
return null;
|
|
3279
|
+
}
|
|
3280
|
+
if (filteredPartners.length > 1) {
|
|
3281
|
+
throw new Error("More than one partner found, fees fetching is not possible.");
|
|
3282
|
+
}
|
|
3283
|
+
const partner = filteredPartners[0];
|
|
3284
|
+
return {
|
|
3285
|
+
creationFeeSol: Number(partner.creation_fee),
|
|
3286
|
+
autoClaimFeeSol: Number(partner.auto_claim_fee),
|
|
3287
|
+
streamflowFee: Number(partner.token_fee_percent.toFixed(4)),
|
|
3288
|
+
streamflowLockFee: Number(partner.token_lock_token_fee_percent.toFixed(4)),
|
|
3289
|
+
partnerFee: 0
|
|
3290
|
+
};
|
|
3291
|
+
};
|
|
3292
|
+
var getWrapFeePercent = (rates, data) => isStrictTokenLockCreate(data) ? rates.streamflowLockFee : rates.streamflowFee;
|
|
3254
3293
|
var SolanaStreamClient = class {
|
|
3255
3294
|
/**
|
|
3256
3295
|
* Create Stream instance
|
|
@@ -3344,10 +3383,8 @@ var SolanaStreamClient = class {
|
|
|
3344
3383
|
tokenProgramId ? new PublicKey(tokenProgramId) : void 0
|
|
3345
3384
|
);
|
|
3346
3385
|
if (isNative) {
|
|
3347
|
-
const
|
|
3348
|
-
|
|
3349
|
-
});
|
|
3350
|
-
const totalAmount = calculateTotalAmountToDeposit(amount, totalFee);
|
|
3386
|
+
const rates = await this.getCreateFeeRates(data.partnerLink, sender.publicKey);
|
|
3387
|
+
const totalAmount = calculateTotalAmountToDeposit(amount, getWrapFeePercent(rates, data));
|
|
3351
3388
|
ixs.push(...await prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
|
|
3352
3389
|
}
|
|
3353
3390
|
const {
|
|
@@ -3734,7 +3771,20 @@ var SolanaStreamClient = class {
|
|
|
3734
3771
|
computeLimit
|
|
3735
3772
|
});
|
|
3736
3773
|
if (isNative) {
|
|
3737
|
-
const
|
|
3774
|
+
const rates = await this.getCreateFeeRates(partnerLink, sender.publicKey);
|
|
3775
|
+
const totalFee = getWrapFeePercent(rates, {
|
|
3776
|
+
start,
|
|
3777
|
+
amount: depositedAmount,
|
|
3778
|
+
period,
|
|
3779
|
+
cliff,
|
|
3780
|
+
cliffAmount,
|
|
3781
|
+
amountPerPeriod,
|
|
3782
|
+
canTopup,
|
|
3783
|
+
automaticWithdrawal,
|
|
3784
|
+
cancelableBySender,
|
|
3785
|
+
cancelableByRecipient,
|
|
3786
|
+
transferableBySender
|
|
3787
|
+
});
|
|
3738
3788
|
const totalAmount = calculateTotalAmountToDeposit(depositedAmount, totalFee);
|
|
3739
3789
|
ixs.push(...await prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
|
|
3740
3790
|
}
|
|
@@ -3824,6 +3874,7 @@ var SolanaStreamClient = class {
|
|
|
3824
3874
|
if (recipients.length === 0) {
|
|
3825
3875
|
throw new Error("Recipients array is empty!");
|
|
3826
3876
|
}
|
|
3877
|
+
const wrapFeeRates = isNative ? await this.getCreateFeeRates(data.partnerLink, sender.publicKey) : void 0;
|
|
3827
3878
|
for (let i = 0; i < recipients.length; i++) {
|
|
3828
3879
|
const recipientData = recipients[i];
|
|
3829
3880
|
const createStreamData = { ...streamParams, ...recipientData };
|
|
@@ -3832,8 +3883,8 @@ var SolanaStreamClient = class {
|
|
|
3832
3883
|
metadataPubKeys: metadataPubKeysExt?.[i] ? [metadataPubKeysExt[i]] : void 0
|
|
3833
3884
|
};
|
|
3834
3885
|
const wrapInstructions = [];
|
|
3835
|
-
if (
|
|
3836
|
-
const totalFee =
|
|
3886
|
+
if (wrapFeeRates) {
|
|
3887
|
+
const totalFee = getWrapFeePercent(wrapFeeRates, createStreamData);
|
|
3837
3888
|
const recipientAmount = calculateTotalAmountToDeposit(recipientData.amount, totalFee);
|
|
3838
3889
|
wrapInstructions.push(...await prepareWrappedAccount(this.connection, sender.publicKey, recipientAmount));
|
|
3839
3890
|
}
|
|
@@ -4744,26 +4795,38 @@ var SolanaStreamClient = class {
|
|
|
4744
4795
|
* @returns Fees
|
|
4745
4796
|
*/
|
|
4746
4797
|
async getFees({ address }) {
|
|
4798
|
+
const partners = await this.getFeeRows();
|
|
4799
|
+
return partners ? findFees(partners, address) : null;
|
|
4800
|
+
}
|
|
4801
|
+
async getFeeRows() {
|
|
4747
4802
|
const data = await this.connection.getAccountInfo(this.feeOraclePublicKey);
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4803
|
+
return data ? borsh.deserialize(PARTNERS_SCHEMA, data.data) : null;
|
|
4804
|
+
}
|
|
4805
|
+
/**
|
|
4806
|
+
* Fee rates the program applies to a create from `sender` with `partnerLink`, used to size the WSOL wrap.
|
|
4807
|
+
* Mirrors `resolve_vesting_partner`: a `partnerLink` counts if it signs or the partner oracle owns it, and a
|
|
4808
|
+
* PartnerLink account stands for its partner. A link to another wallet fails the program's lookup, which then
|
|
4809
|
+
* charges its hardcoded fallback and skips the sender's own row. Otherwise the sender's own row, then the
|
|
4810
|
+
* partner's, then the default row. `partner` only takes a share and never picks the row.
|
|
4811
|
+
*/
|
|
4812
|
+
async getCreateFeeRates(partnerLink, sender) {
|
|
4813
|
+
const fallback = { streamflowFee: DEFAULT_STREAMFLOW_FEE, streamflowLockFee: DEFAULT_STREAMFLOW_FEE };
|
|
4814
|
+
let linkedPartner;
|
|
4815
|
+
if (partnerLink?.isSigner) {
|
|
4816
|
+
linkedPartner = pk(partnerLink.address).toBase58();
|
|
4817
|
+
} else if (partnerLink) {
|
|
4818
|
+
const address = pk(partnerLink.address);
|
|
4819
|
+
const account = await this.connection.getAccountInfo(address);
|
|
4820
|
+
if (account?.owner.equals(this.partnerOracleProgramId)) {
|
|
4821
|
+
const link = decodePartnerLink(account.data);
|
|
4822
|
+
if (link && !link.linkedPubkey.equals(sender)) {
|
|
4823
|
+
return fallback;
|
|
4824
|
+
}
|
|
4825
|
+
linkedPartner = (link?.partnerPubkey ?? address).toBase58();
|
|
4826
|
+
}
|
|
4758
4827
|
}
|
|
4759
|
-
const
|
|
4760
|
-
return
|
|
4761
|
-
creationFeeSol: Number(partner.creation_fee),
|
|
4762
|
-
autoClaimFeeSol: Number(partner.auto_claim_fee),
|
|
4763
|
-
streamflowFee: Number(partner.token_fee_percent.toFixed(4)),
|
|
4764
|
-
streamflowLockFee: Number(partner.token_lock_token_fee_percent.toFixed(4)),
|
|
4765
|
-
partnerFee: 0
|
|
4766
|
-
};
|
|
4828
|
+
const partners = await this.getFeeRows() ?? [];
|
|
4829
|
+
return findFees(partners, sender.toBase58()) ?? (linkedPartner ? findFees(partners, linkedPartner) : null) ?? findFees(partners, WITHDRAWOR) ?? fallback;
|
|
4767
4830
|
}
|
|
4768
4831
|
/**
|
|
4769
4832
|
* Gets default streamflow fee
|