@dexterai/vault 0.4.2 → 0.5.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/README.md +62 -16
- package/dist/constants/index.cjs +13 -1
- package/dist/constants/index.d.cts +11 -1
- package/dist/constants/index.d.ts +11 -1
- package/dist/constants/index.js +12 -1
- package/dist/counterfactual.cjs +12 -1
- package/dist/counterfactual.js +12 -1
- package/dist/factoring/index.cjs +246 -0
- package/dist/factoring/index.d.cts +79 -0
- package/dist/factoring/index.d.ts +79 -0
- package/dist/factoring/index.js +220 -0
- package/dist/idl/dexter_vault.json +976 -1
- package/dist/index.cjs +12 -1
- package/dist/index.js +12 -1
- package/dist/instructions/index.cjs +249 -4400
- package/dist/instructions/index.d.cts +172 -1
- package/dist/instructions/index.d.ts +172 -1
- package/dist/instructions/index.js +235 -4396
- package/dist/kit/index.cjs +67 -0
- package/dist/kit/index.d.cts +13 -0
- package/dist/kit/index.d.ts +13 -0
- package/dist/kit/index.js +41 -0
- package/dist/messages/index.cjs +11 -1
- package/dist/messages/index.js +11 -1
- package/dist/precompile/index.cjs +11 -1
- package/dist/precompile/index.js +11 -1
- package/dist/tab/index.cjs +640 -0
- package/dist/tab/index.d.cts +145 -0
- package/dist/tab/index.d.ts +145 -0
- package/dist/tab/index.js +631 -0
- package/package.json +18 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { PublicKey, TransactionInstruction, Connection } from '@solana/web3.js';
|
|
2
|
+
import { Ed25519Signer } from '../signers/types.cjs';
|
|
3
|
+
import { VaultStateFull } from '../types.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* openTab — composes the settle_voucher(increment) leg that raises the tab's
|
|
7
|
+
* outstanding and arms it. Returns instructions; does NOT send.
|
|
8
|
+
*
|
|
9
|
+
* Note: buildSettleVoucherInstruction needs only { vaultPda, dexterAuthority,
|
|
10
|
+
* amount, increment } — there is no swigAddress param, so we don't accept one
|
|
11
|
+
* (no lying/unused params).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
interface OpenTabParams {
|
|
15
|
+
vaultPda: PublicKey;
|
|
16
|
+
amount: bigint;
|
|
17
|
+
dexterAuthority: PublicKey;
|
|
18
|
+
}
|
|
19
|
+
declare function openTab(p: OpenTabParams): Promise<TransactionInstruction[]>;
|
|
20
|
+
|
|
21
|
+
/** A single SignV2 transfer leg (destination + amount). */
|
|
22
|
+
interface TabTransfer {
|
|
23
|
+
destinationAta: PublicKey;
|
|
24
|
+
amount: bigint;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The injectable Swig SignV2 assembler for ./tab verbs. Default wires the real
|
|
29
|
+
* @swig-wallet/kit; tests inject a fake. Mirrors factoring/instantPayout.ts.
|
|
30
|
+
* The vault instruction (settle_tab_voucher / draw_credit / etc.) is passed as
|
|
31
|
+
* `vaultIx` and becomes the SignV2 preInstruction.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
interface AssembleSignV2Args {
|
|
35
|
+
connection: Connection;
|
|
36
|
+
swigAddress: PublicKey;
|
|
37
|
+
feePayer: PublicKey;
|
|
38
|
+
/** The single preceding instruction Swig ProgramExec authenticates against. */
|
|
39
|
+
vaultIx: TransactionInstruction;
|
|
40
|
+
transfers: TabTransfer[];
|
|
41
|
+
}
|
|
42
|
+
type AssembleSignV2 = (args: AssembleSignV2Args) => Promise<TransactionInstruction[]>;
|
|
43
|
+
/** Real SignV2 assembler — mirrors factoring/instantPayout.ts defaultAssembleSignV2. */
|
|
44
|
+
declare const defaultAssembleSignV2: AssembleSignV2;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* settleTab — the central ./tab verb. Composes the atomic 3-instruction tab
|
|
48
|
+
* settle: [Ed25519 precompile over the voucher] + [settle_tab_voucher] +
|
|
49
|
+
* [Swig SignV2 transfer of the delta]. The delta (cumulative - priorSpent) is
|
|
50
|
+
* computed from a FRESH on-chain read done INSIDE this verb. On-chain
|
|
51
|
+
* settle_tab_voucher re-validates monotonicity, so a stale read fails safe.
|
|
52
|
+
* Returns instructions; does NOT send. Promoted from dexter-facilitator tabSettle.ts.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
interface SettleTabParams {
|
|
56
|
+
connection: Connection;
|
|
57
|
+
vaultPda: PublicKey;
|
|
58
|
+
swigAddress: PublicKey;
|
|
59
|
+
channelId: Uint8Array;
|
|
60
|
+
cumulativeAmount: bigint;
|
|
61
|
+
sequenceNumber: number;
|
|
62
|
+
sessionSigner: Ed25519Signer;
|
|
63
|
+
sellerAta: PublicKey;
|
|
64
|
+
feePayer: PublicKey;
|
|
65
|
+
/** Must equal the vault's recorded dexter_authority; the settle_tab_voucher signer. */
|
|
66
|
+
dexterAuthority: PublicKey;
|
|
67
|
+
assembleSignV2?: AssembleSignV2;
|
|
68
|
+
readPriorSpent?: (connection: Connection, vaultPda: PublicKey) => Promise<bigint>;
|
|
69
|
+
}
|
|
70
|
+
declare function settleTab(p: SettleTabParams): Promise<TransactionInstruction[]>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* readTabMeter — READ-ONLY tab reporter. Reports remaining headroom under the
|
|
74
|
+
* session cap; NEVER refuses. The on-chain cap guard is authoritative; a
|
|
75
|
+
* client-side refuser would invite a stale-cache TOCTOU bug.
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
interface TabMeter {
|
|
79
|
+
spent: bigint;
|
|
80
|
+
maxAmount: bigint;
|
|
81
|
+
remaining: bigint;
|
|
82
|
+
}
|
|
83
|
+
declare function readTabMeter(connection: Connection, vaultPda: PublicKey, read?: (c: Connection, v: PublicKey) => Promise<VaultStateFull>): Promise<TabMeter>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Credit verbs — the tab that can spend PAST the balance. Each wraps a proven,
|
|
87
|
+
* mainnet-tested credit instruction with the SignV2 transfer, same shape as
|
|
88
|
+
* settleTab. WHOSE-SWIG: draw = FINANCIER funds → seller; repay + seize = USER
|
|
89
|
+
* funds → financier. Returns instructions; does NOT send.
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
interface DrawCreditParams {
|
|
93
|
+
connection: Connection;
|
|
94
|
+
userVaultPda: PublicKey;
|
|
95
|
+
financierSwig: PublicKey;
|
|
96
|
+
amount: bigint;
|
|
97
|
+
recoveryWindowSeconds: bigint;
|
|
98
|
+
dexterAuthority: PublicKey;
|
|
99
|
+
sellerAta: PublicKey;
|
|
100
|
+
feePayer: PublicKey;
|
|
101
|
+
assembleSignV2?: AssembleSignV2;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The borrow. draw_credit moves funds FINANCIER → seller, so the SignV2 transfer
|
|
105
|
+
* spends the FINANCIER swig. buildDrawCreditInstruction derives the financier's
|
|
106
|
+
* swig_wallet_address PDA off-chain and passes it as an account; the on-chain
|
|
107
|
+
* program validates it.
|
|
108
|
+
*/
|
|
109
|
+
declare function drawCredit(p: DrawCreditParams): Promise<TransactionInstruction[]>;
|
|
110
|
+
interface RepayCreditParams {
|
|
111
|
+
connection: Connection;
|
|
112
|
+
userVaultPda: PublicKey;
|
|
113
|
+
userSwig: PublicKey;
|
|
114
|
+
amount: bigint;
|
|
115
|
+
dexterAuthority: PublicKey;
|
|
116
|
+
financierAta: PublicKey;
|
|
117
|
+
feePayer: PublicKey;
|
|
118
|
+
assembleSignV2?: AssembleSignV2;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The paydown. repay_credit moves funds USER → financier, so the SignV2 transfer
|
|
122
|
+
* spends the USER swig. buildRepayCreditInstruction takes the user swig as
|
|
123
|
+
* `swigAddress`, derives its swig_wallet_address PDA off-chain and passes it as
|
|
124
|
+
* an account; the on-chain program validates it.
|
|
125
|
+
*/
|
|
126
|
+
declare function repayCredit(p: RepayCreditParams): Promise<TransactionInstruction[]>;
|
|
127
|
+
interface SeizeCollateralParams {
|
|
128
|
+
connection: Connection;
|
|
129
|
+
userVaultPda: PublicKey;
|
|
130
|
+
userSwig: PublicKey;
|
|
131
|
+
dexterAuthority: PublicKey;
|
|
132
|
+
financierAta: PublicKey;
|
|
133
|
+
feePayer: PublicKey;
|
|
134
|
+
seizeAmount: bigint;
|
|
135
|
+
assembleSignV2?: AssembleSignV2;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The deadline liquidation. seize_collateral moves the borrowed slice USER →
|
|
139
|
+
* financier, so the SignV2 transfer spends the USER swig. The on-chain
|
|
140
|
+
* SeizeCollateralArgs is empty (the contract zeroes vault.borrowed); seizeAmount
|
|
141
|
+
* is used ONLY for the SignV2 transfer leg — the snapshot of what's owed.
|
|
142
|
+
*/
|
|
143
|
+
declare function seizeCollateral(p: SeizeCollateralParams): Promise<TransactionInstruction[]>;
|
|
144
|
+
|
|
145
|
+
export { type AssembleSignV2, type AssembleSignV2Args, type DrawCreditParams, type OpenTabParams, type RepayCreditParams, type SeizeCollateralParams, type SettleTabParams, type TabMeter, type TabTransfer, defaultAssembleSignV2, drawCredit, openTab, readTabMeter, repayCredit, seizeCollateral, settleTab };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { PublicKey, TransactionInstruction, Connection } from '@solana/web3.js';
|
|
2
|
+
import { Ed25519Signer } from '../signers/types.js';
|
|
3
|
+
import { VaultStateFull } from '../types.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* openTab — composes the settle_voucher(increment) leg that raises the tab's
|
|
7
|
+
* outstanding and arms it. Returns instructions; does NOT send.
|
|
8
|
+
*
|
|
9
|
+
* Note: buildSettleVoucherInstruction needs only { vaultPda, dexterAuthority,
|
|
10
|
+
* amount, increment } — there is no swigAddress param, so we don't accept one
|
|
11
|
+
* (no lying/unused params).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
interface OpenTabParams {
|
|
15
|
+
vaultPda: PublicKey;
|
|
16
|
+
amount: bigint;
|
|
17
|
+
dexterAuthority: PublicKey;
|
|
18
|
+
}
|
|
19
|
+
declare function openTab(p: OpenTabParams): Promise<TransactionInstruction[]>;
|
|
20
|
+
|
|
21
|
+
/** A single SignV2 transfer leg (destination + amount). */
|
|
22
|
+
interface TabTransfer {
|
|
23
|
+
destinationAta: PublicKey;
|
|
24
|
+
amount: bigint;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The injectable Swig SignV2 assembler for ./tab verbs. Default wires the real
|
|
29
|
+
* @swig-wallet/kit; tests inject a fake. Mirrors factoring/instantPayout.ts.
|
|
30
|
+
* The vault instruction (settle_tab_voucher / draw_credit / etc.) is passed as
|
|
31
|
+
* `vaultIx` and becomes the SignV2 preInstruction.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
interface AssembleSignV2Args {
|
|
35
|
+
connection: Connection;
|
|
36
|
+
swigAddress: PublicKey;
|
|
37
|
+
feePayer: PublicKey;
|
|
38
|
+
/** The single preceding instruction Swig ProgramExec authenticates against. */
|
|
39
|
+
vaultIx: TransactionInstruction;
|
|
40
|
+
transfers: TabTransfer[];
|
|
41
|
+
}
|
|
42
|
+
type AssembleSignV2 = (args: AssembleSignV2Args) => Promise<TransactionInstruction[]>;
|
|
43
|
+
/** Real SignV2 assembler — mirrors factoring/instantPayout.ts defaultAssembleSignV2. */
|
|
44
|
+
declare const defaultAssembleSignV2: AssembleSignV2;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* settleTab — the central ./tab verb. Composes the atomic 3-instruction tab
|
|
48
|
+
* settle: [Ed25519 precompile over the voucher] + [settle_tab_voucher] +
|
|
49
|
+
* [Swig SignV2 transfer of the delta]. The delta (cumulative - priorSpent) is
|
|
50
|
+
* computed from a FRESH on-chain read done INSIDE this verb. On-chain
|
|
51
|
+
* settle_tab_voucher re-validates monotonicity, so a stale read fails safe.
|
|
52
|
+
* Returns instructions; does NOT send. Promoted from dexter-facilitator tabSettle.ts.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
interface SettleTabParams {
|
|
56
|
+
connection: Connection;
|
|
57
|
+
vaultPda: PublicKey;
|
|
58
|
+
swigAddress: PublicKey;
|
|
59
|
+
channelId: Uint8Array;
|
|
60
|
+
cumulativeAmount: bigint;
|
|
61
|
+
sequenceNumber: number;
|
|
62
|
+
sessionSigner: Ed25519Signer;
|
|
63
|
+
sellerAta: PublicKey;
|
|
64
|
+
feePayer: PublicKey;
|
|
65
|
+
/** Must equal the vault's recorded dexter_authority; the settle_tab_voucher signer. */
|
|
66
|
+
dexterAuthority: PublicKey;
|
|
67
|
+
assembleSignV2?: AssembleSignV2;
|
|
68
|
+
readPriorSpent?: (connection: Connection, vaultPda: PublicKey) => Promise<bigint>;
|
|
69
|
+
}
|
|
70
|
+
declare function settleTab(p: SettleTabParams): Promise<TransactionInstruction[]>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* readTabMeter — READ-ONLY tab reporter. Reports remaining headroom under the
|
|
74
|
+
* session cap; NEVER refuses. The on-chain cap guard is authoritative; a
|
|
75
|
+
* client-side refuser would invite a stale-cache TOCTOU bug.
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
interface TabMeter {
|
|
79
|
+
spent: bigint;
|
|
80
|
+
maxAmount: bigint;
|
|
81
|
+
remaining: bigint;
|
|
82
|
+
}
|
|
83
|
+
declare function readTabMeter(connection: Connection, vaultPda: PublicKey, read?: (c: Connection, v: PublicKey) => Promise<VaultStateFull>): Promise<TabMeter>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Credit verbs — the tab that can spend PAST the balance. Each wraps a proven,
|
|
87
|
+
* mainnet-tested credit instruction with the SignV2 transfer, same shape as
|
|
88
|
+
* settleTab. WHOSE-SWIG: draw = FINANCIER funds → seller; repay + seize = USER
|
|
89
|
+
* funds → financier. Returns instructions; does NOT send.
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
interface DrawCreditParams {
|
|
93
|
+
connection: Connection;
|
|
94
|
+
userVaultPda: PublicKey;
|
|
95
|
+
financierSwig: PublicKey;
|
|
96
|
+
amount: bigint;
|
|
97
|
+
recoveryWindowSeconds: bigint;
|
|
98
|
+
dexterAuthority: PublicKey;
|
|
99
|
+
sellerAta: PublicKey;
|
|
100
|
+
feePayer: PublicKey;
|
|
101
|
+
assembleSignV2?: AssembleSignV2;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The borrow. draw_credit moves funds FINANCIER → seller, so the SignV2 transfer
|
|
105
|
+
* spends the FINANCIER swig. buildDrawCreditInstruction derives the financier's
|
|
106
|
+
* swig_wallet_address PDA off-chain and passes it as an account; the on-chain
|
|
107
|
+
* program validates it.
|
|
108
|
+
*/
|
|
109
|
+
declare function drawCredit(p: DrawCreditParams): Promise<TransactionInstruction[]>;
|
|
110
|
+
interface RepayCreditParams {
|
|
111
|
+
connection: Connection;
|
|
112
|
+
userVaultPda: PublicKey;
|
|
113
|
+
userSwig: PublicKey;
|
|
114
|
+
amount: bigint;
|
|
115
|
+
dexterAuthority: PublicKey;
|
|
116
|
+
financierAta: PublicKey;
|
|
117
|
+
feePayer: PublicKey;
|
|
118
|
+
assembleSignV2?: AssembleSignV2;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The paydown. repay_credit moves funds USER → financier, so the SignV2 transfer
|
|
122
|
+
* spends the USER swig. buildRepayCreditInstruction takes the user swig as
|
|
123
|
+
* `swigAddress`, derives its swig_wallet_address PDA off-chain and passes it as
|
|
124
|
+
* an account; the on-chain program validates it.
|
|
125
|
+
*/
|
|
126
|
+
declare function repayCredit(p: RepayCreditParams): Promise<TransactionInstruction[]>;
|
|
127
|
+
interface SeizeCollateralParams {
|
|
128
|
+
connection: Connection;
|
|
129
|
+
userVaultPda: PublicKey;
|
|
130
|
+
userSwig: PublicKey;
|
|
131
|
+
dexterAuthority: PublicKey;
|
|
132
|
+
financierAta: PublicKey;
|
|
133
|
+
feePayer: PublicKey;
|
|
134
|
+
seizeAmount: bigint;
|
|
135
|
+
assembleSignV2?: AssembleSignV2;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The deadline liquidation. seize_collateral moves the borrowed slice USER →
|
|
139
|
+
* financier, so the SignV2 transfer spends the USER swig. The on-chain
|
|
140
|
+
* SeizeCollateralArgs is empty (the contract zeroes vault.borrowed); seizeAmount
|
|
141
|
+
* is used ONLY for the SignV2 transfer leg — the snapshot of what's owed.
|
|
142
|
+
*/
|
|
143
|
+
declare function seizeCollateral(p: SeizeCollateralParams): Promise<TransactionInstruction[]>;
|
|
144
|
+
|
|
145
|
+
export { type AssembleSignV2, type AssembleSignV2Args, type DrawCreditParams, type OpenTabParams, type RepayCreditParams, type SeizeCollateralParams, type SettleTabParams, type TabMeter, type TabTransfer, defaultAssembleSignV2, drawCredit, openTab, readTabMeter, repayCredit, seizeCollateral, settleTab };
|