@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,91 @@
|
|
|
1
|
+
import type { ClientWithCoreApi, SuiClientTypes } from "@mysten/sui/client";
|
|
2
|
+
import type { Signer } from "@mysten/sui/cryptography";
|
|
3
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
4
|
+
import type { DecimalString, Percent, SuiAddress, SuiCardConfig, SuiFeeTierList, SuiNetwork, SuiSwapFeeList, WalletInterface } from "../types.js";
|
|
5
|
+
export declare class SuiSilverCardPackageInfo {
|
|
6
|
+
readonly network: SuiNetwork;
|
|
7
|
+
readonly address: string;
|
|
8
|
+
readonly module: string;
|
|
9
|
+
constructor(network: SuiNetwork);
|
|
10
|
+
}
|
|
11
|
+
export declare class SuiTransactionPayload {
|
|
12
|
+
private readonly _suiClient;
|
|
13
|
+
readonly transaction: Transaction;
|
|
14
|
+
readonly wallet: WalletInterface;
|
|
15
|
+
constructor(_suiClient: ClientWithCoreApi, transaction: Transaction, wallet: WalletInterface);
|
|
16
|
+
execute(options?: {
|
|
17
|
+
signer?: Signer;
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
}): Promise<SuiClientTypes.TransactionResult<object>>;
|
|
20
|
+
}
|
|
21
|
+
export declare class SuiCardAdminService {
|
|
22
|
+
readonly packageInfo: SuiSilverCardPackageInfo;
|
|
23
|
+
readonly suiClient: ClientWithCoreApi;
|
|
24
|
+
readonly adminCapObjectId: SuiAddress;
|
|
25
|
+
readonly cardConfigObjectId: SuiAddress;
|
|
26
|
+
readonly feeTierListObjectId: SuiAddress;
|
|
27
|
+
readonly swapFeeListObjectId: SuiAddress;
|
|
28
|
+
readonly usdcCoinType: string;
|
|
29
|
+
readonly usdcCoinMetadata: SuiClientTypes.CoinMetadata;
|
|
30
|
+
readonly wallet: WalletInterface;
|
|
31
|
+
constructor(packageInfo: SuiSilverCardPackageInfo, suiClient: ClientWithCoreApi, adminCapObjectId: SuiAddress, cardConfigObjectId: SuiAddress, feeTierListObjectId: SuiAddress, swapFeeListObjectId: SuiAddress, usdcCoinType: string, usdcCoinMetadata: SuiClientTypes.CoinMetadata, wallet: WalletInterface);
|
|
32
|
+
static create(packageInfo: SuiSilverCardPackageInfo, suiClient: ClientWithCoreApi, wallet: WalletInterface): Promise<SuiCardAdminService>;
|
|
33
|
+
getCardConfig(): Promise<SuiCardConfig>;
|
|
34
|
+
getFeeTierList(): Promise<SuiFeeTierList>;
|
|
35
|
+
getSwapFeeList(): Promise<SuiSwapFeeList>;
|
|
36
|
+
setNativeFee(params: {
|
|
37
|
+
feePercent: number;
|
|
38
|
+
}): Promise<SuiTransactionPayload>;
|
|
39
|
+
setNonNativeFee(params: {
|
|
40
|
+
feePercent: number;
|
|
41
|
+
}): Promise<SuiTransactionPayload>;
|
|
42
|
+
setRevenueVault(params: {
|
|
43
|
+
vaultAddress: string;
|
|
44
|
+
}): Promise<SuiTransactionPayload>;
|
|
45
|
+
setUsdcAddress(params: {
|
|
46
|
+
usdcAddress: string;
|
|
47
|
+
}): Promise<SuiTransactionPayload>;
|
|
48
|
+
setCardVault(params: {
|
|
49
|
+
vaultAddress: string;
|
|
50
|
+
}): Promise<SuiTransactionPayload>;
|
|
51
|
+
setRevenueFee(params: {
|
|
52
|
+
feePercent: number;
|
|
53
|
+
}): Promise<SuiTransactionPayload>;
|
|
54
|
+
setMinCardAmount(params: {
|
|
55
|
+
minCardAmount: string;
|
|
56
|
+
}): Promise<SuiTransactionPayload>;
|
|
57
|
+
setMaxCardAmount(params: {
|
|
58
|
+
maxCardAmount: string;
|
|
59
|
+
}): Promise<SuiTransactionPayload>;
|
|
60
|
+
setDailyLimit(params: {
|
|
61
|
+
dailyLimit: string;
|
|
62
|
+
}): Promise<SuiTransactionPayload>;
|
|
63
|
+
addFeeTier(params: {
|
|
64
|
+
minAmount: DecimalString;
|
|
65
|
+
maxAmount: DecimalString;
|
|
66
|
+
fee: Percent;
|
|
67
|
+
}): Promise<SuiTransactionPayload>;
|
|
68
|
+
updateFeeTier(params: {
|
|
69
|
+
minAmount: DecimalString;
|
|
70
|
+
maxAmount: DecimalString;
|
|
71
|
+
fee: Percent;
|
|
72
|
+
}): Promise<SuiTransactionPayload>;
|
|
73
|
+
removeFeeTier(params: {
|
|
74
|
+
minAmount: DecimalString;
|
|
75
|
+
maxAmount: DecimalString;
|
|
76
|
+
}): Promise<SuiTransactionPayload>;
|
|
77
|
+
getFeeForAmount(params: {
|
|
78
|
+
amount: DecimalString;
|
|
79
|
+
}): Promise<SuiTransactionPayload>;
|
|
80
|
+
addSwapFee(params: {
|
|
81
|
+
tokenType: string;
|
|
82
|
+
fee: number;
|
|
83
|
+
}): Promise<SuiTransactionPayload>;
|
|
84
|
+
updateSwapFee(params: {
|
|
85
|
+
tokenType: string;
|
|
86
|
+
fee: number;
|
|
87
|
+
}): Promise<SuiTransactionPayload>;
|
|
88
|
+
removeSwapFee(params: {
|
|
89
|
+
tokenType: string;
|
|
90
|
+
}): Promise<SuiTransactionPayload>;
|
|
91
|
+
}
|
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
3
|
+
import { fromBase64, isValidSuiAddress, toBase64 } from "@mysten/sui/utils";
|
|
4
|
+
import { bpsToPercent, percentToBps } from "@zebec-network/core-utils";
|
|
5
|
+
import { TEN_BIGNUM } from "@zebec-network/solana-common";
|
|
6
|
+
import { SUI_SILVERCARD_ADMIN_CAP_STRUCT_TYPE, SUI_SILVERCARD_CARD_CONFIG_OBJECT_ID, SUI_SILVERCARD_FEE_TIER_LIST_OBJECT_ID, SUI_SILVERCARD_MODULE_NAME, SUI_SILVERCARD_PACKAGE_ADDRESS, SUI_SILVERCARD_SWAP_FEE_LIST_OBJECT_ID, SUI_USDC_COIN_TYPE, } from "../constants.js";
|
|
7
|
+
import { createSuiSignTransactionMethodFromSigner } from "../utils.js";
|
|
8
|
+
export class SuiSilverCardPackageInfo {
|
|
9
|
+
network;
|
|
10
|
+
address;
|
|
11
|
+
module;
|
|
12
|
+
constructor(network) {
|
|
13
|
+
this.network = network;
|
|
14
|
+
this.address = SUI_SILVERCARD_PACKAGE_ADDRESS[network];
|
|
15
|
+
this.module = SUI_SILVERCARD_MODULE_NAME;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class SuiTransactionPayload {
|
|
19
|
+
_suiClient;
|
|
20
|
+
transaction;
|
|
21
|
+
wallet;
|
|
22
|
+
constructor(_suiClient, transaction, wallet) {
|
|
23
|
+
this._suiClient = _suiClient;
|
|
24
|
+
this.transaction = transaction;
|
|
25
|
+
this.wallet = wallet;
|
|
26
|
+
}
|
|
27
|
+
async execute(options) {
|
|
28
|
+
const transaction = await this.transaction.build({
|
|
29
|
+
client: this._suiClient,
|
|
30
|
+
});
|
|
31
|
+
const signTransaction = this.wallet.signTransaction
|
|
32
|
+
? this.wallet.signTransaction
|
|
33
|
+
: options?.signer
|
|
34
|
+
? createSuiSignTransactionMethodFromSigner(options.signer)
|
|
35
|
+
: undefined;
|
|
36
|
+
if (!signTransaction) {
|
|
37
|
+
throw new Error("Both signTransaction and signer is undefined.");
|
|
38
|
+
}
|
|
39
|
+
const { signature, bytes } = await signTransaction({
|
|
40
|
+
transaction: toBase64(transaction),
|
|
41
|
+
});
|
|
42
|
+
const result = await this._suiClient.core.executeTransaction({
|
|
43
|
+
transaction: fromBase64(bytes),
|
|
44
|
+
signatures: [signature],
|
|
45
|
+
signal: options?.signal,
|
|
46
|
+
include: {
|
|
47
|
+
effects: true,
|
|
48
|
+
transaction: true,
|
|
49
|
+
events: true,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
const res = await this._suiClient.core.waitForTransaction({
|
|
53
|
+
signal: options?.signal,
|
|
54
|
+
result,
|
|
55
|
+
});
|
|
56
|
+
return res;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export class SuiCardAdminService {
|
|
60
|
+
packageInfo;
|
|
61
|
+
suiClient;
|
|
62
|
+
adminCapObjectId;
|
|
63
|
+
cardConfigObjectId;
|
|
64
|
+
feeTierListObjectId;
|
|
65
|
+
swapFeeListObjectId;
|
|
66
|
+
usdcCoinType;
|
|
67
|
+
usdcCoinMetadata;
|
|
68
|
+
wallet;
|
|
69
|
+
constructor(packageInfo, suiClient, adminCapObjectId, cardConfigObjectId, feeTierListObjectId, swapFeeListObjectId, usdcCoinType, usdcCoinMetadata, wallet) {
|
|
70
|
+
this.packageInfo = packageInfo;
|
|
71
|
+
this.suiClient = suiClient;
|
|
72
|
+
this.adminCapObjectId = adminCapObjectId;
|
|
73
|
+
this.cardConfigObjectId = cardConfigObjectId;
|
|
74
|
+
this.feeTierListObjectId = feeTierListObjectId;
|
|
75
|
+
this.swapFeeListObjectId = swapFeeListObjectId;
|
|
76
|
+
this.usdcCoinType = usdcCoinType;
|
|
77
|
+
this.usdcCoinMetadata = usdcCoinMetadata;
|
|
78
|
+
this.wallet = wallet;
|
|
79
|
+
}
|
|
80
|
+
static async create(packageInfo, suiClient, wallet) {
|
|
81
|
+
const admin = wallet.address;
|
|
82
|
+
const response = await suiClient.core.listOwnedObjects({
|
|
83
|
+
owner: admin,
|
|
84
|
+
type: SUI_SILVERCARD_ADMIN_CAP_STRUCT_TYPE[packageInfo.network],
|
|
85
|
+
});
|
|
86
|
+
const { objects } = response;
|
|
87
|
+
// console.log("admin cap objects:", objects);
|
|
88
|
+
const [adminCapObject] = objects;
|
|
89
|
+
if (!adminCapObject || objects.length !== 1) {
|
|
90
|
+
throw new Error("Given wallet address does not own any admin cap object.");
|
|
91
|
+
}
|
|
92
|
+
const adminCapObjectId = adminCapObject.objectId;
|
|
93
|
+
const coinType = SUI_USDC_COIN_TYPE[packageInfo.network];
|
|
94
|
+
const coinMetadataResponse = await suiClient.core.getCoinMetadata({
|
|
95
|
+
coinType,
|
|
96
|
+
});
|
|
97
|
+
if (!coinMetadataResponse.coinMetadata) {
|
|
98
|
+
throw new Error("Could not fetch usdc coin metadata");
|
|
99
|
+
}
|
|
100
|
+
const cardConfigObjectId = SUI_SILVERCARD_CARD_CONFIG_OBJECT_ID[packageInfo.network];
|
|
101
|
+
const feeTierListObjectId = SUI_SILVERCARD_FEE_TIER_LIST_OBJECT_ID[packageInfo.network];
|
|
102
|
+
const swapFeeListObjectId = SUI_SILVERCARD_SWAP_FEE_LIST_OBJECT_ID[packageInfo.network];
|
|
103
|
+
return new SuiCardAdminService(packageInfo, suiClient, adminCapObjectId, cardConfigObjectId, feeTierListObjectId, swapFeeListObjectId, coinType, coinMetadataResponse.coinMetadata, wallet);
|
|
104
|
+
}
|
|
105
|
+
async getCardConfig() {
|
|
106
|
+
const usdcDecimals = this.usdcCoinMetadata.decimals;
|
|
107
|
+
const UNITS_PER_USDC = TEN_BIGNUM.pow(usdcDecimals);
|
|
108
|
+
const { object } = await this.suiClient.core.getObject({
|
|
109
|
+
objectId: this.cardConfigObjectId,
|
|
110
|
+
include: { json: true },
|
|
111
|
+
});
|
|
112
|
+
const json = object.json;
|
|
113
|
+
if (typeof json.admin !== "string")
|
|
114
|
+
throw new Error('Invalid card config: missing or invalid "admin"');
|
|
115
|
+
if (typeof json.card_vault !== "string")
|
|
116
|
+
throw new Error('Invalid card config: missing or invalid "card_vault"');
|
|
117
|
+
if (typeof json.daily_card_buy_limit !== "string")
|
|
118
|
+
throw new Error('Invalid card config: missing or invalid "daily_card_buy_limit"');
|
|
119
|
+
if (typeof json.max_card_amount !== "string")
|
|
120
|
+
throw new Error('Invalid card config: missing or invalid "max_card_amount"');
|
|
121
|
+
if (typeof json.min_card_amount !== "string")
|
|
122
|
+
throw new Error('Invalid card config: missing or invalid "min_card_amount"');
|
|
123
|
+
if (typeof json.native_fee !== "string")
|
|
124
|
+
throw new Error('Invalid card config: missing or invalid "native_fee"');
|
|
125
|
+
if (typeof json.non_native_fee !== "string")
|
|
126
|
+
throw new Error('Invalid card config: missing or invalid "non_native_fee"');
|
|
127
|
+
if (typeof json.revenue_fee !== "string")
|
|
128
|
+
throw new Error('Invalid card config: missing or invalid "revenue_fee"');
|
|
129
|
+
if (typeof json.revenue_vault !== "string")
|
|
130
|
+
throw new Error('Invalid card config: missing or invalid "revenue_vault"');
|
|
131
|
+
if (typeof json.version !== "string")
|
|
132
|
+
throw new Error('Invalid card config: missing or invalid "version"');
|
|
133
|
+
if (typeof json.usdc_address !== "string")
|
|
134
|
+
throw new Error('Invalid card config: missing or invalid "usdc_address"');
|
|
135
|
+
return {
|
|
136
|
+
admin: json.admin,
|
|
137
|
+
cardVault: json.card_vault,
|
|
138
|
+
dailyCardBuyLimit: BigNumber(json.daily_card_buy_limit)
|
|
139
|
+
.div(UNITS_PER_USDC)
|
|
140
|
+
.toFixed(),
|
|
141
|
+
id: object.objectId,
|
|
142
|
+
maxCardAmount: BigNumber(json.max_card_amount)
|
|
143
|
+
.div(UNITS_PER_USDC)
|
|
144
|
+
.toFixed(),
|
|
145
|
+
minCardAmount: BigNumber(json.min_card_amount)
|
|
146
|
+
.div(UNITS_PER_USDC)
|
|
147
|
+
.toFixed(),
|
|
148
|
+
nativeFee: bpsToPercent(json.native_fee),
|
|
149
|
+
nonNativeFee: bpsToPercent(json.non_native_fee),
|
|
150
|
+
revenueFee: bpsToPercent(json.revenue_fee),
|
|
151
|
+
revenueVault: json.revenue_vault,
|
|
152
|
+
version: json.version,
|
|
153
|
+
usdcAddress: json.usdc_address,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
async getFeeTierList() {
|
|
157
|
+
const usdcDecimals = this.usdcCoinMetadata.decimals;
|
|
158
|
+
const UNITS_PER_USDC = TEN_BIGNUM.pow(usdcDecimals);
|
|
159
|
+
const { object } = await this.suiClient.core.getObject({
|
|
160
|
+
objectId: this.feeTierListObjectId,
|
|
161
|
+
include: { json: true },
|
|
162
|
+
});
|
|
163
|
+
const json = object.json;
|
|
164
|
+
if (!Array.isArray(json.tiers))
|
|
165
|
+
throw new Error('Invalid fee tier list: missing or invalid "tiers"');
|
|
166
|
+
if (typeof json.version !== "string")
|
|
167
|
+
throw new Error('Invalid fee tier list: missing or invalid "version"');
|
|
168
|
+
const tiers = json.tiers.map((tier) => {
|
|
169
|
+
if (typeof tier !== "object" || tier === null)
|
|
170
|
+
throw new Error("Invalid fee tier: expected object");
|
|
171
|
+
const t = tier;
|
|
172
|
+
if (typeof t.minAmount !== "string")
|
|
173
|
+
throw new Error('Invalid fee tier: missing or invalid "minAmount"');
|
|
174
|
+
if (typeof t.maxAmount !== "string")
|
|
175
|
+
throw new Error('Invalid fee tier: missing or invalid "maxAmount"');
|
|
176
|
+
if (typeof t.fee !== "string")
|
|
177
|
+
throw new Error('Invalid fee tier: missing or invalid "fee"');
|
|
178
|
+
return {
|
|
179
|
+
minAmount: BigNumber(t.minAmount).div(UNITS_PER_USDC).toFixed(),
|
|
180
|
+
maxAmount: BigNumber(t.maxAmount).div(UNITS_PER_USDC).toFixed(),
|
|
181
|
+
fee: bpsToPercent(t.fee),
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
return {
|
|
185
|
+
id: object.objectId,
|
|
186
|
+
tiers,
|
|
187
|
+
version: json.version,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
async getSwapFeeList() {
|
|
191
|
+
const { object } = await this.suiClient.core.getObject({
|
|
192
|
+
objectId: this.swapFeeListObjectId,
|
|
193
|
+
include: { json: true },
|
|
194
|
+
});
|
|
195
|
+
const json = object.json;
|
|
196
|
+
if (typeof json.version !== "string")
|
|
197
|
+
throw new Error('Invalid swap fee list: missing or invalid "version"');
|
|
198
|
+
if (!Array.isArray(json.swap_fees))
|
|
199
|
+
throw new Error('Invalid swap fee list: missing or invalid "swap_fees"');
|
|
200
|
+
const swapFees = json.swap_fees.map((swapFee) => {
|
|
201
|
+
if (typeof swapFee !== "object" || swapFee === null)
|
|
202
|
+
throw new Error("Invalid swap fee: expected object");
|
|
203
|
+
const sf = swapFee;
|
|
204
|
+
if (typeof sf.token_type !== "string")
|
|
205
|
+
throw new Error('Invalid swap fee: missing or invalid "token_type"');
|
|
206
|
+
if (typeof sf.fee !== "string")
|
|
207
|
+
throw new Error('Invalid swap fee: missing or invalid "fee"');
|
|
208
|
+
return {
|
|
209
|
+
tokenType: sf.token_type,
|
|
210
|
+
fee: bpsToPercent(sf.fee),
|
|
211
|
+
};
|
|
212
|
+
});
|
|
213
|
+
return {
|
|
214
|
+
id: object.objectId,
|
|
215
|
+
version: json.version,
|
|
216
|
+
swapFees,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
async setNativeFee(params) {
|
|
220
|
+
const feeBps = BigInt(percentToBps(params.feePercent));
|
|
221
|
+
const tx = new Transaction();
|
|
222
|
+
tx.moveCall({
|
|
223
|
+
target: `${this.packageInfo.address}::${this.packageInfo.module}::set_native_fee`,
|
|
224
|
+
arguments: [
|
|
225
|
+
tx.object(this.adminCapObjectId),
|
|
226
|
+
tx.object(this.cardConfigObjectId),
|
|
227
|
+
tx.pure.u64(feeBps),
|
|
228
|
+
],
|
|
229
|
+
});
|
|
230
|
+
tx.setSender(this.wallet.address);
|
|
231
|
+
return new SuiTransactionPayload(this.suiClient, tx, this.wallet);
|
|
232
|
+
}
|
|
233
|
+
async setNonNativeFee(params) {
|
|
234
|
+
const feeBps = BigInt(percentToBps(params.feePercent));
|
|
235
|
+
const tx = new Transaction();
|
|
236
|
+
tx.moveCall({
|
|
237
|
+
target: `${this.packageInfo.address}::${this.packageInfo.module}::set_non_native_fee`,
|
|
238
|
+
arguments: [
|
|
239
|
+
tx.object(this.adminCapObjectId),
|
|
240
|
+
tx.object(this.cardConfigObjectId),
|
|
241
|
+
tx.pure.u64(feeBps),
|
|
242
|
+
],
|
|
243
|
+
});
|
|
244
|
+
tx.setSender(this.wallet.address);
|
|
245
|
+
return new SuiTransactionPayload(this.suiClient, tx, this.wallet);
|
|
246
|
+
}
|
|
247
|
+
async setRevenueVault(params) {
|
|
248
|
+
if (!isValidSuiAddress(params.vaultAddress)) {
|
|
249
|
+
throw new Error("Invalid Sui Address");
|
|
250
|
+
}
|
|
251
|
+
const tx = new Transaction();
|
|
252
|
+
tx.moveCall({
|
|
253
|
+
target: `${this.packageInfo.address}::${this.packageInfo.module}::set_revenue_vault`,
|
|
254
|
+
arguments: [
|
|
255
|
+
tx.object(this.adminCapObjectId),
|
|
256
|
+
tx.object(this.cardConfigObjectId),
|
|
257
|
+
tx.pure.address(params.vaultAddress),
|
|
258
|
+
],
|
|
259
|
+
});
|
|
260
|
+
tx.setSender(this.wallet.address);
|
|
261
|
+
return new SuiTransactionPayload(this.suiClient, tx, this.wallet);
|
|
262
|
+
}
|
|
263
|
+
async setUsdcAddress(params) {
|
|
264
|
+
if (!isValidSuiAddress(params.usdcAddress)) {
|
|
265
|
+
throw new Error("Invalid Sui Address");
|
|
266
|
+
}
|
|
267
|
+
const tx = new Transaction();
|
|
268
|
+
tx.moveCall({
|
|
269
|
+
target: `${this.packageInfo.address}::${this.packageInfo.module}::set_usdc_address`,
|
|
270
|
+
arguments: [
|
|
271
|
+
tx.object(this.adminCapObjectId),
|
|
272
|
+
tx.object(this.cardConfigObjectId),
|
|
273
|
+
tx.pure.address(params.usdcAddress),
|
|
274
|
+
],
|
|
275
|
+
});
|
|
276
|
+
tx.setSender(this.wallet.address);
|
|
277
|
+
return new SuiTransactionPayload(this.suiClient, tx, this.wallet);
|
|
278
|
+
}
|
|
279
|
+
async setCardVault(params) {
|
|
280
|
+
if (!isValidSuiAddress(params.vaultAddress)) {
|
|
281
|
+
throw new Error("Invalid Sui Address");
|
|
282
|
+
}
|
|
283
|
+
const tx = new Transaction();
|
|
284
|
+
tx.moveCall({
|
|
285
|
+
target: `${this.packageInfo.address}::${this.packageInfo.module}::set_card_vault`,
|
|
286
|
+
arguments: [
|
|
287
|
+
tx.object(this.adminCapObjectId),
|
|
288
|
+
tx.object(this.cardConfigObjectId),
|
|
289
|
+
tx.pure.address(params.vaultAddress),
|
|
290
|
+
],
|
|
291
|
+
});
|
|
292
|
+
tx.setSender(this.wallet.address);
|
|
293
|
+
return new SuiTransactionPayload(this.suiClient, tx, this.wallet);
|
|
294
|
+
}
|
|
295
|
+
async setRevenueFee(params) {
|
|
296
|
+
const feeBps = BigInt(percentToBps(params.feePercent));
|
|
297
|
+
const tx = new Transaction();
|
|
298
|
+
tx.moveCall({
|
|
299
|
+
target: `${this.packageInfo.address}::${this.packageInfo.module}::set_revenue_fee`,
|
|
300
|
+
arguments: [
|
|
301
|
+
tx.object(this.adminCapObjectId),
|
|
302
|
+
tx.object(this.cardConfigObjectId),
|
|
303
|
+
tx.pure.u64(feeBps),
|
|
304
|
+
],
|
|
305
|
+
});
|
|
306
|
+
tx.setSender(this.wallet.address);
|
|
307
|
+
return new SuiTransactionPayload(this.suiClient, tx, this.wallet);
|
|
308
|
+
}
|
|
309
|
+
async setMinCardAmount(params) {
|
|
310
|
+
const usdcDecimals = this.usdcCoinMetadata.decimals;
|
|
311
|
+
const minCardAmount = BigInt(BigNumber(params.minCardAmount)
|
|
312
|
+
.times(TEN_BIGNUM.pow(usdcDecimals))
|
|
313
|
+
.toFixed(0));
|
|
314
|
+
const tx = new Transaction();
|
|
315
|
+
tx.moveCall({
|
|
316
|
+
target: `${this.packageInfo.address}::${this.packageInfo.module}::set_min_card_amount`,
|
|
317
|
+
arguments: [
|
|
318
|
+
tx.object(this.adminCapObjectId),
|
|
319
|
+
tx.object(this.cardConfigObjectId),
|
|
320
|
+
tx.pure.u64(minCardAmount),
|
|
321
|
+
],
|
|
322
|
+
});
|
|
323
|
+
tx.setSender(this.wallet.address);
|
|
324
|
+
return new SuiTransactionPayload(this.suiClient, tx, this.wallet);
|
|
325
|
+
}
|
|
326
|
+
async setMaxCardAmount(params) {
|
|
327
|
+
const usdcDecimals = this.usdcCoinMetadata.decimals;
|
|
328
|
+
const maxCardAmount = BigInt(BigNumber(params.maxCardAmount)
|
|
329
|
+
.times(TEN_BIGNUM.pow(usdcDecimals))
|
|
330
|
+
.toFixed(0));
|
|
331
|
+
const tx = new Transaction();
|
|
332
|
+
tx.moveCall({
|
|
333
|
+
target: `${this.packageInfo.address}::${this.packageInfo.module}::set_max_card_amount`,
|
|
334
|
+
arguments: [
|
|
335
|
+
tx.object(this.adminCapObjectId),
|
|
336
|
+
tx.object(this.cardConfigObjectId),
|
|
337
|
+
tx.pure.u64(maxCardAmount),
|
|
338
|
+
],
|
|
339
|
+
});
|
|
340
|
+
tx.setSender(this.wallet.address);
|
|
341
|
+
return new SuiTransactionPayload(this.suiClient, tx, this.wallet);
|
|
342
|
+
}
|
|
343
|
+
async setDailyLimit(params) {
|
|
344
|
+
const usdcDecimals = this.usdcCoinMetadata.decimals;
|
|
345
|
+
const dailyLimit = BigInt(BigNumber(params.dailyLimit)
|
|
346
|
+
.times(TEN_BIGNUM.pow(usdcDecimals))
|
|
347
|
+
.toFixed(0));
|
|
348
|
+
const tx = new Transaction();
|
|
349
|
+
tx.moveCall({
|
|
350
|
+
target: `${this.packageInfo.address}::${this.packageInfo.module}::set_daily_limit`,
|
|
351
|
+
arguments: [
|
|
352
|
+
tx.object(this.adminCapObjectId),
|
|
353
|
+
tx.object(this.cardConfigObjectId),
|
|
354
|
+
tx.pure.u64(dailyLimit),
|
|
355
|
+
],
|
|
356
|
+
});
|
|
357
|
+
tx.setSender(this.wallet.address);
|
|
358
|
+
return new SuiTransactionPayload(this.suiClient, tx, this.wallet);
|
|
359
|
+
}
|
|
360
|
+
async addFeeTier(params) {
|
|
361
|
+
const usdcDecimals = this.usdcCoinMetadata.decimals;
|
|
362
|
+
const feeTier = {
|
|
363
|
+
fee: BigInt(percentToBps(params.fee)),
|
|
364
|
+
minAmount: BigInt(BigNumber(params.minAmount)
|
|
365
|
+
.times(TEN_BIGNUM.pow(usdcDecimals))
|
|
366
|
+
.toFixed(0, BigNumber.ROUND_DOWN)),
|
|
367
|
+
maxAmount: BigInt(BigNumber(params.maxAmount)
|
|
368
|
+
.times(TEN_BIGNUM.pow(usdcDecimals))
|
|
369
|
+
.toFixed(0, BigNumber.ROUND_DOWN)),
|
|
370
|
+
};
|
|
371
|
+
const tx = new Transaction();
|
|
372
|
+
tx.moveCall({
|
|
373
|
+
target: `${this.packageInfo.address}::${this.packageInfo.module}::add_fee_tier`,
|
|
374
|
+
arguments: [
|
|
375
|
+
tx.object(this.adminCapObjectId),
|
|
376
|
+
tx.object(this.feeTierListObjectId),
|
|
377
|
+
tx.pure.u64(feeTier.minAmount),
|
|
378
|
+
tx.pure.u64(feeTier.maxAmount),
|
|
379
|
+
tx.pure.u64(feeTier.fee),
|
|
380
|
+
],
|
|
381
|
+
});
|
|
382
|
+
tx.setSender(this.wallet.address);
|
|
383
|
+
return new SuiTransactionPayload(this.suiClient, tx, this.wallet);
|
|
384
|
+
}
|
|
385
|
+
async updateFeeTier(params) {
|
|
386
|
+
const usdcDecimals = this.usdcCoinMetadata.decimals;
|
|
387
|
+
const feeTier = {
|
|
388
|
+
fee: BigInt(percentToBps(params.fee)),
|
|
389
|
+
minAmount: BigInt(BigNumber(params.minAmount)
|
|
390
|
+
.times(TEN_BIGNUM.pow(usdcDecimals))
|
|
391
|
+
.toFixed(0, BigNumber.ROUND_DOWN)),
|
|
392
|
+
maxAmount: BigInt(BigNumber(params.maxAmount)
|
|
393
|
+
.times(TEN_BIGNUM.pow(usdcDecimals))
|
|
394
|
+
.toFixed(0, BigNumber.ROUND_DOWN)),
|
|
395
|
+
};
|
|
396
|
+
const tx = new Transaction();
|
|
397
|
+
tx.moveCall({
|
|
398
|
+
target: `${this.packageInfo.address}::${this.packageInfo.module}::update_fee_tier`,
|
|
399
|
+
arguments: [
|
|
400
|
+
tx.object(this.adminCapObjectId),
|
|
401
|
+
tx.object(this.feeTierListObjectId),
|
|
402
|
+
tx.pure.u64(feeTier.minAmount),
|
|
403
|
+
tx.pure.u64(feeTier.maxAmount),
|
|
404
|
+
tx.pure.u64(feeTier.fee),
|
|
405
|
+
],
|
|
406
|
+
});
|
|
407
|
+
tx.setSender(this.wallet.address);
|
|
408
|
+
return new SuiTransactionPayload(this.suiClient, tx, this.wallet);
|
|
409
|
+
}
|
|
410
|
+
async removeFeeTier(params) {
|
|
411
|
+
const usdcDecimals = this.usdcCoinMetadata.decimals;
|
|
412
|
+
const minAmount = BigInt(BigNumber(params.minAmount)
|
|
413
|
+
.times(TEN_BIGNUM.pow(usdcDecimals))
|
|
414
|
+
.toFixed(0, BigNumber.ROUND_DOWN));
|
|
415
|
+
const maxAmount = BigInt(BigNumber(params.maxAmount)
|
|
416
|
+
.times(TEN_BIGNUM.pow(usdcDecimals))
|
|
417
|
+
.toFixed(0, BigNumber.ROUND_DOWN));
|
|
418
|
+
const tx = new Transaction();
|
|
419
|
+
tx.moveCall({
|
|
420
|
+
target: `${this.packageInfo.address}::${this.packageInfo.module}::remove_fee_tier`,
|
|
421
|
+
arguments: [
|
|
422
|
+
tx.object(this.adminCapObjectId),
|
|
423
|
+
tx.object(this.feeTierListObjectId),
|
|
424
|
+
tx.pure.u64(minAmount),
|
|
425
|
+
tx.pure.u64(maxAmount),
|
|
426
|
+
],
|
|
427
|
+
});
|
|
428
|
+
tx.setSender(this.wallet.address);
|
|
429
|
+
return new SuiTransactionPayload(this.suiClient, tx, this.wallet);
|
|
430
|
+
}
|
|
431
|
+
async getFeeForAmount(params) {
|
|
432
|
+
const usdcDecimals = this.usdcCoinMetadata.decimals;
|
|
433
|
+
const amount = BigInt(BigNumber(params.amount)
|
|
434
|
+
.times(TEN_BIGNUM.pow(usdcDecimals))
|
|
435
|
+
.toFixed(0, BigNumber.ROUND_DOWN));
|
|
436
|
+
const tx = new Transaction();
|
|
437
|
+
tx.moveCall({
|
|
438
|
+
target: `${this.packageInfo.address}::${this.packageInfo.module}::get_fee_from_tiers`,
|
|
439
|
+
arguments: [tx.object(this.feeTierListObjectId), tx.pure.u64(amount)],
|
|
440
|
+
});
|
|
441
|
+
tx.setSender(this.wallet.address);
|
|
442
|
+
return new SuiTransactionPayload(this.suiClient, tx, this.wallet);
|
|
443
|
+
}
|
|
444
|
+
async addSwapFee(params) {
|
|
445
|
+
const fee = BigInt(percentToBps(params.fee));
|
|
446
|
+
const tx = new Transaction();
|
|
447
|
+
tx.moveCall({
|
|
448
|
+
target: `${this.packageInfo.address}::${this.packageInfo.module}::add_swap_fee`,
|
|
449
|
+
arguments: [
|
|
450
|
+
tx.object(this.adminCapObjectId),
|
|
451
|
+
tx.object(this.swapFeeListObjectId),
|
|
452
|
+
tx.pure.string(params.tokenType),
|
|
453
|
+
tx.pure.u64(fee),
|
|
454
|
+
],
|
|
455
|
+
});
|
|
456
|
+
tx.setSender(this.wallet.address);
|
|
457
|
+
return new SuiTransactionPayload(this.suiClient, tx, this.wallet);
|
|
458
|
+
}
|
|
459
|
+
async updateSwapFee(params) {
|
|
460
|
+
const fee = BigInt(percentToBps(params.fee));
|
|
461
|
+
const tx = new Transaction();
|
|
462
|
+
tx.moveCall({
|
|
463
|
+
target: `${this.packageInfo.address}::${this.packageInfo.module}::update_swap_fee`,
|
|
464
|
+
arguments: [
|
|
465
|
+
tx.object(this.adminCapObjectId),
|
|
466
|
+
tx.object(this.swapFeeListObjectId),
|
|
467
|
+
tx.pure.string(params.tokenType),
|
|
468
|
+
tx.pure.u64(fee),
|
|
469
|
+
],
|
|
470
|
+
});
|
|
471
|
+
tx.setSender(this.wallet.address);
|
|
472
|
+
return new SuiTransactionPayload(this.suiClient, tx, this.wallet);
|
|
473
|
+
}
|
|
474
|
+
async removeSwapFee(params) {
|
|
475
|
+
const tx = new Transaction();
|
|
476
|
+
tx.moveCall({
|
|
477
|
+
target: `${this.packageInfo.address}::${this.packageInfo.module}::remove_swap_fee`,
|
|
478
|
+
arguments: [
|
|
479
|
+
tx.object(this.adminCapObjectId),
|
|
480
|
+
tx.object(this.swapFeeListObjectId),
|
|
481
|
+
tx.pure.string(params.tokenType),
|
|
482
|
+
],
|
|
483
|
+
});
|
|
484
|
+
tx.setSender(this.wallet.address);
|
|
485
|
+
return new SuiTransactionPayload(this.suiClient, tx, this.wallet);
|
|
486
|
+
}
|
|
487
|
+
}
|