@zebec-network/admin-sdk 1.0.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/LICENSE +21 -0
- package/README.md +730 -0
- package/dist/artifacts/abi/index.d.ts +161 -0
- package/dist/artifacts/abi/index.js +7 -0
- package/dist/artifacts/abi/token.json +350 -0
- package/dist/artifacts/abi/weth.json +153 -0
- package/dist/artifacts/abi/zebecCard.json +1229 -0
- package/dist/artifacts/index.d.ts +11 -0
- package/dist/artifacts/index.js +11 -0
- package/dist/artifacts/typechain-types/OdysseyZebecCard.d.ts +559 -0
- package/dist/artifacts/typechain-types/OdysseyZebecCard.js +1 -0
- package/dist/artifacts/typechain-types/Token.d.ts +149 -0
- package/dist/artifacts/typechain-types/Token.js +1 -0
- package/dist/artifacts/typechain-types/Weth.d.ts +179 -0
- package/dist/artifacts/typechain-types/Weth.js +1 -0
- package/dist/artifacts/typechain-types/ZebecCard.d.ts +723 -0
- package/dist/artifacts/typechain-types/ZebecCard.js +1 -0
- package/dist/artifacts/typechain-types/common.d.ts +50 -0
- package/dist/artifacts/typechain-types/common.js +1 -0
- package/dist/artifacts/typechain-types/factories/OdysseyZebecCard__factory.d.ts +735 -0
- package/dist/artifacts/typechain-types/factories/OdysseyZebecCard__factory.js +959 -0
- package/dist/artifacts/typechain-types/factories/Token__factory.d.ts +280 -0
- package/dist/artifacts/typechain-types/factories/Token__factory.js +374 -0
- package/dist/artifacts/typechain-types/factories/Weth__factory.d.ts +219 -0
- package/dist/artifacts/typechain-types/factories/Weth__factory.js +292 -0
- package/dist/artifacts/typechain-types/factories/ZebecCard__factory.d.ts +966 -0
- package/dist/artifacts/typechain-types/factories/ZebecCard__factory.js +1253 -0
- package/dist/artifacts/typechain-types/factories/index.d.ts +4 -0
- package/dist/artifacts/typechain-types/factories/index.js +7 -0
- package/dist/artifacts/typechain-types/index.d.ts +9 -0
- package/dist/artifacts/typechain-types/index.js +8 -0
- package/dist/artifacts/zebec_instant_card.d.ts +3683 -0
- package/dist/artifacts/zebec_instant_card.js +1 -0
- package/dist/artifacts/zebec_instant_card.json +2801 -0
- package/dist/artifacts/zebec_proxy_stream.d.ts +1933 -0
- package/dist/artifacts/zebec_proxy_stream.js +1 -0
- package/dist/artifacts/zebec_proxy_stream.json +1497 -0
- package/dist/artifacts/zebec_stake_v1.d.ts +1679 -0
- package/dist/artifacts/zebec_stake_v1.js +1 -0
- package/dist/artifacts/zebec_stake_v1.json +1255 -0
- package/dist/artifacts/zebec_stream.d.ts +1481 -0
- package/dist/artifacts/zebec_stream.js +1 -0
- package/dist/artifacts/zebec_stream.json +1243 -0
- package/dist/constants.d.ts +32 -0
- package/dist/constants.js +115 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/pda.d.ts +23 -0
- package/dist/pda.js +125 -0
- package/dist/services/evmCardService.d.ts +189 -0
- package/dist/services/evmCardService.js +322 -0
- package/dist/services/index.d.ts +6 -0
- package/dist/services/index.js +6 -0
- package/dist/services/proxyStreamService.d.ts +72 -0
- package/dist/services/proxyStreamService.js +302 -0
- package/dist/services/solanaCardV2Service.d.ts +50 -0
- package/dist/services/solanaCardV2Service.js +717 -0
- package/dist/services/stakingService.d.ts +39 -0
- package/dist/services/stakingService.js +265 -0
- package/dist/services/streamServices.d.ts +50 -0
- package/dist/services/streamServices.js +322 -0
- package/dist/services/suiCardService.d.ts +91 -0
- package/dist/services/suiCardService.js +487 -0
- package/dist/types.d.ts +433 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +39 -0
- package/package.json +57 -0
|
@@ -0,0 +1,717 @@
|
|
|
1
|
+
import { AnchorProvider, Program, translateAddress, } from "@coral-xyz/anchor";
|
|
2
|
+
import { bpsToPercent, percentToBps } from "@zebec-network/core-utils";
|
|
3
|
+
import { createAssociatedTokenAccountInstruction, getAssociatedTokenAddressSync, TransactionPayload, UNITS_PER_USDC, } from "@zebec-network/solana-common";
|
|
4
|
+
import { BigNumber } from "bignumber.js";
|
|
5
|
+
import BN from "bn.js";
|
|
6
|
+
import { ZEBEC_CARD_V2_IDL } from "../artifacts/index.js";
|
|
7
|
+
import { deriveCardConfigPda, derivePartnerCardConfigPda, derivePartnerTokenFeeMapPda, deriveTokenFeeMapPda, } from "../pda.js";
|
|
8
|
+
export class ZebecSolanaCardV2AdminService {
|
|
9
|
+
provider;
|
|
10
|
+
network;
|
|
11
|
+
program;
|
|
12
|
+
constructor(provider, network, program) {
|
|
13
|
+
this.provider = provider;
|
|
14
|
+
this.network = network;
|
|
15
|
+
this.program = program;
|
|
16
|
+
}
|
|
17
|
+
static create(provider, network) {
|
|
18
|
+
const connection = provider.connection;
|
|
19
|
+
const rpcEndpoint = connection.rpcEndpoint;
|
|
20
|
+
const connNetwork = rpcEndpoint.includes("devnet")
|
|
21
|
+
? "devnet"
|
|
22
|
+
: rpcEndpoint.includes("testnet")
|
|
23
|
+
? "testnet"
|
|
24
|
+
: "mainnet-beta";
|
|
25
|
+
if (connNetwork === "testnet") {
|
|
26
|
+
throw new Error("InvalidOperation: Testnet is not supported. Please use connection with devnet or mainnet-beta network.");
|
|
27
|
+
}
|
|
28
|
+
if (network !== connNetwork) {
|
|
29
|
+
throw new Error(`InvalidOperation: Network mismatch. network and connection network should be same. network: ${network}, connection: ${connNetwork}`);
|
|
30
|
+
}
|
|
31
|
+
const program = new Program(ZEBEC_CARD_V2_IDL, provider);
|
|
32
|
+
return new ZebecSolanaCardV2AdminService(provider, network, program);
|
|
33
|
+
}
|
|
34
|
+
async _createPayload(payerKey, instructions, signers, addressLookupTableAccounts) {
|
|
35
|
+
const errorMap = new Map();
|
|
36
|
+
this.program.idl.errors.map((error) => errorMap.set(error.code, error.msg));
|
|
37
|
+
const provider = this.provider;
|
|
38
|
+
let signTransaction;
|
|
39
|
+
if (provider instanceof AnchorProvider) {
|
|
40
|
+
signTransaction = async (tx) => {
|
|
41
|
+
return provider.wallet.signTransaction(tx);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return new TransactionPayload(this.connection, errorMap, {
|
|
45
|
+
instructions,
|
|
46
|
+
feePayer: payerKey,
|
|
47
|
+
signers: signers ?? [],
|
|
48
|
+
addressLookupTableAccounts: addressLookupTableAccounts ?? [],
|
|
49
|
+
}, signTransaction);
|
|
50
|
+
}
|
|
51
|
+
get connection() {
|
|
52
|
+
return this.provider.connection;
|
|
53
|
+
}
|
|
54
|
+
get programId() {
|
|
55
|
+
return this.program.programId;
|
|
56
|
+
}
|
|
57
|
+
async getInitCardConfigsInstruction(usdcToken, zicOwner, data) {
|
|
58
|
+
const { revenueFee, nativeFee, nonNativeFee, cardVault, revenueVault, commissionVault, maxCardAmount, minCardAmount, feeTiers, dailyCardPurchaseLimit, carbonFee, } = data;
|
|
59
|
+
return this.program.methods
|
|
60
|
+
.initCardConfigs({
|
|
61
|
+
cardVault,
|
|
62
|
+
commissionVault,
|
|
63
|
+
nativeFee,
|
|
64
|
+
nonNativeFee,
|
|
65
|
+
revenueFee,
|
|
66
|
+
revenueVault,
|
|
67
|
+
maxCardAmount,
|
|
68
|
+
minCardAmount,
|
|
69
|
+
feeTier: feeTiers,
|
|
70
|
+
dailyCardBuyLimit: dailyCardPurchaseLimit,
|
|
71
|
+
carbonFee,
|
|
72
|
+
})
|
|
73
|
+
.accounts({
|
|
74
|
+
usdcToken,
|
|
75
|
+
zicOwner,
|
|
76
|
+
})
|
|
77
|
+
.instruction();
|
|
78
|
+
}
|
|
79
|
+
async getSetCardConfigsInstruction(zicOwner, data) {
|
|
80
|
+
const { revenueFee, nativeFee, nonNativeFee, cardVault, revenueVault, commissionVault, feeTiers, maxCardAmount, minCardAmount, dailyCardPurchaseLimit, newZicOwner, carbonFee, } = data;
|
|
81
|
+
return this.program.methods
|
|
82
|
+
.setCardConfigs({
|
|
83
|
+
zicOwner: newZicOwner,
|
|
84
|
+
cardVault,
|
|
85
|
+
commissionVault,
|
|
86
|
+
revenueVault,
|
|
87
|
+
nativeFee,
|
|
88
|
+
nonNativeFee,
|
|
89
|
+
revenueFee,
|
|
90
|
+
maxCardAmount,
|
|
91
|
+
minCardAmount,
|
|
92
|
+
dailyCardBuyLimit: dailyCardPurchaseLimit,
|
|
93
|
+
feeTier: feeTiers,
|
|
94
|
+
carbonFee,
|
|
95
|
+
})
|
|
96
|
+
.accounts({
|
|
97
|
+
zicOwner,
|
|
98
|
+
})
|
|
99
|
+
.instruction();
|
|
100
|
+
}
|
|
101
|
+
async getSetCustomFeesInstruction(zicOwner, tokenFeeList) {
|
|
102
|
+
return this.program.methods
|
|
103
|
+
.setCustomFees(tokenFeeList)
|
|
104
|
+
.accounts({
|
|
105
|
+
zicOwner,
|
|
106
|
+
})
|
|
107
|
+
.instruction();
|
|
108
|
+
}
|
|
109
|
+
async getDeleteCustomFeesInstruction(zicOwner, tokenList) {
|
|
110
|
+
return this.program.methods
|
|
111
|
+
.deleteCustomFees(tokenList)
|
|
112
|
+
.accounts({
|
|
113
|
+
zicOwner,
|
|
114
|
+
})
|
|
115
|
+
.instruction();
|
|
116
|
+
}
|
|
117
|
+
async initCardConfig(params) {
|
|
118
|
+
const { zicOwnerAddress, cardVaultAddress, revenueVaultAddress, commissionVaultAddress, usdcAddress, } = params;
|
|
119
|
+
const zicOwner = zicOwnerAddress
|
|
120
|
+
? translateAddress(zicOwnerAddress)
|
|
121
|
+
: this.provider.publicKey;
|
|
122
|
+
if (!zicOwner) {
|
|
123
|
+
throw new Error("Either provide zicOwnerAddress or use provider with publicKey");
|
|
124
|
+
}
|
|
125
|
+
const usdcToken = translateAddress(usdcAddress);
|
|
126
|
+
const cardVault = translateAddress(cardVaultAddress);
|
|
127
|
+
const revenueVault = translateAddress(revenueVaultAddress);
|
|
128
|
+
const commissionVault = translateAddress(commissionVaultAddress);
|
|
129
|
+
// const cardConfig = deriveCardConfigPda(this.program.programId);
|
|
130
|
+
const nativeFee = new BN(percentToBps(params.nativeFeePercent));
|
|
131
|
+
const nonNativeFee = new BN(percentToBps(params.nonNativeFeePercent));
|
|
132
|
+
const revenueFee = new BN(percentToBps(params.revenueFeePercent));
|
|
133
|
+
const carbonFee = new BN(percentToBps(params.carbonFeePercent));
|
|
134
|
+
const maxCardAmount = new BN(BigNumber(params.maxCardAmount).times(UNITS_PER_USDC).toFixed(0));
|
|
135
|
+
const minCardAmount = new BN(BigNumber(params.minCardAmount).times(UNITS_PER_USDC).toFixed(0));
|
|
136
|
+
const dailyCardPurchaseLimit = new BN(BigNumber(params.dailyCardPurchaseLimit).times(UNITS_PER_USDC).toFixed(0));
|
|
137
|
+
const feeTiers = params.feeTiers.map((feeTier) => {
|
|
138
|
+
const minAmount = new BN(BigNumber(feeTier.minAmount).times(UNITS_PER_USDC).toFixed(0));
|
|
139
|
+
const maxAmount = new BN(BigNumber(feeTier.maxAmount).times(UNITS_PER_USDC).toFixed(0));
|
|
140
|
+
const fee = new BN(percentToBps(feeTier.feePercent));
|
|
141
|
+
return {
|
|
142
|
+
minAmount,
|
|
143
|
+
maxAmount,
|
|
144
|
+
fee,
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
feeTiers.sort((a, b) => b.minAmount.cmp(a.minAmount));
|
|
148
|
+
const ixs = [];
|
|
149
|
+
const ix = await this.getInitCardConfigsInstruction(usdcToken, zicOwner, {
|
|
150
|
+
revenueVault,
|
|
151
|
+
cardVault,
|
|
152
|
+
commissionVault,
|
|
153
|
+
nativeFee,
|
|
154
|
+
nonNativeFee,
|
|
155
|
+
revenueFee,
|
|
156
|
+
feeTiers,
|
|
157
|
+
maxCardAmount,
|
|
158
|
+
minCardAmount,
|
|
159
|
+
dailyCardPurchaseLimit,
|
|
160
|
+
carbonFee,
|
|
161
|
+
});
|
|
162
|
+
ixs.push(ix);
|
|
163
|
+
const cardVaultUsdcAccount = getAssociatedTokenAddressSync(usdcToken, cardVault, true);
|
|
164
|
+
const cardVaultUsdcAccountInfo = await this.connection.getAccountInfo(cardVaultUsdcAccount, this.connection.commitment);
|
|
165
|
+
if (!cardVaultUsdcAccountInfo) {
|
|
166
|
+
ixs.push(createAssociatedTokenAccountInstruction(zicOwner, cardVaultUsdcAccount, cardVault, usdcToken));
|
|
167
|
+
}
|
|
168
|
+
if (!revenueVault.equals(cardVault)) {
|
|
169
|
+
const revenueVaultUsdcAccount = getAssociatedTokenAddressSync(usdcToken, revenueVault, true);
|
|
170
|
+
const revenueVaultUsdcAccountInfo = await this.connection.getAccountInfo(revenueVaultUsdcAccount, this.connection.commitment);
|
|
171
|
+
if (!revenueVaultUsdcAccountInfo) {
|
|
172
|
+
ixs.push(createAssociatedTokenAccountInstruction(zicOwner, revenueVaultUsdcAccount, revenueVault, usdcToken));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (!commissionVault.equals(revenueVault) &&
|
|
176
|
+
!commissionVault.equals(cardVault)) {
|
|
177
|
+
const commissionVaultUsdcAccount = getAssociatedTokenAddressSync(usdcToken, commissionVault, true);
|
|
178
|
+
const commissionVaultUsdcAccountInfo = await this.connection.getAccountInfo(commissionVaultUsdcAccount, this.connection.commitment);
|
|
179
|
+
if (!commissionVaultUsdcAccountInfo) {
|
|
180
|
+
ixs.push(createAssociatedTokenAccountInstruction(zicOwner, commissionVaultUsdcAccount, commissionVault, usdcToken));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const payload = await this._createPayload(zicOwner, ixs, []);
|
|
184
|
+
return payload;
|
|
185
|
+
}
|
|
186
|
+
async setCardConfig(params) {
|
|
187
|
+
const { zicOwnerAddress, newZicOwnerAddress, cardVaultAddress, revenueVaultAddress, commissionVaultAddress, } = params;
|
|
188
|
+
const zicOwner = zicOwnerAddress
|
|
189
|
+
? translateAddress(zicOwnerAddress)
|
|
190
|
+
: this.provider.publicKey;
|
|
191
|
+
if (!zicOwner) {
|
|
192
|
+
throw new Error("Either provide zicOwnerAddress or use provider with publicKey");
|
|
193
|
+
}
|
|
194
|
+
const newZicOwner = translateAddress(newZicOwnerAddress);
|
|
195
|
+
const cardVault = translateAddress(cardVaultAddress);
|
|
196
|
+
const revenueVault = translateAddress(revenueVaultAddress);
|
|
197
|
+
const commissionVault = translateAddress(commissionVaultAddress);
|
|
198
|
+
const [cardConfig] = deriveCardConfigPda(this.program.programId);
|
|
199
|
+
const cardConfigInfo = await this.program.account.card.fetch(cardConfig, "confirmed");
|
|
200
|
+
if (!zicOwner.equals(cardConfigInfo.zicOwner)) {
|
|
201
|
+
throw new Error("Invalid owner of the config.");
|
|
202
|
+
}
|
|
203
|
+
const usdcToken = cardConfigInfo.usdcMint;
|
|
204
|
+
const nativeFee = new BN(percentToBps(params.nativeFeePercent));
|
|
205
|
+
const nonNativeFee = new BN(percentToBps(params.nonNativeFeePercent));
|
|
206
|
+
const revenueFee = new BN(percentToBps(params.revenueFeePercent));
|
|
207
|
+
const carbonFee = new BN(percentToBps(params.carbonFeePercent));
|
|
208
|
+
const maxCardAmount = new BN(BigNumber(params.maxCardAmount).times(UNITS_PER_USDC).toFixed(0));
|
|
209
|
+
const minCardAmount = new BN(BigNumber(params.minCardAmount).times(UNITS_PER_USDC).toFixed(0));
|
|
210
|
+
const dailyCardPurchaseLimit = new BN(BigNumber(params.dailyCardPurchaseLimit).times(UNITS_PER_USDC).toFixed(0));
|
|
211
|
+
const feeTiers = params.feeTiers.map((feeTier) => {
|
|
212
|
+
const minAmount = new BN(BigNumber(feeTier.minAmount).times(UNITS_PER_USDC).toFixed(0));
|
|
213
|
+
const maxAmount = new BN(BigNumber(feeTier.maxAmount).times(UNITS_PER_USDC).toFixed(0));
|
|
214
|
+
const fee = new BN(percentToBps(feeTier.feePercent));
|
|
215
|
+
return {
|
|
216
|
+
minAmount,
|
|
217
|
+
maxAmount,
|
|
218
|
+
fee,
|
|
219
|
+
};
|
|
220
|
+
});
|
|
221
|
+
feeTiers.sort((a, b) => b.minAmount.cmp(a.minAmount));
|
|
222
|
+
const ixs = [];
|
|
223
|
+
const ix = await this.getSetCardConfigsInstruction(zicOwner, {
|
|
224
|
+
newZicOwner,
|
|
225
|
+
revenueFee,
|
|
226
|
+
nativeFee,
|
|
227
|
+
nonNativeFee,
|
|
228
|
+
cardVault,
|
|
229
|
+
revenueVault,
|
|
230
|
+
commissionVault,
|
|
231
|
+
feeTiers,
|
|
232
|
+
maxCardAmount,
|
|
233
|
+
minCardAmount,
|
|
234
|
+
dailyCardPurchaseLimit,
|
|
235
|
+
carbonFee,
|
|
236
|
+
});
|
|
237
|
+
ixs.push(ix);
|
|
238
|
+
const cardVaultUsdcAccount = getAssociatedTokenAddressSync(usdcToken, cardVault, true);
|
|
239
|
+
const cardVaultUsdcAccountInfo = await this.connection.getAccountInfo(cardVaultUsdcAccount, this.connection.commitment);
|
|
240
|
+
if (!cardVaultUsdcAccountInfo) {
|
|
241
|
+
ixs.push(createAssociatedTokenAccountInstruction(zicOwner, cardVaultUsdcAccount, cardVault, usdcToken));
|
|
242
|
+
}
|
|
243
|
+
if (!revenueVault.equals(cardVault)) {
|
|
244
|
+
const revenueVaultUsdcAccount = getAssociatedTokenAddressSync(usdcToken, revenueVault, true);
|
|
245
|
+
const revenueVaultUsdcAccountInfo = await this.connection.getAccountInfo(revenueVaultUsdcAccount, this.connection.commitment);
|
|
246
|
+
if (!revenueVaultUsdcAccountInfo) {
|
|
247
|
+
ixs.push(createAssociatedTokenAccountInstruction(zicOwner, revenueVaultUsdcAccount, revenueVault, usdcToken));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (!commissionVault.equals(revenueVault) &&
|
|
251
|
+
!commissionVault.equals(cardVault)) {
|
|
252
|
+
const commissionVaultUsdcAccount = getAssociatedTokenAddressSync(usdcToken, commissionVault, true);
|
|
253
|
+
const commissionVaultUsdcAccountInfo = await this.connection.getAccountInfo(commissionVaultUsdcAccount, this.connection.commitment);
|
|
254
|
+
if (!commissionVaultUsdcAccountInfo) {
|
|
255
|
+
ixs.push(createAssociatedTokenAccountInstruction(zicOwner, commissionVaultUsdcAccount, commissionVault, usdcToken));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const payload = await this._createPayload(zicOwner, ixs, []);
|
|
259
|
+
return payload;
|
|
260
|
+
}
|
|
261
|
+
async setCustomFees(params) {
|
|
262
|
+
const { tokenFeeList, zicOwnerAddress } = params;
|
|
263
|
+
const zicOwner = zicOwnerAddress
|
|
264
|
+
? translateAddress(zicOwnerAddress)
|
|
265
|
+
: this.provider.publicKey;
|
|
266
|
+
if (!zicOwner) {
|
|
267
|
+
throw new Error("Either provide zicOwnerAddress or use provider with publicKey");
|
|
268
|
+
}
|
|
269
|
+
const parsedTokenFeeList = tokenFeeList.map((tokenFee) => ({
|
|
270
|
+
tokenAddress: translateAddress(tokenFee.tokenAddress),
|
|
271
|
+
fee: new BN(percentToBps(tokenFee.fee)),
|
|
272
|
+
}));
|
|
273
|
+
const ix = await this.getSetCustomFeesInstruction(zicOwner, parsedTokenFeeList);
|
|
274
|
+
return this._createPayload(zicOwner, [ix], []);
|
|
275
|
+
}
|
|
276
|
+
async deleteCustomFees(params) {
|
|
277
|
+
const { tokenAddressList, zicOwnerAddress } = params;
|
|
278
|
+
const zicOwner = zicOwnerAddress
|
|
279
|
+
? translateAddress(zicOwnerAddress)
|
|
280
|
+
: this.provider.publicKey;
|
|
281
|
+
if (!zicOwner) {
|
|
282
|
+
throw new Error("Either provide zicOwnerAddress or use provider with publicKey");
|
|
283
|
+
}
|
|
284
|
+
const tokenList = tokenAddressList.map((tokenAddress) => translateAddress(tokenAddress));
|
|
285
|
+
const ix = await this.getDeleteCustomFeesInstruction(zicOwner, tokenList);
|
|
286
|
+
return this._createPayload(zicOwner, [ix], []);
|
|
287
|
+
}
|
|
288
|
+
async getCardConfigInfo() {
|
|
289
|
+
const [cardConfig] = deriveCardConfigPda(this.program.programId);
|
|
290
|
+
const decoded = await this.program.account.card.fetch(cardConfig, this.connection.commitment);
|
|
291
|
+
const providerConfig = {
|
|
292
|
+
minCardAmount: BigNumber(decoded.providerConfig.minCardAmount.toString())
|
|
293
|
+
.div(UNITS_PER_USDC)
|
|
294
|
+
.toFixed(),
|
|
295
|
+
maxCardAmount: BigNumber(decoded.providerConfig.maxCardAmount.toString())
|
|
296
|
+
.div(UNITS_PER_USDC)
|
|
297
|
+
.toFixed(),
|
|
298
|
+
feeTiers: decoded.providerConfig.feeTiers.tiers.map((feeTier) => {
|
|
299
|
+
const feePercent = bpsToPercent(feeTier.fee.toNumber());
|
|
300
|
+
const minAmount = BigNumber(feeTier.minAmount.toString())
|
|
301
|
+
.div(UNITS_PER_USDC)
|
|
302
|
+
.toFixed();
|
|
303
|
+
const maxAmount = BigNumber(feeTier.maxAmount.toString())
|
|
304
|
+
.div(UNITS_PER_USDC)
|
|
305
|
+
.toFixed();
|
|
306
|
+
return {
|
|
307
|
+
feePercent,
|
|
308
|
+
minAmount,
|
|
309
|
+
maxAmount,
|
|
310
|
+
};
|
|
311
|
+
}),
|
|
312
|
+
};
|
|
313
|
+
const totalCardSold = BigNumber(decoded.totalBought.toString())
|
|
314
|
+
.div(UNITS_PER_USDC)
|
|
315
|
+
.toFixed();
|
|
316
|
+
const dailyCardPurchaseLimit = BigNumber(decoded.dailyCardBuyLimit.toString())
|
|
317
|
+
.div(UNITS_PER_USDC)
|
|
318
|
+
.toFixed();
|
|
319
|
+
return {
|
|
320
|
+
address: cardConfig,
|
|
321
|
+
index: BigInt(decoded.index.toString()),
|
|
322
|
+
revenueFeePercent: bpsToPercent(decoded.revenueFee.toNumber()),
|
|
323
|
+
nativeFeePercent: bpsToPercent(decoded.nativeFee.toNumber()),
|
|
324
|
+
nonNativeFeePercent: bpsToPercent(decoded.nonNativeFee.toNumber()),
|
|
325
|
+
usdcMint: decoded.usdcMint,
|
|
326
|
+
zicOwner: decoded.zicOwner,
|
|
327
|
+
cardVault: decoded.cardVault,
|
|
328
|
+
revenueVault: decoded.revenueVault,
|
|
329
|
+
commissionVault: decoded.commissionVault,
|
|
330
|
+
dailyCardPurchaseLimit,
|
|
331
|
+
totalCardSold,
|
|
332
|
+
providerConfig,
|
|
333
|
+
carbonFeePercent: bpsToPercent(decoded.carbonFee.toNumber()),
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
async getCardPurchaseInfo(cardPurchasePda) {
|
|
337
|
+
const decoded = await this.program.account.cardPurchase.fetch(cardPurchasePda, this.connection.commitment);
|
|
338
|
+
const amount = BigNumber(decoded.amount.toString())
|
|
339
|
+
.div(UNITS_PER_USDC)
|
|
340
|
+
.toFixed();
|
|
341
|
+
return {
|
|
342
|
+
address: cardPurchasePda,
|
|
343
|
+
amount,
|
|
344
|
+
buyerAddress: decoded.buyerAddress,
|
|
345
|
+
index: BigInt(decoded.index.toString()),
|
|
346
|
+
purchaseAt: decoded.purchaseAt.toNumber(),
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
async getUserPurchaseRecord(userPurchaseRecordPda) {
|
|
350
|
+
const decoded = await this.program.account.userPurchaseRecord.fetch(userPurchaseRecordPda, this.connection.commitment);
|
|
351
|
+
const totalCardBoughtPerDay = BigNumber(decoded.totalBoughtPerDay.toString())
|
|
352
|
+
.div(UNITS_PER_USDC)
|
|
353
|
+
.toFixed();
|
|
354
|
+
return {
|
|
355
|
+
address: userPurchaseRecordPda,
|
|
356
|
+
owner: decoded.userAddress,
|
|
357
|
+
lastCardBoughtTimestamp: decoded.dateTimeInUnix.toNumber(),
|
|
358
|
+
totalCardBoughtPerDay,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
async getCustomTokenFees() {
|
|
362
|
+
const [tokeFeeMapPda] = deriveTokenFeeMapPda(this.programId);
|
|
363
|
+
const decoded = await this.program.account.customFeeMap.fetch(tokeFeeMapPda, this.connection.commitment);
|
|
364
|
+
const tokenFeeList = decoded.feeMap.map((item) => ({
|
|
365
|
+
tokenAddress: item.tokenAddress,
|
|
366
|
+
fee: bpsToPercent(item.fee.toNumber()),
|
|
367
|
+
}));
|
|
368
|
+
return tokenFeeList;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
export class ZebecSolanaPartnerAdminCardService {
|
|
372
|
+
partnershipName;
|
|
373
|
+
provider;
|
|
374
|
+
network;
|
|
375
|
+
program;
|
|
376
|
+
constructor(partnershipName, provider, network, program) {
|
|
377
|
+
this.partnershipName = partnershipName;
|
|
378
|
+
this.provider = provider;
|
|
379
|
+
this.network = network;
|
|
380
|
+
this.program = program;
|
|
381
|
+
}
|
|
382
|
+
static create(partnershipName, provider, network) {
|
|
383
|
+
const connection = provider.connection;
|
|
384
|
+
const rpcEndpoint = connection.rpcEndpoint;
|
|
385
|
+
const connNetwork = rpcEndpoint.includes("devnet")
|
|
386
|
+
? "devnet"
|
|
387
|
+
: rpcEndpoint.includes("testnet")
|
|
388
|
+
? "testnet"
|
|
389
|
+
: "mainnet-beta";
|
|
390
|
+
if (connNetwork === "testnet") {
|
|
391
|
+
throw new Error("InvalidOperation: Testnet is not supported. Please use connection with devnet or mainnet-beta network.");
|
|
392
|
+
}
|
|
393
|
+
if (network !== connNetwork) {
|
|
394
|
+
throw new Error(`InvalidOperation: Network mismatch. network and connection network should be same. network: ${network}, connection: ${connNetwork}`);
|
|
395
|
+
}
|
|
396
|
+
const program = new Program(ZEBEC_CARD_V2_IDL, provider);
|
|
397
|
+
return new ZebecSolanaPartnerAdminCardService(partnershipName, provider, network, program);
|
|
398
|
+
}
|
|
399
|
+
async _createPayload(payerKey, instructions, signers, addressLookupTableAccounts) {
|
|
400
|
+
const errorMap = new Map();
|
|
401
|
+
this.program.idl.errors.map((error) => errorMap.set(error.code, error.msg));
|
|
402
|
+
const provider = this.provider;
|
|
403
|
+
let signTransaction;
|
|
404
|
+
if (provider instanceof AnchorProvider) {
|
|
405
|
+
signTransaction = async (tx) => {
|
|
406
|
+
return provider.wallet.signTransaction(tx);
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
return new TransactionPayload(this.connection, errorMap, {
|
|
410
|
+
instructions,
|
|
411
|
+
feePayer: payerKey,
|
|
412
|
+
signers: signers ?? [],
|
|
413
|
+
addressLookupTableAccounts: addressLookupTableAccounts ?? [],
|
|
414
|
+
}, signTransaction);
|
|
415
|
+
}
|
|
416
|
+
get connection() {
|
|
417
|
+
return this.provider.connection;
|
|
418
|
+
}
|
|
419
|
+
get programId() {
|
|
420
|
+
return this.program.programId;
|
|
421
|
+
}
|
|
422
|
+
async getInitPartnerCardConfigsInstruction(usdcToken, zicOwner, data) {
|
|
423
|
+
const { cardVault, revenueVault, maxCardAmount, minCardAmount, feeTiers, dailyCardPurchaseLimit, partnershipName, carbonFee, } = data;
|
|
424
|
+
const [cardPda] = derivePartnerCardConfigPda(this.programId, partnershipName);
|
|
425
|
+
return this.program.methods
|
|
426
|
+
.initPartnerCardConfigs({
|
|
427
|
+
cardVault,
|
|
428
|
+
revenueVault,
|
|
429
|
+
maxCardAmount,
|
|
430
|
+
minCardAmount,
|
|
431
|
+
feeTier: feeTiers,
|
|
432
|
+
dailyCardBuyLimit: dailyCardPurchaseLimit,
|
|
433
|
+
carbonFee,
|
|
434
|
+
partnershipName,
|
|
435
|
+
})
|
|
436
|
+
.accountsPartial({
|
|
437
|
+
usdcToken,
|
|
438
|
+
zicOwner,
|
|
439
|
+
cardPda,
|
|
440
|
+
})
|
|
441
|
+
.instruction();
|
|
442
|
+
}
|
|
443
|
+
async getSetPartnerCardConfigsInstruction(zicOwner, data) {
|
|
444
|
+
const { cardVault, revenueVault, feeTiers, maxCardAmount, minCardAmount, dailyCardPurchaseLimit, newZicOwner, carbonFee, partnershipName, } = data;
|
|
445
|
+
const [cardPda] = derivePartnerCardConfigPda(this.programId, partnershipName);
|
|
446
|
+
return this.program.methods
|
|
447
|
+
.setPartnerCardConfigs({
|
|
448
|
+
zicOwner: newZicOwner,
|
|
449
|
+
cardVault,
|
|
450
|
+
revenueVault,
|
|
451
|
+
maxCardAmount,
|
|
452
|
+
minCardAmount,
|
|
453
|
+
dailyCardBuyLimit: dailyCardPurchaseLimit,
|
|
454
|
+
feeTier: feeTiers,
|
|
455
|
+
carbonFee,
|
|
456
|
+
})
|
|
457
|
+
.accountsPartial({
|
|
458
|
+
zicOwner,
|
|
459
|
+
cardPda,
|
|
460
|
+
})
|
|
461
|
+
.instruction();
|
|
462
|
+
}
|
|
463
|
+
async getSetPartnerCustomFeesInstruction(zicOwner, partnershipName, tokenFeeList) {
|
|
464
|
+
const [cardPda] = derivePartnerCardConfigPda(this.programId, partnershipName);
|
|
465
|
+
const [feeMapPda] = derivePartnerTokenFeeMapPda(cardPda, this.programId);
|
|
466
|
+
return this.program.methods
|
|
467
|
+
.setPartnerCustomFees({
|
|
468
|
+
customFeeMap: tokenFeeList,
|
|
469
|
+
})
|
|
470
|
+
.accountsPartial({
|
|
471
|
+
zicOwner,
|
|
472
|
+
cardPda,
|
|
473
|
+
feeMapPda,
|
|
474
|
+
})
|
|
475
|
+
.instruction();
|
|
476
|
+
}
|
|
477
|
+
async getDeletePartnerCustomFeesInstruction(zicOwner, data) {
|
|
478
|
+
const { tokenList, partnershipName } = data;
|
|
479
|
+
const [cardPda] = derivePartnerCardConfigPda(this.programId, partnershipName);
|
|
480
|
+
const [feeMapPda] = derivePartnerTokenFeeMapPda(cardPda, this.programId);
|
|
481
|
+
return this.program.methods
|
|
482
|
+
.deletePartnerCustomFees({
|
|
483
|
+
customFeeMap: tokenList,
|
|
484
|
+
})
|
|
485
|
+
.accountsPartial({
|
|
486
|
+
zicOwner,
|
|
487
|
+
cardPda,
|
|
488
|
+
feeMapPda,
|
|
489
|
+
})
|
|
490
|
+
.instruction();
|
|
491
|
+
}
|
|
492
|
+
async initPartnerCardConfig(params) {
|
|
493
|
+
const { zicOwnerAddress, cardVaultAddress, revenueVaultAddress, usdcAddress, } = params;
|
|
494
|
+
const zicOwner = zicOwnerAddress
|
|
495
|
+
? translateAddress(zicOwnerAddress)
|
|
496
|
+
: this.provider.publicKey;
|
|
497
|
+
if (!zicOwner) {
|
|
498
|
+
throw new Error("Either provide zicOwnerAddress or use provider with publicKey");
|
|
499
|
+
}
|
|
500
|
+
const usdcToken = translateAddress(usdcAddress);
|
|
501
|
+
const cardVault = translateAddress(cardVaultAddress);
|
|
502
|
+
const revenueVault = translateAddress(revenueVaultAddress);
|
|
503
|
+
const carbonFee = new BN(percentToBps(params.carbonFeePercent));
|
|
504
|
+
const maxCardAmount = new BN(BigNumber(params.maxCardAmount).times(UNITS_PER_USDC).toFixed(0));
|
|
505
|
+
const minCardAmount = new BN(BigNumber(params.minCardAmount).times(UNITS_PER_USDC).toFixed(0));
|
|
506
|
+
const dailyCardPurchaseLimit = new BN(BigNumber(params.dailyCardPurchaseLimit).times(UNITS_PER_USDC).toFixed(0));
|
|
507
|
+
const feeTiers = params.feeTiers.map((feeTier) => {
|
|
508
|
+
const minAmount = new BN(BigNumber(feeTier.minAmount).times(UNITS_PER_USDC).toFixed(0));
|
|
509
|
+
const maxAmount = new BN(BigNumber(feeTier.maxAmount).times(UNITS_PER_USDC).toFixed(0));
|
|
510
|
+
const fee = new BN(percentToBps(feeTier.feePercent));
|
|
511
|
+
return {
|
|
512
|
+
minAmount,
|
|
513
|
+
maxAmount,
|
|
514
|
+
fee,
|
|
515
|
+
};
|
|
516
|
+
});
|
|
517
|
+
feeTiers.sort((a, b) => b.minAmount.cmp(a.minAmount));
|
|
518
|
+
const ixs = [];
|
|
519
|
+
const ix = await this.getInitPartnerCardConfigsInstruction(usdcToken, zicOwner, {
|
|
520
|
+
revenueVault,
|
|
521
|
+
cardVault,
|
|
522
|
+
feeTiers,
|
|
523
|
+
maxCardAmount,
|
|
524
|
+
minCardAmount,
|
|
525
|
+
dailyCardPurchaseLimit,
|
|
526
|
+
carbonFee,
|
|
527
|
+
partnershipName: this.partnershipName,
|
|
528
|
+
});
|
|
529
|
+
ixs.push(ix);
|
|
530
|
+
const cardVaultUsdcAccount = getAssociatedTokenAddressSync(usdcToken, cardVault, true);
|
|
531
|
+
const cardVaultUsdcAccountInfo = await this.connection.getAccountInfo(cardVaultUsdcAccount, this.connection.commitment);
|
|
532
|
+
if (!cardVaultUsdcAccountInfo) {
|
|
533
|
+
ixs.push(createAssociatedTokenAccountInstruction(zicOwner, cardVaultUsdcAccount, cardVault, usdcToken));
|
|
534
|
+
}
|
|
535
|
+
if (!revenueVault.equals(cardVault)) {
|
|
536
|
+
const revenueVaultUsdcAccount = getAssociatedTokenAddressSync(usdcToken, revenueVault, true);
|
|
537
|
+
const revenueVaultUsdcAccountInfo = await this.connection.getAccountInfo(revenueVaultUsdcAccount, this.connection.commitment);
|
|
538
|
+
if (!revenueVaultUsdcAccountInfo) {
|
|
539
|
+
ixs.push(createAssociatedTokenAccountInstruction(zicOwner, revenueVaultUsdcAccount, revenueVault, usdcToken));
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
const payload = await this._createPayload(zicOwner, ixs, []);
|
|
543
|
+
return payload;
|
|
544
|
+
}
|
|
545
|
+
async setPartnerCardConfig(params) {
|
|
546
|
+
const { zicOwnerAddress, newZicOwnerAddress, cardVaultAddress, revenueVaultAddress, } = params;
|
|
547
|
+
const zicOwner = zicOwnerAddress
|
|
548
|
+
? translateAddress(zicOwnerAddress)
|
|
549
|
+
: this.provider.publicKey;
|
|
550
|
+
if (!zicOwner) {
|
|
551
|
+
throw new Error("Either provide zicOwnerAddress or use provider with publicKey");
|
|
552
|
+
}
|
|
553
|
+
const newZicOwner = translateAddress(newZicOwnerAddress);
|
|
554
|
+
const cardVault = translateAddress(cardVaultAddress);
|
|
555
|
+
const revenueVault = translateAddress(revenueVaultAddress);
|
|
556
|
+
const [cardConfig] = derivePartnerCardConfigPda(this.program.programId, this.partnershipName);
|
|
557
|
+
const cardConfigInfo = await this.program.account.cardPartner.fetch(cardConfig, "confirmed");
|
|
558
|
+
if (!zicOwner.equals(cardConfigInfo.zicOwner)) {
|
|
559
|
+
throw new Error("Invalid owner of the config.");
|
|
560
|
+
}
|
|
561
|
+
const usdcToken = cardConfigInfo.usdcMint;
|
|
562
|
+
const carbonFee = new BN(percentToBps(params.carbonFeePercent));
|
|
563
|
+
const maxCardAmount = new BN(BigNumber(params.maxCardAmount).times(UNITS_PER_USDC).toFixed(0));
|
|
564
|
+
const minCardAmount = new BN(BigNumber(params.minCardAmount).times(UNITS_PER_USDC).toFixed(0));
|
|
565
|
+
const dailyCardPurchaseLimit = new BN(BigNumber(params.dailyCardPurchaseLimit).times(UNITS_PER_USDC).toFixed(0));
|
|
566
|
+
const feeTiers = params.feeTiers.map((feeTier) => {
|
|
567
|
+
const minAmount = new BN(BigNumber(feeTier.minAmount).times(UNITS_PER_USDC).toFixed(0));
|
|
568
|
+
const maxAmount = new BN(BigNumber(feeTier.maxAmount).times(UNITS_PER_USDC).toFixed(0));
|
|
569
|
+
const fee = new BN(percentToBps(feeTier.feePercent));
|
|
570
|
+
return {
|
|
571
|
+
minAmount,
|
|
572
|
+
maxAmount,
|
|
573
|
+
fee,
|
|
574
|
+
};
|
|
575
|
+
});
|
|
576
|
+
feeTiers.sort((a, b) => b.minAmount.cmp(a.minAmount));
|
|
577
|
+
const ixs = [];
|
|
578
|
+
const ix = await this.getSetPartnerCardConfigsInstruction(zicOwner, {
|
|
579
|
+
newZicOwner,
|
|
580
|
+
cardVault,
|
|
581
|
+
revenueVault,
|
|
582
|
+
feeTiers,
|
|
583
|
+
maxCardAmount,
|
|
584
|
+
minCardAmount,
|
|
585
|
+
dailyCardPurchaseLimit,
|
|
586
|
+
carbonFee,
|
|
587
|
+
partnershipName: this.partnershipName,
|
|
588
|
+
});
|
|
589
|
+
ixs.push(ix);
|
|
590
|
+
const cardVaultUsdcAccount = getAssociatedTokenAddressSync(usdcToken, cardVault, true);
|
|
591
|
+
const cardVaultUsdcAccountInfo = await this.connection.getAccountInfo(cardVaultUsdcAccount, this.connection.commitment);
|
|
592
|
+
if (!cardVaultUsdcAccountInfo) {
|
|
593
|
+
ixs.push(createAssociatedTokenAccountInstruction(zicOwner, cardVaultUsdcAccount, cardVault, usdcToken));
|
|
594
|
+
}
|
|
595
|
+
if (!revenueVault.equals(cardVault)) {
|
|
596
|
+
const revenueVaultUsdcAccount = getAssociatedTokenAddressSync(usdcToken, revenueVault, true);
|
|
597
|
+
const revenueVaultUsdcAccountInfo = await this.connection.getAccountInfo(revenueVaultUsdcAccount, this.connection.commitment);
|
|
598
|
+
if (!revenueVaultUsdcAccountInfo) {
|
|
599
|
+
ixs.push(createAssociatedTokenAccountInstruction(zicOwner, revenueVaultUsdcAccount, revenueVault, usdcToken));
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
const payload = await this._createPayload(zicOwner, ixs, []);
|
|
603
|
+
return payload;
|
|
604
|
+
}
|
|
605
|
+
async setPartnerCustomFees(params) {
|
|
606
|
+
const { tokenFeeList, zicOwnerAddress } = params;
|
|
607
|
+
const zicOwner = zicOwnerAddress
|
|
608
|
+
? translateAddress(zicOwnerAddress)
|
|
609
|
+
: this.provider.publicKey;
|
|
610
|
+
if (!zicOwner) {
|
|
611
|
+
throw new Error("Either provide zicOwnerAddress or use provider with publicKey");
|
|
612
|
+
}
|
|
613
|
+
const parsedTokenFeeList = tokenFeeList.map((tokenFee) => ({
|
|
614
|
+
tokenAddress: translateAddress(tokenFee.tokenAddress),
|
|
615
|
+
fee: new BN(percentToBps(tokenFee.fee)),
|
|
616
|
+
}));
|
|
617
|
+
const ix = await this.getSetPartnerCustomFeesInstruction(zicOwner, this.partnershipName, parsedTokenFeeList);
|
|
618
|
+
return this._createPayload(zicOwner, [ix], []);
|
|
619
|
+
}
|
|
620
|
+
async deletePartnerCustomFees(params) {
|
|
621
|
+
const { tokenAddressList, zicOwnerAddress } = params;
|
|
622
|
+
const zicOwner = zicOwnerAddress
|
|
623
|
+
? translateAddress(zicOwnerAddress)
|
|
624
|
+
: this.provider.publicKey;
|
|
625
|
+
if (!zicOwner) {
|
|
626
|
+
throw new Error("Either provide zicOwnerAddress or use provider with publicKey");
|
|
627
|
+
}
|
|
628
|
+
const tokenList = tokenAddressList.map((tokenAddress) => translateAddress(tokenAddress));
|
|
629
|
+
const ix = await this.getDeletePartnerCustomFeesInstruction(zicOwner, {
|
|
630
|
+
tokenList,
|
|
631
|
+
partnershipName: this.partnershipName,
|
|
632
|
+
});
|
|
633
|
+
return this._createPayload(zicOwner, [ix], []);
|
|
634
|
+
}
|
|
635
|
+
async getPartnerCardConfigInfo() {
|
|
636
|
+
const [cardPda] = derivePartnerCardConfigPda(this.program.programId, this.partnershipName);
|
|
637
|
+
console.debug("cardPda", cardPda.toString());
|
|
638
|
+
const decoded = await this.program.account.cardPartner.fetch(cardPda, this.connection.commitment);
|
|
639
|
+
const providerConfig = {
|
|
640
|
+
minCardAmount: BigNumber(decoded.providerConfig.minCardAmount.toString())
|
|
641
|
+
.div(UNITS_PER_USDC)
|
|
642
|
+
.toFixed(),
|
|
643
|
+
maxCardAmount: BigNumber(decoded.providerConfig.maxCardAmount.toString())
|
|
644
|
+
.div(UNITS_PER_USDC)
|
|
645
|
+
.toFixed(),
|
|
646
|
+
feeTiers: decoded.providerConfig.feeTiers.tiers.map((feeTier) => {
|
|
647
|
+
const feePercent = bpsToPercent(feeTier.fee.toNumber());
|
|
648
|
+
const minAmount = BigNumber(feeTier.minAmount.toString())
|
|
649
|
+
.div(UNITS_PER_USDC)
|
|
650
|
+
.toFixed();
|
|
651
|
+
const maxAmount = BigNumber(feeTier.maxAmount.toString())
|
|
652
|
+
.div(UNITS_PER_USDC)
|
|
653
|
+
.toFixed();
|
|
654
|
+
return {
|
|
655
|
+
feePercent,
|
|
656
|
+
minAmount,
|
|
657
|
+
maxAmount,
|
|
658
|
+
};
|
|
659
|
+
}),
|
|
660
|
+
};
|
|
661
|
+
const totalCardSold = BigNumber(decoded.totalBought.toString())
|
|
662
|
+
.div(UNITS_PER_USDC)
|
|
663
|
+
.toFixed();
|
|
664
|
+
const dailyCardPurchaseLimit = BigNumber(decoded.dailyCardBuyLimit.toString())
|
|
665
|
+
.div(UNITS_PER_USDC)
|
|
666
|
+
.toFixed();
|
|
667
|
+
const partnerName = decoded.partnershipName;
|
|
668
|
+
return {
|
|
669
|
+
address: cardPda,
|
|
670
|
+
partnerName: partnerName,
|
|
671
|
+
index: BigInt(decoded.index.toString()),
|
|
672
|
+
usdcMint: decoded.usdcMint,
|
|
673
|
+
zicOwner: decoded.zicOwner,
|
|
674
|
+
cardVault: decoded.cardVault,
|
|
675
|
+
revenueVault: decoded.revenueVault,
|
|
676
|
+
dailyCardPurchaseLimit,
|
|
677
|
+
totalCardSold,
|
|
678
|
+
providerConfig,
|
|
679
|
+
carbonFeePercent: bpsToPercent(decoded.carbonFee.toNumber()),
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
async getPartnerCustomTokenFees() {
|
|
683
|
+
const [cardPda] = derivePartnerCardConfigPda(this.programId, this.partnershipName);
|
|
684
|
+
const [tokeFeeMapPda] = derivePartnerTokenFeeMapPda(cardPda, this.programId);
|
|
685
|
+
const decoded = await this.program.account.customFeeMap.fetch(tokeFeeMapPda, this.connection.commitment);
|
|
686
|
+
const tokenFeeList = decoded.feeMap.map((item) => ({
|
|
687
|
+
tokenAddress: item.tokenAddress,
|
|
688
|
+
fee: bpsToPercent(item.fee.toNumber()),
|
|
689
|
+
}));
|
|
690
|
+
return tokenFeeList;
|
|
691
|
+
}
|
|
692
|
+
async getCardPurchaseInfo(cardPurchasePda) {
|
|
693
|
+
const decoded = await this.program.account.cardPurchase.fetch(cardPurchasePda, this.connection.commitment);
|
|
694
|
+
const amount = BigNumber(decoded.amount.toString())
|
|
695
|
+
.div(UNITS_PER_USDC)
|
|
696
|
+
.toFixed();
|
|
697
|
+
return {
|
|
698
|
+
address: cardPurchasePda,
|
|
699
|
+
amount,
|
|
700
|
+
buyerAddress: decoded.buyerAddress,
|
|
701
|
+
index: BigInt(decoded.index.toString()),
|
|
702
|
+
purchaseAt: decoded.purchaseAt.toNumber(),
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
async getPartnerUserPurchaseRecord(userPurchaseRecordPda) {
|
|
706
|
+
const decoded = await this.program.account.userPurchaseRecord.fetch(userPurchaseRecordPda, this.connection.commitment);
|
|
707
|
+
const totalCardBoughtPerDay = BigNumber(decoded.totalBoughtPerDay.toString())
|
|
708
|
+
.div(UNITS_PER_USDC)
|
|
709
|
+
.toFixed();
|
|
710
|
+
return {
|
|
711
|
+
address: userPurchaseRecordPda,
|
|
712
|
+
owner: decoded.userAddress,
|
|
713
|
+
lastCardBoughtTimestamp: decoded.dateTimeInUnix.toNumber(),
|
|
714
|
+
totalCardBoughtPerDay,
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
}
|