@omnipair/dusk-sdk 2.0.1 → 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 +85 -21
- 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 +2358 -1420
- package/dist/referral.d.ts +28 -28
- package/dist/referral.d.ts.map +1 -1
- package/dist/referral.js +41 -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 +2350 -1412
- package/dist/types_v2.d.ts.map +1 -1
- package/dist/write.d.ts +67 -13
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +211 -36
- 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 +2358 -1420
- package/src/referral.ts +71 -71
- package/src/type-aliases.ts +8 -7
- package/src/types_v2.ts +2358 -1420
- package/src/write.ts +341 -53
package/src/referral.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
createAssociatedTokenAccountIdempotentInstruction,
|
|
3
2
|
createTransferCheckedWithTransferHookInstruction,
|
|
4
|
-
getAssociatedTokenAddressSync,
|
|
5
3
|
getMint,
|
|
6
4
|
getTransferHook,
|
|
7
5
|
TOKEN_2022_PROGRAM_ID,
|
|
@@ -12,52 +10,72 @@ import {
|
|
|
12
10
|
type AccountMeta,
|
|
13
11
|
type Commitment,
|
|
14
12
|
type Connection,
|
|
15
|
-
type TransactionInstruction,
|
|
16
13
|
} from "@solana/web3.js";
|
|
17
14
|
|
|
18
15
|
import { address, type AddressLike } from "./address.js";
|
|
19
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
deriveReferralAccrualAddress,
|
|
18
|
+
deriveReferralPartnerAddress,
|
|
19
|
+
} from "./constants.js";
|
|
20
20
|
|
|
21
|
-
export const
|
|
22
|
-
export const
|
|
21
|
+
export const REFERRAL_BPS_DENOMINATOR = 10_000;
|
|
22
|
+
export const MAX_REFERRAL_INTEREST_SHARE_BPS = REFERRAL_BPS_DENOMINATOR;
|
|
23
23
|
|
|
24
24
|
export type IntegerLike = bigint | number | string | { toString(): string };
|
|
25
25
|
|
|
26
|
-
export interface
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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);
|
|
31
43
|
}
|
|
32
44
|
|
|
33
|
-
export function
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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");
|
|
41
60
|
}
|
|
42
|
-
|
|
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);
|
|
43
68
|
return {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
69
|
+
interestPaid,
|
|
70
|
+
interestVaultCredit,
|
|
71
|
+
protocolInterestRevenue,
|
|
72
|
+
interestShareBps: params.interestShareBps,
|
|
73
|
+
referralAmount,
|
|
48
74
|
};
|
|
49
75
|
}
|
|
50
76
|
|
|
51
|
-
export function
|
|
52
|
-
|
|
53
|
-
!Number.isInteger(configuredFeeBps) ||
|
|
54
|
-
configuredFeeBps < 0 ||
|
|
55
|
-
configuredFeeBps > MAX_REFERRAL_ORIGINATION_FEE_BPS
|
|
56
|
-
) {
|
|
57
|
-
throw new Error(
|
|
58
|
-
`referral origination fee must be between 0 and ${MAX_REFERRAL_ORIGINATION_FEE_BPS} bps`
|
|
59
|
-
);
|
|
60
|
-
}
|
|
77
|
+
export function assertReferralInterestShareBps(shareBps: number): void {
|
|
78
|
+
assertBps(shareBps, "referral interest share");
|
|
61
79
|
}
|
|
62
80
|
|
|
63
81
|
export async function tokenProgramForMint(
|
|
@@ -76,50 +94,32 @@ export async function tokenProgramForMint(
|
|
|
76
94
|
throw new Error(`Unsupported mint owner: ${account.owner.toBase58()}`);
|
|
77
95
|
}
|
|
78
96
|
|
|
79
|
-
export interface
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
tokenProgram: PublicKey;
|
|
97
|
+
export interface ReferralAccrualAddresses {
|
|
98
|
+
referralPartner: PublicKey;
|
|
99
|
+
referralAccrual: PublicKey;
|
|
83
100
|
}
|
|
84
101
|
|
|
85
|
-
export
|
|
86
|
-
connection: Connection;
|
|
102
|
+
export function referralAccrualAddresses(params: {
|
|
87
103
|
referrer: AddressLike;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}):
|
|
104
|
+
market: AddressLike;
|
|
105
|
+
assetMint: AddressLike;
|
|
106
|
+
}): ReferralAccrualAddresses {
|
|
91
107
|
const referrer = address(params.referrer);
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
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
|
|
100
115
|
);
|
|
101
|
-
return {
|
|
116
|
+
return { referralPartner, referralAccrual };
|
|
102
117
|
}
|
|
103
118
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
mint: AddressLike;
|
|
109
|
-
commitment?: Commitment;
|
|
110
|
-
}): Promise<ReferralVaultAddresses & { instruction: TransactionInstruction }> {
|
|
111
|
-
const mint = address(params.mint);
|
|
112
|
-
const addresses = await referralVaultAddresses(params);
|
|
113
|
-
return {
|
|
114
|
-
...addresses,
|
|
115
|
-
instruction: createAssociatedTokenAccountIdempotentInstruction(
|
|
116
|
-
address(params.payer),
|
|
117
|
-
addresses.referralVault,
|
|
118
|
-
addresses.referralProfile,
|
|
119
|
-
mint,
|
|
120
|
-
addresses.tokenProgram
|
|
121
|
-
),
|
|
122
|
-
};
|
|
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
|
+
}
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
export interface TransferHookTransfer {
|
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"];
|