@solana/subscriptions 0.2.0 → 0.3.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/index.cjs +113 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +47 -23
- package/dist/index.d.ts +47 -23
- package/dist/index.js +113 -35
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -513,14 +513,16 @@ function getCreateFixedDelegationDataEncoder() {
|
|
|
513
513
|
return (0, import_kit9.getStructEncoder)([
|
|
514
514
|
["nonce", (0, import_kit9.getU64Encoder)()],
|
|
515
515
|
["amount", (0, import_kit9.getU64Encoder)()],
|
|
516
|
-
["expiryTs", (0, import_kit9.getI64Encoder)()]
|
|
516
|
+
["expiryTs", (0, import_kit9.getI64Encoder)()],
|
|
517
|
+
["expectedSubscriptionAuthorityInitId", (0, import_kit9.getI64Encoder)()]
|
|
517
518
|
]);
|
|
518
519
|
}
|
|
519
520
|
function getCreateFixedDelegationDataDecoder() {
|
|
520
521
|
return (0, import_kit9.getStructDecoder)([
|
|
521
522
|
["nonce", (0, import_kit9.getU64Decoder)()],
|
|
522
523
|
["amount", (0, import_kit9.getU64Decoder)()],
|
|
523
|
-
["expiryTs", (0, import_kit9.getI64Decoder)()]
|
|
524
|
+
["expiryTs", (0, import_kit9.getI64Decoder)()],
|
|
525
|
+
["expectedSubscriptionAuthorityInitId", (0, import_kit9.getI64Decoder)()]
|
|
524
526
|
]);
|
|
525
527
|
}
|
|
526
528
|
function getCreateFixedDelegationDataCodec() {
|
|
@@ -535,7 +537,8 @@ function getCreateRecurringDelegationDataEncoder() {
|
|
|
535
537
|
["amountPerPeriod", (0, import_kit10.getU64Encoder)()],
|
|
536
538
|
["periodLengthS", (0, import_kit10.getU64Encoder)()],
|
|
537
539
|
["startTs", (0, import_kit10.getI64Encoder)()],
|
|
538
|
-
["expiryTs", (0, import_kit10.getI64Encoder)()]
|
|
540
|
+
["expiryTs", (0, import_kit10.getI64Encoder)()],
|
|
541
|
+
["expectedSubscriptionAuthorityInitId", (0, import_kit10.getI64Encoder)()]
|
|
539
542
|
]);
|
|
540
543
|
}
|
|
541
544
|
function getCreateRecurringDelegationDataDecoder() {
|
|
@@ -544,7 +547,8 @@ function getCreateRecurringDelegationDataDecoder() {
|
|
|
544
547
|
["amountPerPeriod", (0, import_kit10.getU64Decoder)()],
|
|
545
548
|
["periodLengthS", (0, import_kit10.getU64Decoder)()],
|
|
546
549
|
["startTs", (0, import_kit10.getI64Decoder)()],
|
|
547
|
-
["expiryTs", (0, import_kit10.getI64Decoder)()]
|
|
550
|
+
["expiryTs", (0, import_kit10.getI64Decoder)()],
|
|
551
|
+
["expectedSubscriptionAuthorityInitId", (0, import_kit10.getI64Decoder)()]
|
|
548
552
|
]);
|
|
549
553
|
}
|
|
550
554
|
function getCreateRecurringDelegationDataCodec() {
|
|
@@ -653,7 +657,8 @@ function getSubscribeDataEncoder() {
|
|
|
653
657
|
["expectedMint", (0, import_kit15.getAddressEncoder)()],
|
|
654
658
|
["expectedAmount", (0, import_kit15.getU64Encoder)()],
|
|
655
659
|
["expectedPeriodHours", (0, import_kit15.getU64Encoder)()],
|
|
656
|
-
["expectedCreatedAt", (0, import_kit15.getI64Encoder)()]
|
|
660
|
+
["expectedCreatedAt", (0, import_kit15.getI64Encoder)()],
|
|
661
|
+
["expectedSubscriptionAuthorityInitId", (0, import_kit15.getI64Encoder)()]
|
|
657
662
|
]);
|
|
658
663
|
}
|
|
659
664
|
function getSubscribeDataDecoder() {
|
|
@@ -663,7 +668,8 @@ function getSubscribeDataDecoder() {
|
|
|
663
668
|
["expectedMint", (0, import_kit15.getAddressDecoder)()],
|
|
664
669
|
["expectedAmount", (0, import_kit15.getU64Decoder)()],
|
|
665
670
|
["expectedPeriodHours", (0, import_kit15.getU64Decoder)()],
|
|
666
|
-
["expectedCreatedAt", (0, import_kit15.getI64Decoder)()]
|
|
671
|
+
["expectedCreatedAt", (0, import_kit15.getI64Decoder)()],
|
|
672
|
+
["expectedSubscriptionAuthorityInitId", (0, import_kit15.getI64Decoder)()]
|
|
667
673
|
]);
|
|
668
674
|
}
|
|
669
675
|
function getSubscribeDataCodec() {
|
|
@@ -1913,6 +1919,7 @@ function getTransferFixedInstruction(input, config) {
|
|
|
1913
1919
|
subscriptionAuthority: { value: input.subscriptionAuthority ?? null, isWritable: false },
|
|
1914
1920
|
delegatorAta: { value: input.delegatorAta ?? null, isWritable: true },
|
|
1915
1921
|
receiverAta: { value: input.receiverAta ?? null, isWritable: true },
|
|
1922
|
+
tokenMint: { value: input.tokenMint ?? null, isWritable: false },
|
|
1916
1923
|
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
1917
1924
|
delegatee: { value: input.delegatee ?? null, isWritable: false },
|
|
1918
1925
|
eventAuthority: { value: input.eventAuthority ?? null, isWritable: false },
|
|
@@ -1933,6 +1940,7 @@ function getTransferFixedInstruction(input, config) {
|
|
|
1933
1940
|
getAccountMeta("subscriptionAuthority", accounts.subscriptionAuthority),
|
|
1934
1941
|
getAccountMeta("delegatorAta", accounts.delegatorAta),
|
|
1935
1942
|
getAccountMeta("receiverAta", accounts.receiverAta),
|
|
1943
|
+
getAccountMeta("tokenMint", accounts.tokenMint),
|
|
1936
1944
|
getAccountMeta("tokenProgram", accounts.tokenProgram),
|
|
1937
1945
|
getAccountMeta("delegatee", accounts.delegatee),
|
|
1938
1946
|
getAccountMeta("eventAuthority", accounts.eventAuthority),
|
|
@@ -1943,10 +1951,10 @@ function getTransferFixedInstruction(input, config) {
|
|
|
1943
1951
|
});
|
|
1944
1952
|
}
|
|
1945
1953
|
function parseTransferFixedInstruction(instruction) {
|
|
1946
|
-
if (instruction.accounts.length <
|
|
1954
|
+
if (instruction.accounts.length < 9) {
|
|
1947
1955
|
throw new import_kit33.SolanaError(import_kit33.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
|
|
1948
1956
|
actualAccountMetas: instruction.accounts.length,
|
|
1949
|
-
expectedAccountMetas:
|
|
1957
|
+
expectedAccountMetas: 9
|
|
1950
1958
|
});
|
|
1951
1959
|
}
|
|
1952
1960
|
let accountIndex = 0;
|
|
@@ -1962,6 +1970,7 @@ function parseTransferFixedInstruction(instruction) {
|
|
|
1962
1970
|
subscriptionAuthority: getNextAccount(),
|
|
1963
1971
|
delegatorAta: getNextAccount(),
|
|
1964
1972
|
receiverAta: getNextAccount(),
|
|
1973
|
+
tokenMint: getNextAccount(),
|
|
1965
1974
|
tokenProgram: getNextAccount(),
|
|
1966
1975
|
delegatee: getNextAccount(),
|
|
1967
1976
|
eventAuthority: getNextAccount(),
|
|
@@ -2003,6 +2012,7 @@ function getTransferRecurringInstruction(input, config) {
|
|
|
2003
2012
|
subscriptionAuthority: { value: input.subscriptionAuthority ?? null, isWritable: false },
|
|
2004
2013
|
delegatorAta: { value: input.delegatorAta ?? null, isWritable: true },
|
|
2005
2014
|
receiverAta: { value: input.receiverAta ?? null, isWritable: true },
|
|
2015
|
+
tokenMint: { value: input.tokenMint ?? null, isWritable: false },
|
|
2006
2016
|
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
2007
2017
|
delegatee: { value: input.delegatee ?? null, isWritable: false },
|
|
2008
2018
|
eventAuthority: { value: input.eventAuthority ?? null, isWritable: false },
|
|
@@ -2023,6 +2033,7 @@ function getTransferRecurringInstruction(input, config) {
|
|
|
2023
2033
|
getAccountMeta("subscriptionAuthority", accounts.subscriptionAuthority),
|
|
2024
2034
|
getAccountMeta("delegatorAta", accounts.delegatorAta),
|
|
2025
2035
|
getAccountMeta("receiverAta", accounts.receiverAta),
|
|
2036
|
+
getAccountMeta("tokenMint", accounts.tokenMint),
|
|
2026
2037
|
getAccountMeta("tokenProgram", accounts.tokenProgram),
|
|
2027
2038
|
getAccountMeta("delegatee", accounts.delegatee),
|
|
2028
2039
|
getAccountMeta("eventAuthority", accounts.eventAuthority),
|
|
@@ -2033,10 +2044,10 @@ function getTransferRecurringInstruction(input, config) {
|
|
|
2033
2044
|
});
|
|
2034
2045
|
}
|
|
2035
2046
|
function parseTransferRecurringInstruction(instruction) {
|
|
2036
|
-
if (instruction.accounts.length <
|
|
2047
|
+
if (instruction.accounts.length < 9) {
|
|
2037
2048
|
throw new import_kit34.SolanaError(import_kit34.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
|
|
2038
2049
|
actualAccountMetas: instruction.accounts.length,
|
|
2039
|
-
expectedAccountMetas:
|
|
2050
|
+
expectedAccountMetas: 9
|
|
2040
2051
|
});
|
|
2041
2052
|
}
|
|
2042
2053
|
let accountIndex = 0;
|
|
@@ -2052,6 +2063,7 @@ function parseTransferRecurringInstruction(instruction) {
|
|
|
2052
2063
|
subscriptionAuthority: getNextAccount(),
|
|
2053
2064
|
delegatorAta: getNextAccount(),
|
|
2054
2065
|
receiverAta: getNextAccount(),
|
|
2066
|
+
tokenMint: getNextAccount(),
|
|
2055
2067
|
tokenProgram: getNextAccount(),
|
|
2056
2068
|
delegatee: getNextAccount(),
|
|
2057
2069
|
eventAuthority: getNextAccount(),
|
|
@@ -2098,6 +2110,7 @@ function getTransferSubscriptionInstruction(input, config) {
|
|
|
2098
2110
|
delegatorAta: { value: input.delegatorAta ?? null, isWritable: true },
|
|
2099
2111
|
receiverAta: { value: input.receiverAta ?? null, isWritable: true },
|
|
2100
2112
|
caller: { value: input.caller ?? null, isWritable: false },
|
|
2113
|
+
tokenMint: { value: input.tokenMint ?? null, isWritable: false },
|
|
2101
2114
|
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
2102
2115
|
eventAuthority: { value: input.eventAuthority ?? null, isWritable: false },
|
|
2103
2116
|
selfProgram: { value: input.selfProgram ?? null, isWritable: false }
|
|
@@ -2119,6 +2132,7 @@ function getTransferSubscriptionInstruction(input, config) {
|
|
|
2119
2132
|
getAccountMeta("delegatorAta", accounts.delegatorAta),
|
|
2120
2133
|
getAccountMeta("receiverAta", accounts.receiverAta),
|
|
2121
2134
|
getAccountMeta("caller", accounts.caller),
|
|
2135
|
+
getAccountMeta("tokenMint", accounts.tokenMint),
|
|
2122
2136
|
getAccountMeta("tokenProgram", accounts.tokenProgram),
|
|
2123
2137
|
getAccountMeta("eventAuthority", accounts.eventAuthority),
|
|
2124
2138
|
getAccountMeta("selfProgram", accounts.selfProgram)
|
|
@@ -2128,10 +2142,10 @@ function getTransferSubscriptionInstruction(input, config) {
|
|
|
2128
2142
|
});
|
|
2129
2143
|
}
|
|
2130
2144
|
function parseTransferSubscriptionInstruction(instruction) {
|
|
2131
|
-
if (instruction.accounts.length <
|
|
2145
|
+
if (instruction.accounts.length < 10) {
|
|
2132
2146
|
throw new import_kit35.SolanaError(import_kit35.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
|
|
2133
2147
|
actualAccountMetas: instruction.accounts.length,
|
|
2134
|
-
expectedAccountMetas:
|
|
2148
|
+
expectedAccountMetas: 10
|
|
2135
2149
|
});
|
|
2136
2150
|
}
|
|
2137
2151
|
let accountIndex = 0;
|
|
@@ -2149,6 +2163,7 @@ function parseTransferSubscriptionInstruction(instruction) {
|
|
|
2149
2163
|
delegatorAta: getNextAccount(),
|
|
2150
2164
|
receiverAta: getNextAccount(),
|
|
2151
2165
|
caller: getNextAccount(),
|
|
2166
|
+
tokenMint: getNextAccount(),
|
|
2152
2167
|
tokenProgram: getNextAccount(),
|
|
2153
2168
|
eventAuthority: getNextAccount(),
|
|
2154
2169
|
selfProgram: getNextAccount()
|
|
@@ -2816,6 +2831,11 @@ async function getCloseSubscriptionAuthorityOverlayInstructionAsync(input) {
|
|
|
2816
2831
|
}
|
|
2817
2832
|
async function getCreateFixedDelegationOverlayInstructionAsync(input) {
|
|
2818
2833
|
assertPositive(input.amount, "amount");
|
|
2834
|
+
if (input.expectedSubscriptionAuthorityInitId === void 0) {
|
|
2835
|
+
throw new Error(
|
|
2836
|
+
"getCreateFixedDelegationOverlayInstructionAsync requires expectedSubscriptionAuthorityInitId. Use the plugin client `subscriptions.instructions.createFixedDelegation(...)` to auto-fetch from the live authority."
|
|
2837
|
+
);
|
|
2838
|
+
}
|
|
2819
2839
|
const [subscriptionAuthority] = await findSubscriptionAuthorityPda(
|
|
2820
2840
|
{ tokenMint: input.tokenMint, user: input.delegator.address },
|
|
2821
2841
|
pdaConfig(input.programAddress)
|
|
@@ -2837,6 +2857,7 @@ async function getCreateFixedDelegationOverlayInstructionAsync(input) {
|
|
|
2837
2857
|
delegator: input.delegator,
|
|
2838
2858
|
fixedDelegation: {
|
|
2839
2859
|
amount: input.amount,
|
|
2860
|
+
expectedSubscriptionAuthorityInitId: input.expectedSubscriptionAuthorityInitId,
|
|
2840
2861
|
expiryTs: input.expiryTs,
|
|
2841
2862
|
nonce: input.nonce
|
|
2842
2863
|
},
|
|
@@ -2850,6 +2871,11 @@ async function getCreateFixedDelegationOverlayInstructionAsync(input) {
|
|
|
2850
2871
|
async function getCreateRecurringDelegationOverlayInstructionAsync(input) {
|
|
2851
2872
|
assertPositive(input.amountPerPeriod, "amountPerPeriod");
|
|
2852
2873
|
assertPositive(input.periodLengthS, "periodLengthS");
|
|
2874
|
+
if (input.expectedSubscriptionAuthorityInitId === void 0) {
|
|
2875
|
+
throw new Error(
|
|
2876
|
+
"getCreateRecurringDelegationOverlayInstructionAsync requires expectedSubscriptionAuthorityInitId. Use the plugin client `subscriptions.instructions.createRecurringDelegation(...)` to auto-fetch from the live authority."
|
|
2877
|
+
);
|
|
2878
|
+
}
|
|
2853
2879
|
const [subscriptionAuthority] = await findSubscriptionAuthorityPda(
|
|
2854
2880
|
{ tokenMint: input.tokenMint, user: input.delegator.address },
|
|
2855
2881
|
pdaConfig(input.programAddress)
|
|
@@ -2871,6 +2897,7 @@ async function getCreateRecurringDelegationOverlayInstructionAsync(input) {
|
|
|
2871
2897
|
delegator: input.delegator,
|
|
2872
2898
|
recurringDelegation: {
|
|
2873
2899
|
amountPerPeriod: input.amountPerPeriod,
|
|
2900
|
+
expectedSubscriptionAuthorityInitId: input.expectedSubscriptionAuthorityInitId,
|
|
2874
2901
|
expiryTs: input.expiryTs,
|
|
2875
2902
|
nonce: input.nonce,
|
|
2876
2903
|
periodLengthS: input.periodLengthS,
|
|
@@ -2925,6 +2952,7 @@ async function getTransferDelegationOverlayInstructionAsync(input, getInstructio
|
|
|
2925
2952
|
delegatorAta: input.delegatorAta,
|
|
2926
2953
|
receiverAta: input.receiverAta,
|
|
2927
2954
|
subscriptionAuthority,
|
|
2955
|
+
tokenMint: input.tokenMint,
|
|
2928
2956
|
tokenProgram: input.tokenProgram,
|
|
2929
2957
|
transferData: {
|
|
2930
2958
|
amount: input.amount,
|
|
@@ -2960,6 +2988,7 @@ async function getTransferSubscriptionOverlayInstructionAsync(input) {
|
|
|
2960
2988
|
receiverAta: input.receiverAta,
|
|
2961
2989
|
subscriptionAuthority,
|
|
2962
2990
|
subscriptionPda: input.subscriptionPda,
|
|
2991
|
+
tokenMint: input.tokenMint,
|
|
2963
2992
|
tokenProgram: input.tokenProgram,
|
|
2964
2993
|
transferData: {
|
|
2965
2994
|
amount: input.amount,
|
|
@@ -3024,9 +3053,9 @@ function getDeletePlanOverlayInstruction(input) {
|
|
|
3024
3053
|
return getDeletePlanInstruction({ owner: input.owner, planPda: input.planPda }, pdaConfig(input.programAddress));
|
|
3025
3054
|
}
|
|
3026
3055
|
async function getSubscribeOverlayInstructionAsync(input) {
|
|
3027
|
-
if (input.expectedAmount === void 0 || input.expectedPeriodHours === void 0 || input.expectedCreatedAt === void 0) {
|
|
3056
|
+
if (input.expectedAmount === void 0 || input.expectedPeriodHours === void 0 || input.expectedCreatedAt === void 0 || input.expectedSubscriptionAuthorityInitId === void 0) {
|
|
3028
3057
|
throw new Error(
|
|
3029
|
-
"getSubscribeOverlayInstructionAsync requires expectedAmount, expectedPeriodHours, and
|
|
3058
|
+
"getSubscribeOverlayInstructionAsync requires expectedAmount, expectedPeriodHours, expectedCreatedAt, and expectedSubscriptionAuthorityInitId. Use the plugin client `subscriptions.instructions.subscribe(...)` to auto-fetch from the live plan and authority."
|
|
3030
3059
|
);
|
|
3031
3060
|
}
|
|
3032
3061
|
const [planPda, planBump] = await findPlanPda(
|
|
@@ -3047,6 +3076,7 @@ async function getSubscribeOverlayInstructionAsync(input) {
|
|
|
3047
3076
|
expectedCreatedAt: input.expectedCreatedAt,
|
|
3048
3077
|
expectedMint: input.tokenMint,
|
|
3049
3078
|
expectedPeriodHours: input.expectedPeriodHours,
|
|
3079
|
+
expectedSubscriptionAuthorityInitId: input.expectedSubscriptionAuthorityInitId,
|
|
3050
3080
|
planBump,
|
|
3051
3081
|
planId: input.planId
|
|
3052
3082
|
},
|
|
@@ -3103,6 +3133,20 @@ function subscriptionsProgram2() {
|
|
|
3103
3133
|
},
|
|
3104
3134
|
plansForOwner: (owner) => fetchPlansForOwner(c.rpc, owner)
|
|
3105
3135
|
};
|
|
3136
|
+
const resolveExpectedSubscriptionAuthorityInitId = async (tokenMint, user, programAddress, expectedSubscriptionAuthorityInitId) => {
|
|
3137
|
+
if (expectedSubscriptionAuthorityInitId !== void 0) {
|
|
3138
|
+
return expectedSubscriptionAuthorityInitId;
|
|
3139
|
+
}
|
|
3140
|
+
const [subscriptionAuthorityPda] = await findSubscriptionAuthorityPda(
|
|
3141
|
+
{ tokenMint, user },
|
|
3142
|
+
pdaConfig(programAddress)
|
|
3143
|
+
);
|
|
3144
|
+
const subscriptionAuthority = await fetchMaybeSubscriptionAuthority(c.rpc, subscriptionAuthorityPda);
|
|
3145
|
+
if (!subscriptionAuthority.exists) {
|
|
3146
|
+
throw new Error("SubscriptionAuthority is not initialized for this delegator and token mint.");
|
|
3147
|
+
}
|
|
3148
|
+
return subscriptionAuthority.data.initId;
|
|
3149
|
+
};
|
|
3106
3150
|
const instructions = {
|
|
3107
3151
|
cancelSubscription: (input) => (0, import_program_client_core16.addSelfPlanAndSendFunctions)(
|
|
3108
3152
|
client,
|
|
@@ -3120,11 +3164,21 @@ function subscriptionsProgram2() {
|
|
|
3120
3164
|
),
|
|
3121
3165
|
createFixedDelegation: (input) => (0, import_program_client_core16.addSelfPlanAndSendFunctions)(
|
|
3122
3166
|
client,
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3167
|
+
(async () => {
|
|
3168
|
+
const delegator = input.delegator ?? client.identity;
|
|
3169
|
+
const expectedSubscriptionAuthorityInitId = await resolveExpectedSubscriptionAuthorityInitId(
|
|
3170
|
+
input.tokenMint,
|
|
3171
|
+
delegator.address,
|
|
3172
|
+
input.programAddress,
|
|
3173
|
+
input.expectedSubscriptionAuthorityInitId
|
|
3174
|
+
);
|
|
3175
|
+
return await getCreateFixedDelegationOverlayInstructionAsync({
|
|
3176
|
+
...input,
|
|
3177
|
+
delegator,
|
|
3178
|
+
expectedSubscriptionAuthorityInitId,
|
|
3179
|
+
payer: input.payer ?? (client.payer === client.identity ? void 0 : client.payer)
|
|
3180
|
+
});
|
|
3181
|
+
})()
|
|
3128
3182
|
),
|
|
3129
3183
|
createPlan: (input) => (0, import_program_client_core16.addSelfPlanAndSendFunctions)(
|
|
3130
3184
|
client,
|
|
@@ -3135,11 +3189,21 @@ function subscriptionsProgram2() {
|
|
|
3135
3189
|
),
|
|
3136
3190
|
createRecurringDelegation: (input) => (0, import_program_client_core16.addSelfPlanAndSendFunctions)(
|
|
3137
3191
|
client,
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3192
|
+
(async () => {
|
|
3193
|
+
const delegator = input.delegator ?? client.identity;
|
|
3194
|
+
const expectedSubscriptionAuthorityInitId = await resolveExpectedSubscriptionAuthorityInitId(
|
|
3195
|
+
input.tokenMint,
|
|
3196
|
+
delegator.address,
|
|
3197
|
+
input.programAddress,
|
|
3198
|
+
input.expectedSubscriptionAuthorityInitId
|
|
3199
|
+
);
|
|
3200
|
+
return await getCreateRecurringDelegationOverlayInstructionAsync({
|
|
3201
|
+
...input,
|
|
3202
|
+
delegator,
|
|
3203
|
+
expectedSubscriptionAuthorityInitId,
|
|
3204
|
+
payer: input.payer ?? (client.payer === client.identity ? void 0 : client.payer)
|
|
3205
|
+
});
|
|
3206
|
+
})()
|
|
3143
3207
|
),
|
|
3144
3208
|
deletePlan: (input) => (0, import_program_client_core16.addSelfPlanAndSendFunctions)(
|
|
3145
3209
|
client,
|
|
@@ -3180,9 +3244,14 @@ function subscriptionsProgram2() {
|
|
|
3180
3244
|
subscribe: (input) => (0, import_program_client_core16.addSelfPlanAndSendFunctions)(
|
|
3181
3245
|
client,
|
|
3182
3246
|
(async () => {
|
|
3183
|
-
|
|
3247
|
+
const subscriber = input.subscriber ?? client.identity;
|
|
3248
|
+
let {
|
|
3249
|
+
expectedAmount,
|
|
3250
|
+
expectedCreatedAt,
|
|
3251
|
+
expectedPeriodHours,
|
|
3252
|
+
expectedSubscriptionAuthorityInitId
|
|
3253
|
+
} = input;
|
|
3184
3254
|
if (expectedAmount === void 0 || expectedPeriodHours === void 0 || expectedCreatedAt === void 0) {
|
|
3185
|
-
const subscriber = input.subscriber ?? client.identity;
|
|
3186
3255
|
const [planPda] = await findPlanPda(
|
|
3187
3256
|
{ owner: input.merchant, planId: input.planId },
|
|
3188
3257
|
pdaConfig(input.programAddress)
|
|
@@ -3191,22 +3260,31 @@ function subscriptionsProgram2() {
|
|
|
3191
3260
|
expectedAmount = expectedAmount ?? plan.data.data.terms.amount;
|
|
3192
3261
|
expectedPeriodHours = expectedPeriodHours ?? plan.data.data.terms.periodHours;
|
|
3193
3262
|
expectedCreatedAt = expectedCreatedAt ?? plan.data.data.terms.createdAt;
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3263
|
+
}
|
|
3264
|
+
if (expectedSubscriptionAuthorityInitId === void 0) {
|
|
3265
|
+
const [subscriptionAuthorityPda] = await findSubscriptionAuthorityPda(
|
|
3266
|
+
{ tokenMint: input.tokenMint, user: subscriber.address },
|
|
3267
|
+
pdaConfig(input.programAddress)
|
|
3268
|
+
);
|
|
3269
|
+
const subscriptionAuthority = await fetchMaybeSubscriptionAuthority(
|
|
3270
|
+
c.rpc,
|
|
3271
|
+
subscriptionAuthorityPda
|
|
3272
|
+
);
|
|
3273
|
+
if (!subscriptionAuthority.exists) {
|
|
3274
|
+
throw new Error(
|
|
3275
|
+
"SubscriptionAuthority is not initialized for this subscriber and token mint."
|
|
3276
|
+
);
|
|
3277
|
+
}
|
|
3278
|
+
expectedSubscriptionAuthorityInitId = subscriptionAuthority.data.initId;
|
|
3202
3279
|
}
|
|
3203
3280
|
return await getSubscribeOverlayInstructionAsync({
|
|
3204
3281
|
...input,
|
|
3205
3282
|
expectedAmount,
|
|
3206
3283
|
expectedCreatedAt,
|
|
3207
3284
|
expectedPeriodHours,
|
|
3285
|
+
expectedSubscriptionAuthorityInitId,
|
|
3208
3286
|
payer: input.payer ?? (client.payer === client.identity ? void 0 : client.payer),
|
|
3209
|
-
subscriber
|
|
3287
|
+
subscriber
|
|
3210
3288
|
});
|
|
3211
3289
|
})()
|
|
3212
3290
|
),
|