@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/constants.ts
CHANGED
|
@@ -24,7 +24,6 @@ export const SEEDS = {
|
|
|
24
24
|
MARKET_V2: Buffer.from("market_v2"),
|
|
25
25
|
MARKET_RESERVE_VAULT: Buffer.from("market_reserve"),
|
|
26
26
|
MARKET_COLLATERAL_VAULT: Buffer.from("market_collateral"),
|
|
27
|
-
MARKET_FEE_VAULT: Buffer.from("market_fee"),
|
|
28
27
|
MARKET_INTEREST_VAULT: Buffer.from("market_interest"),
|
|
29
28
|
BORROW_POSITION: Buffer.from("borrow_position_v2"),
|
|
30
29
|
LEVERAGE_POSITION: Buffer.from("leverage_position_v2"),
|
|
@@ -32,7 +31,8 @@ export const SEEDS = {
|
|
|
32
31
|
HLP_YLP_VAULT: Buffer.from("hlp_ylp_vault"),
|
|
33
32
|
INSURANCE: Buffer.from("insurance"),
|
|
34
33
|
FUTARCHY_AUTHORITY: Buffer.from("futarchy_authority"),
|
|
35
|
-
|
|
34
|
+
REFERRAL_PARTNER: Buffer.from("referral_partner"),
|
|
35
|
+
REFERRAL_ACCRUAL: Buffer.from("referral_accrual"),
|
|
36
36
|
METADATA: Buffer.from("metadata"),
|
|
37
37
|
} as const;
|
|
38
38
|
|
|
@@ -51,10 +51,27 @@ export function deriveFutarchyAuthorityAddress(): [PublicKey, number] {
|
|
|
51
51
|
return PublicKey.findProgramAddressSync([SEEDS.FUTARCHY_AUTHORITY], DUSK_PROGRAM_ID);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
/** Derive the protocol-wide referral
|
|
55
|
-
export function
|
|
54
|
+
/** Derive the protocol-wide referral partner for a referrer authority. */
|
|
55
|
+
export function deriveReferralPartnerAddress(authority: PublicKey): [PublicKey, number] {
|
|
56
56
|
return PublicKey.findProgramAddressSync(
|
|
57
|
-
[SEEDS.
|
|
57
|
+
[SEEDS.REFERRAL_PARTNER, authority.toBuffer()],
|
|
58
|
+
DUSK_PROGRAM_ID
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Derive claimable referral interest for one partner, market, and debt mint. */
|
|
63
|
+
export function deriveReferralAccrualAddress(
|
|
64
|
+
referralPartner: PublicKey,
|
|
65
|
+
market: PublicKey,
|
|
66
|
+
assetMint: PublicKey
|
|
67
|
+
): [PublicKey, number] {
|
|
68
|
+
return PublicKey.findProgramAddressSync(
|
|
69
|
+
[
|
|
70
|
+
SEEDS.REFERRAL_ACCRUAL,
|
|
71
|
+
referralPartner.toBuffer(),
|
|
72
|
+
market.toBuffer(),
|
|
73
|
+
assetMint.toBuffer(),
|
|
74
|
+
],
|
|
58
75
|
DUSK_PROGRAM_ID
|
|
59
76
|
);
|
|
60
77
|
}
|
|
@@ -114,19 +131,6 @@ export function deriveMarketCollateralVaultAddress(
|
|
|
114
131
|
);
|
|
115
132
|
}
|
|
116
133
|
|
|
117
|
-
/**
|
|
118
|
-
* Derive market fee vault PDA address
|
|
119
|
-
*/
|
|
120
|
-
export function deriveMarketFeeVaultAddress(
|
|
121
|
-
market: PublicKey,
|
|
122
|
-
feeMint: PublicKey
|
|
123
|
-
): [PublicKey, number] {
|
|
124
|
-
return PublicKey.findProgramAddressSync(
|
|
125
|
-
[SEEDS.MARKET_FEE_VAULT, market.toBuffer(), feeMint.toBuffer()],
|
|
126
|
-
DUSK_PROGRAM_ID
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
134
|
/**
|
|
131
135
|
* Derive market interest vault PDA address
|
|
132
136
|
*/
|
|
@@ -180,6 +184,7 @@ function yieldTokenKindCode(tokenKind: YieldTokenKind): number {
|
|
|
180
184
|
export function deriveYieldAccountAddress(
|
|
181
185
|
market: PublicKey,
|
|
182
186
|
owner: PublicKey,
|
|
187
|
+
lpMint: PublicKey,
|
|
183
188
|
assetMint: PublicKey,
|
|
184
189
|
tokenKind: YieldTokenKind
|
|
185
190
|
): [PublicKey, number] {
|
|
@@ -188,6 +193,7 @@ export function deriveYieldAccountAddress(
|
|
|
188
193
|
SEEDS.YIELD_ACCOUNT,
|
|
189
194
|
market.toBuffer(),
|
|
190
195
|
owner.toBuffer(),
|
|
196
|
+
lpMint.toBuffer(),
|
|
191
197
|
assetMint.toBuffer(),
|
|
192
198
|
Buffer.from([yieldTokenKindCode(tokenKind)]),
|
|
193
199
|
],
|
|
@@ -200,7 +206,8 @@ export interface YieldTransferHookAccountsArgs {
|
|
|
200
206
|
market: PublicKey;
|
|
201
207
|
sourceOwner: PublicKey;
|
|
202
208
|
destinationOwner: PublicKey;
|
|
203
|
-
|
|
209
|
+
baseMint: PublicKey;
|
|
210
|
+
quoteMint: PublicKey;
|
|
204
211
|
tokenKind: YieldTokenKind;
|
|
205
212
|
}
|
|
206
213
|
|
|
@@ -229,16 +236,11 @@ interface TransferHookValidationMeta {
|
|
|
229
236
|
isWritable: boolean;
|
|
230
237
|
}
|
|
231
238
|
|
|
232
|
-
export interface
|
|
233
|
-
market: PublicKey;
|
|
234
|
-
assetMint: PublicKey;
|
|
235
|
-
tokenKind: YieldTokenKind;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
export interface YlpTransferHookValidationArgs {
|
|
239
|
+
export interface LpTransferHookValidationArgs {
|
|
239
240
|
market: PublicKey;
|
|
240
241
|
baseMint: PublicKey;
|
|
241
242
|
quoteMint: PublicKey;
|
|
243
|
+
tokenKind: YieldTokenKind;
|
|
242
244
|
}
|
|
243
245
|
|
|
244
246
|
/**
|
|
@@ -339,6 +341,7 @@ function yieldAccountTransferHookSeeds(
|
|
|
339
341
|
dataIndex: TRANSFER_HOOK_TOKEN_ACCOUNT_OWNER_OFFSET,
|
|
340
342
|
length: 32,
|
|
341
343
|
},
|
|
344
|
+
{ kind: "accountKey", index: 1 },
|
|
342
345
|
{ kind: "accountKey", index: assetMintAccountIndex },
|
|
343
346
|
{ kind: "literal", bytes: [yieldTokenKindCode(tokenKind)] },
|
|
344
347
|
];
|
|
@@ -383,46 +386,28 @@ export function buildYieldTransferHookValidationAccountData(extraMetas: AccountM
|
|
|
383
386
|
* source/destination YieldAccount PDAs from the source and destination token
|
|
384
387
|
* account owners observed by Token-2022 during Execute.
|
|
385
388
|
*/
|
|
386
|
-
export function
|
|
387
|
-
market,
|
|
388
|
-
assetMint,
|
|
389
|
-
tokenKind,
|
|
390
|
-
}: YieldTransferHookValidationArgs): Buffer {
|
|
391
|
-
return encodeTransferHookValidationAccountData([
|
|
392
|
-
staticTransferHookMeta({ pubkey: market, isSigner: false, isWritable: false }),
|
|
393
|
-
staticTransferHookMeta({ pubkey: assetMint, isSigner: false, isWritable: false }),
|
|
394
|
-
pdaTransferHookMeta(
|
|
395
|
-
yieldAccountTransferHookSeeds(TRANSFER_HOOK_SOURCE_ACCOUNT_INDEX, tokenKind),
|
|
396
|
-
true
|
|
397
|
-
),
|
|
398
|
-
pdaTransferHookMeta(
|
|
399
|
-
yieldAccountTransferHookSeeds(TRANSFER_HOOK_DESTINATION_ACCOUNT_INDEX, tokenKind),
|
|
400
|
-
true
|
|
401
|
-
),
|
|
402
|
-
]);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
export function buildYlpTransferHookValidationAccountData({
|
|
389
|
+
export function buildLpTransferHookValidationAccountData({
|
|
406
390
|
market,
|
|
407
391
|
baseMint,
|
|
408
392
|
quoteMint,
|
|
409
|
-
|
|
393
|
+
tokenKind,
|
|
394
|
+
}: LpTransferHookValidationArgs): Buffer {
|
|
410
395
|
return encodeTransferHookValidationAccountData([
|
|
411
|
-
staticTransferHookMeta({ pubkey: market, isSigner: false, isWritable:
|
|
396
|
+
staticTransferHookMeta({ pubkey: market, isSigner: false, isWritable: true }),
|
|
412
397
|
staticTransferHookMeta({ pubkey: baseMint, isSigner: false, isWritable: false }),
|
|
413
398
|
staticTransferHookMeta({ pubkey: quoteMint, isSigner: false, isWritable: false }),
|
|
414
399
|
pdaTransferHookMeta(
|
|
415
|
-
yieldAccountTransferHookSeeds(TRANSFER_HOOK_SOURCE_ACCOUNT_INDEX,
|
|
400
|
+
yieldAccountTransferHookSeeds(TRANSFER_HOOK_SOURCE_ACCOUNT_INDEX, tokenKind),
|
|
416
401
|
true
|
|
417
402
|
),
|
|
418
403
|
pdaTransferHookMeta(
|
|
419
|
-
yieldAccountTransferHookSeeds(TRANSFER_HOOK_DESTINATION_ACCOUNT_INDEX,
|
|
404
|
+
yieldAccountTransferHookSeeds(TRANSFER_HOOK_DESTINATION_ACCOUNT_INDEX, tokenKind),
|
|
420
405
|
true
|
|
421
406
|
),
|
|
422
407
|
pdaTransferHookMeta(
|
|
423
408
|
yieldAccountTransferHookSeeds(
|
|
424
409
|
TRANSFER_HOOK_SOURCE_ACCOUNT_INDEX,
|
|
425
|
-
|
|
410
|
+
tokenKind,
|
|
426
411
|
TRANSFER_HOOK_QUOTE_ASSET_MINT_ACCOUNT_INDEX
|
|
427
412
|
),
|
|
428
413
|
true
|
|
@@ -430,7 +415,7 @@ export function buildYlpTransferHookValidationAccountData({
|
|
|
430
415
|
pdaTransferHookMeta(
|
|
431
416
|
yieldAccountTransferHookSeeds(
|
|
432
417
|
TRANSFER_HOOK_DESTINATION_ACCOUNT_INDEX,
|
|
433
|
-
|
|
418
|
+
tokenKind,
|
|
434
419
|
TRANSFER_HOOK_QUOTE_ASSET_MINT_ACCOUNT_INDEX
|
|
435
420
|
),
|
|
436
421
|
true
|
|
@@ -447,77 +432,47 @@ export function buildYlpTransferHookValidationAccountData({
|
|
|
447
432
|
* accounts, hook program, and standard validation PDA as extra metas so the
|
|
448
433
|
* hook can checkpoint revenue before the balance move is finalized.
|
|
449
434
|
*/
|
|
450
|
-
export function
|
|
451
|
-
lpMint,
|
|
452
|
-
market,
|
|
453
|
-
sourceOwner,
|
|
454
|
-
destinationOwner,
|
|
455
|
-
assetMint,
|
|
456
|
-
tokenKind,
|
|
457
|
-
}: YieldTransferHookAccountsArgs): AccountMeta[] {
|
|
458
|
-
const sourceYieldAccount = deriveYieldAccountAddress(
|
|
459
|
-
market,
|
|
460
|
-
sourceOwner,
|
|
461
|
-
assetMint,
|
|
462
|
-
tokenKind
|
|
463
|
-
)[0];
|
|
464
|
-
const destinationYieldAccount = deriveYieldAccountAddress(
|
|
465
|
-
market,
|
|
466
|
-
destinationOwner,
|
|
467
|
-
assetMint,
|
|
468
|
-
tokenKind
|
|
469
|
-
)[0];
|
|
470
|
-
const validationAccount = deriveYieldTransferHookValidationAddress(lpMint)[0];
|
|
471
|
-
|
|
472
|
-
return [
|
|
473
|
-
{ pubkey: market, isSigner: false, isWritable: false },
|
|
474
|
-
{ pubkey: assetMint, isSigner: false, isWritable: false },
|
|
475
|
-
{ pubkey: sourceYieldAccount, isSigner: false, isWritable: true },
|
|
476
|
-
{ pubkey: destinationYieldAccount, isSigner: false, isWritable: true },
|
|
477
|
-
{ pubkey: DUSK_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
478
|
-
{ pubkey: validationAccount, isSigner: false, isWritable: false },
|
|
479
|
-
];
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
export function buildYlpTransferHookAccountMetas({
|
|
435
|
+
export function buildLpTransferHookAccountMetas({
|
|
483
436
|
lpMint,
|
|
484
437
|
market,
|
|
485
438
|
sourceOwner,
|
|
486
439
|
destinationOwner,
|
|
487
440
|
baseMint,
|
|
488
441
|
quoteMint,
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
quoteMint: PublicKey;
|
|
492
|
-
}): AccountMeta[] {
|
|
442
|
+
tokenKind,
|
|
443
|
+
}: YieldTransferHookAccountsArgs): AccountMeta[] {
|
|
493
444
|
const sourceBaseYieldAccount = deriveYieldAccountAddress(
|
|
494
445
|
market,
|
|
495
446
|
sourceOwner,
|
|
447
|
+
lpMint,
|
|
496
448
|
baseMint,
|
|
497
|
-
|
|
449
|
+
tokenKind
|
|
498
450
|
)[0];
|
|
499
451
|
const destinationBaseYieldAccount = deriveYieldAccountAddress(
|
|
500
452
|
market,
|
|
501
453
|
destinationOwner,
|
|
454
|
+
lpMint,
|
|
502
455
|
baseMint,
|
|
503
|
-
|
|
456
|
+
tokenKind
|
|
504
457
|
)[0];
|
|
505
458
|
const sourceQuoteYieldAccount = deriveYieldAccountAddress(
|
|
506
459
|
market,
|
|
507
460
|
sourceOwner,
|
|
461
|
+
lpMint,
|
|
508
462
|
quoteMint,
|
|
509
|
-
|
|
463
|
+
tokenKind
|
|
510
464
|
)[0];
|
|
511
465
|
const destinationQuoteYieldAccount = deriveYieldAccountAddress(
|
|
512
466
|
market,
|
|
513
467
|
destinationOwner,
|
|
468
|
+
lpMint,
|
|
514
469
|
quoteMint,
|
|
515
|
-
|
|
470
|
+
tokenKind
|
|
516
471
|
)[0];
|
|
517
472
|
const validationAccount = deriveYieldTransferHookValidationAddress(lpMint)[0];
|
|
518
473
|
|
|
519
474
|
return [
|
|
520
|
-
{ pubkey: market, isSigner: false, isWritable:
|
|
475
|
+
{ pubkey: market, isSigner: false, isWritable: true },
|
|
521
476
|
{ pubkey: baseMint, isSigner: false, isWritable: false },
|
|
522
477
|
{ pubkey: quoteMint, isSigner: false, isWritable: false },
|
|
523
478
|
{ pubkey: sourceBaseYieldAccount, isSigner: false, isWritable: true },
|
package/src/get.ts
CHANGED
|
@@ -14,10 +14,10 @@ import {
|
|
|
14
14
|
deriveLeveragePositionAddress,
|
|
15
15
|
deriveMarketAddress,
|
|
16
16
|
deriveMarketCollateralVaultAddress,
|
|
17
|
-
deriveMarketFeeVaultAddress,
|
|
18
17
|
deriveMarketInterestVaultAddress,
|
|
19
18
|
deriveMarketReserveVaultAddress,
|
|
20
|
-
|
|
19
|
+
deriveReferralAccrualAddress,
|
|
20
|
+
deriveReferralPartnerAddress,
|
|
21
21
|
deriveTokenMetadataAddress,
|
|
22
22
|
deriveYieldAccountAddress,
|
|
23
23
|
deriveYieldTransferHookValidationAddress,
|
|
@@ -42,6 +42,8 @@ import type {
|
|
|
42
42
|
LeverageDelegation,
|
|
43
43
|
LeveragePosition,
|
|
44
44
|
Market,
|
|
45
|
+
ReferralAccrual,
|
|
46
|
+
ReferralPartner,
|
|
45
47
|
YieldAccount,
|
|
46
48
|
} from "./type-aliases.js";
|
|
47
49
|
import type { Dusk } from "./types_v2.js";
|
|
@@ -52,7 +54,6 @@ export const pda = {
|
|
|
52
54
|
tokenMetadata: deriveTokenMetadataAddress,
|
|
53
55
|
marketReserveVault: deriveMarketReserveVaultAddress,
|
|
54
56
|
marketCollateralVault: deriveMarketCollateralVaultAddress,
|
|
55
|
-
marketFeeVault: deriveMarketFeeVaultAddress,
|
|
56
57
|
marketInterestVault: deriveMarketInterestVaultAddress,
|
|
57
58
|
borrowPosition: deriveBorrowPositionAddress,
|
|
58
59
|
leveragePosition: deriveLeveragePositionAddress,
|
|
@@ -60,7 +61,8 @@ export const pda = {
|
|
|
60
61
|
yieldTransferHookValidation: deriveYieldTransferHookValidationAddress,
|
|
61
62
|
hlpYlpVault: deriveHlpYlpVaultAddress,
|
|
62
63
|
insurance: deriveInsuranceAddress,
|
|
63
|
-
|
|
64
|
+
referralPartner: deriveReferralPartnerAddress,
|
|
65
|
+
referralAccrual: deriveReferralAccrualAddress,
|
|
64
66
|
} as const;
|
|
65
67
|
|
|
66
68
|
export interface SimulateOptions {
|
|
@@ -85,17 +87,14 @@ export interface PreviewAddLiquidityParams extends SimulateOptions {
|
|
|
85
87
|
|
|
86
88
|
export interface PreviewBorrowCapacityParams extends SimulateOptions {
|
|
87
89
|
market: AddressLike;
|
|
88
|
-
futarchyAuthority?: AddressLike;
|
|
89
90
|
collateralAssetMint: AddressLike;
|
|
90
91
|
debtAssetMint: AddressLike;
|
|
91
92
|
collateralAmount: BN;
|
|
92
93
|
/**
|
|
93
|
-
* Candidate
|
|
94
|
-
*
|
|
94
|
+
* Candidate debt amount used for the returned CF and health fields. When
|
|
95
|
+
* omitted, the program quotes at maximum borrow capacity.
|
|
95
96
|
*/
|
|
96
97
|
projectedBorrowAmount?: BN | null;
|
|
97
|
-
withReferral?: boolean;
|
|
98
|
-
maxAcceptableReferralFeeBps?: number;
|
|
99
98
|
}
|
|
100
99
|
|
|
101
100
|
export interface PreviewBorrowPositionParams extends SimulateOptions {
|
|
@@ -159,6 +158,14 @@ export class DuskGet {
|
|
|
159
158
|
return this.program.account.futarchyAuthority.fetch(address(account));
|
|
160
159
|
}
|
|
161
160
|
|
|
161
|
+
referralPartner(account: AddressLike): Promise<ReferralPartner> {
|
|
162
|
+
return this.program.account.referralPartner.fetch(address(account));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
referralAccrual(account: AddressLike): Promise<ReferralAccrual> {
|
|
166
|
+
return this.program.account.referralAccrual.fetch(address(account));
|
|
167
|
+
}
|
|
168
|
+
|
|
162
169
|
allMarkets() {
|
|
163
170
|
return this.program.account.market.all();
|
|
164
171
|
}
|
|
@@ -171,6 +178,14 @@ export class DuskGet {
|
|
|
171
178
|
return this.program.account.leveragePosition.all();
|
|
172
179
|
}
|
|
173
180
|
|
|
181
|
+
allReferralPartners() {
|
|
182
|
+
return this.program.account.referralPartner.all();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
allReferralAccruals() {
|
|
186
|
+
return this.program.account.referralAccrual.all();
|
|
187
|
+
}
|
|
188
|
+
|
|
174
189
|
async previewMarket(market: AddressLike, options: SimulateOptions = {}): Promise<MarketPreview> {
|
|
175
190
|
const instruction = await this.program.methods
|
|
176
191
|
.previewMarket()
|
|
@@ -224,13 +239,10 @@ export class DuskGet {
|
|
|
224
239
|
.previewBorrowCapacity({
|
|
225
240
|
collateralAmount: params.collateralAmount,
|
|
226
241
|
projectedBorrowAmount: params.projectedBorrowAmount ?? null,
|
|
227
|
-
withReferral: params.withReferral ?? false,
|
|
228
|
-
maxAcceptableReferralFeeBps: params.maxAcceptableReferralFeeBps ?? 0,
|
|
229
242
|
})
|
|
230
243
|
.accounts(
|
|
231
244
|
normalizeAccountKeys({
|
|
232
245
|
market: params.market,
|
|
233
|
-
futarchyAuthority: params.futarchyAuthority ?? deriveFutarchyAuthorityAddress()[0],
|
|
234
246
|
collateralAssetMint: params.collateralAssetMint,
|
|
235
247
|
debtAssetMint: params.debtAssetMint,
|
|
236
248
|
})
|