@omnipair/dusk-sdk 2.0.0 → 2.0.2
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/README.md +118 -10
- package/dist/constants.d.ts +13 -23
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +29 -45
- package/dist/constants.js.map +1 -1
- package/dist/get.d.ts +223 -50
- package/dist/get.d.ts.map +1 -1
- package/dist/get.js +15 -6
- package/dist/get.js.map +1 -1
- package/dist/idl_v2.json +2353 -1405
- package/dist/referral.d.ts +28 -28
- package/dist/referral.d.ts.map +1 -1
- package/dist/referral.js +51 -33
- package/dist/referral.js.map +1 -1
- package/dist/type-aliases.d.ts +8 -7
- package/dist/type-aliases.d.ts.map +1 -1
- package/dist/types_v2.d.ts +2345 -1397
- package/dist/types_v2.d.ts.map +1 -1
- package/dist/write.d.ts +71 -7
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +225 -29
- package/dist/write.js.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +49 -94
- package/src/get.ts +24 -12
- package/src/idl_v2.json +2353 -1405
- package/src/referral.ts +85 -71
- package/src/type-aliases.ts +8 -7
- package/src/types_v2.ts +2353 -1405
- package/src/write.ts +367 -34
package/src/referral.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
createAssociatedTokenAccountIdempotentInstruction,
|
|
3
2
|
createTransferCheckedWithTransferHookInstruction,
|
|
4
|
-
|
|
3
|
+
getMint,
|
|
4
|
+
getTransferHook,
|
|
5
5
|
TOKEN_2022_PROGRAM_ID,
|
|
6
6
|
TOKEN_PROGRAM_ID,
|
|
7
7
|
} from "@solana/spl-token";
|
|
@@ -10,52 +10,72 @@ import {
|
|
|
10
10
|
type AccountMeta,
|
|
11
11
|
type Commitment,
|
|
12
12
|
type Connection,
|
|
13
|
-
type TransactionInstruction,
|
|
14
13
|
} from "@solana/web3.js";
|
|
15
14
|
|
|
16
15
|
import { address, type AddressLike } from "./address.js";
|
|
17
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
deriveReferralAccrualAddress,
|
|
18
|
+
deriveReferralPartnerAddress,
|
|
19
|
+
} from "./constants.js";
|
|
18
20
|
|
|
19
|
-
export const
|
|
20
|
-
export const
|
|
21
|
+
export const REFERRAL_BPS_DENOMINATOR = 10_000;
|
|
22
|
+
export const MAX_REFERRAL_INTEREST_SHARE_BPS = REFERRAL_BPS_DENOMINATOR;
|
|
21
23
|
|
|
22
24
|
export type IntegerLike = bigint | number | string | { toString(): string };
|
|
23
25
|
|
|
24
|
-
export interface
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
export interface ReferralInterestQuote {
|
|
27
|
+
interestPaid: bigint;
|
|
28
|
+
interestVaultCredit: bigint;
|
|
29
|
+
protocolInterestRevenue: bigint;
|
|
30
|
+
interestShareBps: number;
|
|
31
|
+
referralAmount: bigint;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function referralBindingInterestShareBps(params: {
|
|
35
|
+
configuredShareBps: number;
|
|
36
|
+
maxShareBps: number;
|
|
37
|
+
active?: boolean;
|
|
38
|
+
}): number {
|
|
39
|
+
assertReferralInterestShareBps(params.configuredShareBps);
|
|
40
|
+
assertReferralInterestShareBps(params.maxShareBps);
|
|
41
|
+
if (params.active === false) throw new Error("Referral partner is inactive");
|
|
42
|
+
return Math.min(params.configuredShareBps, params.maxShareBps);
|
|
29
43
|
}
|
|
30
44
|
|
|
31
|
-
export function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
export function quoteReferralInterestShare(params: {
|
|
46
|
+
interestPaid: IntegerLike;
|
|
47
|
+
interestVaultCredit?: IntegerLike;
|
|
48
|
+
protocolInterestBps: number;
|
|
49
|
+
interestShareBps: number;
|
|
50
|
+
}): ReferralInterestQuote {
|
|
51
|
+
assertBps(params.protocolInterestBps, "protocol interest share");
|
|
52
|
+
assertReferralInterestShareBps(params.interestShareBps);
|
|
53
|
+
const interestPaid = BigInt(params.interestPaid.toString());
|
|
54
|
+
if (interestPaid < 0n) throw new Error("interestPaid must be non-negative");
|
|
55
|
+
const interestVaultCredit = BigInt(
|
|
56
|
+
(params.interestVaultCredit ?? params.interestPaid).toString()
|
|
57
|
+
);
|
|
58
|
+
if (interestVaultCredit < 0n || interestVaultCredit > interestPaid) {
|
|
59
|
+
throw new Error("interestVaultCredit must be between 0 and interestPaid");
|
|
39
60
|
}
|
|
40
|
-
|
|
61
|
+
|
|
62
|
+
const protocolInterestRevenue =
|
|
63
|
+
(interestVaultCredit * BigInt(params.protocolInterestBps)) /
|
|
64
|
+
BigInt(REFERRAL_BPS_DENOMINATOR);
|
|
65
|
+
const referralAmount =
|
|
66
|
+
(protocolInterestRevenue * BigInt(params.interestShareBps)) /
|
|
67
|
+
BigInt(REFERRAL_BPS_DENOMINATOR);
|
|
41
68
|
return {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
69
|
+
interestPaid,
|
|
70
|
+
interestVaultCredit,
|
|
71
|
+
protocolInterestRevenue,
|
|
72
|
+
interestShareBps: params.interestShareBps,
|
|
73
|
+
referralAmount,
|
|
46
74
|
};
|
|
47
75
|
}
|
|
48
76
|
|
|
49
|
-
export function
|
|
50
|
-
|
|
51
|
-
!Number.isInteger(configuredFeeBps) ||
|
|
52
|
-
configuredFeeBps < 0 ||
|
|
53
|
-
configuredFeeBps > MAX_REFERRAL_ORIGINATION_FEE_BPS
|
|
54
|
-
) {
|
|
55
|
-
throw new Error(
|
|
56
|
-
`referral origination fee must be between 0 and ${MAX_REFERRAL_ORIGINATION_FEE_BPS} bps`
|
|
57
|
-
);
|
|
58
|
-
}
|
|
77
|
+
export function assertReferralInterestShareBps(shareBps: number): void {
|
|
78
|
+
assertBps(shareBps, "referral interest share");
|
|
59
79
|
}
|
|
60
80
|
|
|
61
81
|
export async function tokenProgramForMint(
|
|
@@ -74,50 +94,32 @@ export async function tokenProgramForMint(
|
|
|
74
94
|
throw new Error(`Unsupported mint owner: ${account.owner.toBase58()}`);
|
|
75
95
|
}
|
|
76
96
|
|
|
77
|
-
export interface
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
tokenProgram: PublicKey;
|
|
97
|
+
export interface ReferralAccrualAddresses {
|
|
98
|
+
referralPartner: PublicKey;
|
|
99
|
+
referralAccrual: PublicKey;
|
|
81
100
|
}
|
|
82
101
|
|
|
83
|
-
export
|
|
84
|
-
connection: Connection;
|
|
102
|
+
export function referralAccrualAddresses(params: {
|
|
85
103
|
referrer: AddressLike;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}):
|
|
104
|
+
market: AddressLike;
|
|
105
|
+
assetMint: AddressLike;
|
|
106
|
+
}): ReferralAccrualAddresses {
|
|
89
107
|
const referrer = address(params.referrer);
|
|
90
|
-
const
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
tokenProgram
|
|
108
|
+
const market = address(params.market);
|
|
109
|
+
const assetMint = address(params.assetMint);
|
|
110
|
+
const [referralPartner] = deriveReferralPartnerAddress(referrer);
|
|
111
|
+
const [referralAccrual] = deriveReferralAccrualAddress(
|
|
112
|
+
referralPartner,
|
|
113
|
+
market,
|
|
114
|
+
assetMint
|
|
98
115
|
);
|
|
99
|
-
return {
|
|
116
|
+
return { referralPartner, referralAccrual };
|
|
100
117
|
}
|
|
101
118
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
mint: AddressLike;
|
|
107
|
-
commitment?: Commitment;
|
|
108
|
-
}): Promise<ReferralVaultAddresses & { instruction: TransactionInstruction }> {
|
|
109
|
-
const mint = address(params.mint);
|
|
110
|
-
const addresses = await referralVaultAddresses(params);
|
|
111
|
-
return {
|
|
112
|
-
...addresses,
|
|
113
|
-
instruction: createAssociatedTokenAccountIdempotentInstruction(
|
|
114
|
-
address(params.payer),
|
|
115
|
-
addresses.referralVault,
|
|
116
|
-
addresses.referralProfile,
|
|
117
|
-
mint,
|
|
118
|
-
addresses.tokenProgram
|
|
119
|
-
),
|
|
120
|
-
};
|
|
119
|
+
function assertBps(value: number, label: string): void {
|
|
120
|
+
if (!Number.isInteger(value) || value < 0 || value > REFERRAL_BPS_DENOMINATOR) {
|
|
121
|
+
throw new Error(`${label} must be between 0 and ${REFERRAL_BPS_DENOMINATOR} bps`);
|
|
122
|
+
}
|
|
121
123
|
}
|
|
122
124
|
|
|
123
125
|
export interface TransferHookTransfer {
|
|
@@ -158,6 +160,9 @@ export async function resolveTransferHookAccountMetas(
|
|
|
158
160
|
commitment,
|
|
159
161
|
tokenProgram
|
|
160
162
|
);
|
|
163
|
+
const transferHook = getTransferHook(
|
|
164
|
+
await getMint(connection, mint, commitment, tokenProgram)
|
|
165
|
+
);
|
|
161
166
|
for (const meta of instruction.keys.slice(4)) {
|
|
162
167
|
const key = meta.pubkey.toBase58();
|
|
163
168
|
const current = merged.get(key);
|
|
@@ -167,6 +172,15 @@ export async function resolveTransferHookAccountMetas(
|
|
|
167
172
|
isWritable: Boolean(current?.isWritable || meta.isWritable),
|
|
168
173
|
});
|
|
169
174
|
}
|
|
175
|
+
if (transferHook) {
|
|
176
|
+
const key = transferHook.programId.toBase58();
|
|
177
|
+
const current = merged.get(key);
|
|
178
|
+
merged.set(key, {
|
|
179
|
+
pubkey: transferHook.programId,
|
|
180
|
+
isSigner: Boolean(current?.isSigner),
|
|
181
|
+
isWritable: Boolean(current?.isWritable),
|
|
182
|
+
});
|
|
183
|
+
}
|
|
170
184
|
}
|
|
171
185
|
return [...merged.values()];
|
|
172
186
|
}
|
package/src/type-aliases.ts
CHANGED
|
@@ -7,26 +7,27 @@ export type LeveragePosition = IdlAccounts<Dusk>["leveragePosition"];
|
|
|
7
7
|
export type LeverageDelegation = IdlAccounts<Dusk>["leverageDelegation"];
|
|
8
8
|
export type YieldAccount = IdlAccounts<Dusk>["yieldAccount"];
|
|
9
9
|
export type FutarchyAuthority = IdlAccounts<Dusk>["futarchyAuthority"];
|
|
10
|
-
export type
|
|
11
|
-
export type
|
|
10
|
+
export type ReferralPartner = IdlAccounts<Dusk>["referralPartner"];
|
|
11
|
+
export type ReferralAccrual = IdlAccounts<Dusk>["referralAccrual"];
|
|
12
12
|
|
|
13
13
|
export type HlpClosed = IdlEvents<Dusk>["hlpClosed"];
|
|
14
14
|
export type HlpOpened = IdlEvents<Dusk>["hlpOpened"];
|
|
15
|
-
export type HlpRebalanced = IdlEvents<Dusk>["hlpRebalanced"];
|
|
16
15
|
export type LiquidityAdded = IdlEvents<Dusk>["liquidityAdded"];
|
|
17
16
|
export type LiquidityRemoved = IdlEvents<Dusk>["liquidityRemoved"];
|
|
18
17
|
export type MarketCollateralDeposited = IdlEvents<Dusk>["marketCollateralDeposited"];
|
|
19
18
|
export type MarketCollateralWithdrawn = IdlEvents<Dusk>["marketCollateralWithdrawn"];
|
|
20
19
|
export type MarketCreated = IdlEvents<Dusk>["marketCreated"];
|
|
21
20
|
export type MarketDebtUpdated = IdlEvents<Dusk>["marketDebtUpdated"];
|
|
22
|
-
export type
|
|
21
|
+
export type ManagerFeesClaimed = IdlEvents<Dusk>["managerFeesClaimed"];
|
|
23
22
|
export type MarketHealthUpdated = IdlEvents<Dusk>["marketHealthUpdated"];
|
|
24
23
|
export type MarketUpdated = IdlEvents<Dusk>["marketUpdated"];
|
|
25
24
|
export type PositionLiquidated = IdlEvents<Dusk>["positionLiquidated"];
|
|
26
25
|
export type ProtocolAuctionSettled = IdlEvents<Dusk>["protocolAuctionSettled"];
|
|
27
|
-
export type
|
|
28
|
-
export type
|
|
29
|
-
export type
|
|
26
|
+
export type ReferralBound = IdlEvents<Dusk>["referralBound"];
|
|
27
|
+
export type ReferralPartnerConfigured = IdlEvents<Dusk>["referralPartnerConfigured"];
|
|
28
|
+
export type ReferralInterestAccrued = IdlEvents<Dusk>["referralInterestAccrued"];
|
|
29
|
+
export type ReferralInterestClaimed = IdlEvents<Dusk>["referralInterestClaimed"];
|
|
30
|
+
export type ReferralInterestShareCapUpdated = IdlEvents<Dusk>["referralInterestShareCapUpdated"];
|
|
30
31
|
export type ReferralRecipientUpdated = IdlEvents<Dusk>["referralRecipientUpdated"];
|
|
31
32
|
export type SwapExecuted = IdlEvents<Dusk>["swapExecuted"];
|
|
32
33
|
export type YieldClaimed = IdlEvents<Dusk>["yieldClaimed"];
|