@lightconexyz/lightcone-sdk 0.8.2 → 0.8.3-rc.44
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 +10 -7
- package/dist/domain/position/client.d.ts +9 -9
- package/dist/domain/position/client.d.ts.map +1 -1
- package/dist/domain/position/client.js +40 -40
- package/dist/domain/position/client.js.map +1 -1
- package/dist/domain/position/index.d.ts +4 -4
- package/dist/domain/position/index.d.ts.map +1 -1
- package/dist/domain/position/index.js.map +1 -1
- package/dist/domain/position/state.d.ts +20 -17
- package/dist/domain/position/state.d.ts.map +1 -1
- package/dist/domain/position/state.js +39 -28
- package/dist/domain/position/state.js.map +1 -1
- package/dist/prelude.d.ts +1 -1
- package/dist/prelude.d.ts.map +1 -1
- package/dist/prelude.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -229,12 +229,15 @@ signed-64-bit admission rules; no tick or size normalization is implicit.
|
|
|
229
229
|
`native_sol_balance` alongside the separate mint-keyed SPL map. Initialize
|
|
230
230
|
`WalletDepositBalancesState` with `applyRestSnapshot(wallet, snapshot)` and feed
|
|
231
231
|
the outer `wallet_deposit_balances` channel's nested snapshot, absolute SPL,
|
|
232
|
-
absolute native-SOL, and status events to `applyEvent()`.
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
232
|
+
absolute native-SOL, and status events to `applyEvent()`. Both methods accept an
|
|
233
|
+
optional minimum snapshot slot; only a complete snapshot below that floor is
|
|
234
|
+
ignored without mutation, while an equal slot and every balance/status event
|
|
235
|
+
keep their existing behavior. Without a floor, complete snapshots replace state
|
|
236
|
+
even after a higher incremental-update slot. Status and wrong-wallet events do not mutate
|
|
237
|
+
it, pre-baseline balance updates are ignored, and explicit-zero SPL updates
|
|
238
|
+
remove their mint. Matching SPL updates with invalid or negative
|
|
236
239
|
idle balances return `rejected` without mutation. `contextSlot` records the latest accepted
|
|
237
|
-
|
|
240
|
+
balance observation rather than enforcing global monotonic ordering.
|
|
238
241
|
`combinedSolBalance()` sums native SOL and canonical WSOL with `bigint` precision
|
|
239
242
|
while retaining both stored values. REST response types are trusted rather than
|
|
240
243
|
runtime-decoded; WebSocket frames are validated strictly, while malformed REST
|
|
@@ -281,7 +284,7 @@ Unwrap-all accepts no partial amount and closes the entire positive canonical
|
|
|
281
284
|
account back to the same wallet. Its `SolActionCosts` fields contain the fresh fee, zero
|
|
282
285
|
upfront rent, no account creation, and no sponsorship. Availability reserves
|
|
283
286
|
only that fee rather than the ordinary persistent-account floor;
|
|
284
|
-
`unwrapAllSolBalanceAvailability(
|
|
287
|
+
`unwrapAllSolBalanceAvailability(breakdown, costs)` validates that complete
|
|
285
288
|
cost tuple before deriving fee-only fields. The
|
|
286
289
|
native delta credits every live account lamport, including refunded rent or
|
|
287
290
|
direct donations, minus the fee and removes the full canonical token amount.
|
|
@@ -500,7 +503,7 @@ excluded from routine example runs.
|
|
|
500
503
|
|---------|-------------|
|
|
501
504
|
| [`ws_book_and_trades`](examples/ws_book_and_trades.ts) | Live orderbook depth with `OrderbookState` state + rolling `TradeHistory` buffer |
|
|
502
505
|
| [`ws_ticker_and_prices`](examples/ws_ticker_and_prices.ts) | Best bid/ask ticker + price history candles with `PriceHistoryState` |
|
|
503
|
-
| [`ws_user_and_market`](examples/ws_user_and_market.ts) |
|
|
506
|
+
| [`ws_user_and_market`](examples/ws_user_and_market.ts) | Read-only authenticated user/market subscriptions plus one reduced Trading Wallet balance snapshot |
|
|
504
507
|
|
|
505
508
|
## Error Handling
|
|
506
509
|
|
|
@@ -14,8 +14,8 @@ import { DepositBuilder, MergeBuilder, WithdrawBuilder, RedeemWinningsBuilder, W
|
|
|
14
14
|
* closure.
|
|
15
15
|
*/
|
|
16
16
|
export type SolActionKind = "split" | "merge" | "redeem" | "nativeWithdraw" | "wrap" | "unwrapAll";
|
|
17
|
-
/** Expected changes to the separately authoritative SOL
|
|
18
|
-
export interface
|
|
17
|
+
/** Expected changes to the separately authoritative SOL balances. */
|
|
18
|
+
export interface SolBalanceDelta {
|
|
19
19
|
/** System-account change in lamports, including unsponsored costs. */
|
|
20
20
|
nativeLamports: bigint;
|
|
21
21
|
/** Persistent canonical WSOL ATA change in lamports. */
|
|
@@ -29,10 +29,10 @@ export interface SolActionPlan {
|
|
|
29
29
|
transaction: Transaction;
|
|
30
30
|
/** Live fee/rent observations and explicit sponsorship capability. */
|
|
31
31
|
costs: SolActionCosts;
|
|
32
|
-
/**
|
|
32
|
+
/** Balance totals after action-specific native reserve. */
|
|
33
33
|
availability: SolBalanceAvailability;
|
|
34
|
-
/**
|
|
35
|
-
expectedDelta:
|
|
34
|
+
/** Balance projection that does not replace authoritative state. */
|
|
35
|
+
expectedDelta: SolBalanceDelta;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* Derive the cross-SDK temporary-account seed for native withdrawal.
|
|
@@ -93,7 +93,7 @@ export declare class Positions {
|
|
|
93
93
|
/**
|
|
94
94
|
* Fetch a complete authenticated SPL and native-SOL balance snapshot.
|
|
95
95
|
*
|
|
96
|
-
* `minContextSlot` lower-bounds the
|
|
96
|
+
* `minContextSlot` lower-bounds the complete balance snapshot. Native SOL is
|
|
97
97
|
* required canonical nine-decimal text and remains outside the SPL map. The
|
|
98
98
|
* generic HTTP layer trusts that shape at runtime; WebSocket frames are decoded
|
|
99
99
|
* strictly, while malformed REST exact values fail later when state scales them.
|
|
@@ -124,7 +124,7 @@ export declare class Positions {
|
|
|
124
124
|
* and `SyncNative`. Availability uses the ordinary reserve floor.
|
|
125
125
|
*
|
|
126
126
|
* Callers rebuild immediately before prepared submission. They retain the
|
|
127
|
-
* returned
|
|
127
|
+
* returned balance projection until a complete snapshot covers the confirmed
|
|
128
128
|
* slot. An uncertain outcome requires authoritative refresh before another plan.
|
|
129
129
|
*/
|
|
130
130
|
planWrapSol(amountLamports: bigint, state: WalletDepositBalancesState): Promise<SolActionPlan>;
|
|
@@ -140,7 +140,7 @@ export declare class Positions {
|
|
|
140
140
|
* native SOL to fund that fee without relying on the later account transfer.
|
|
141
141
|
*
|
|
142
142
|
* Callers rebuild immediately before prepared submission. They retain the
|
|
143
|
-
* returned
|
|
143
|
+
* returned balance projection until a complete snapshot covers the confirmed
|
|
144
144
|
* slot. Signing, submission, or confirmation uncertainty requires authoritative
|
|
145
145
|
* refresh and does not authorize automatic resubmission.
|
|
146
146
|
*/
|
|
@@ -207,7 +207,7 @@ export declare class Positions {
|
|
|
207
207
|
private createCanonicalWsolAccount;
|
|
208
208
|
/** Read canonical-account existence and upfront rent for merge/redeem plans. */
|
|
209
209
|
private receivePlanContext;
|
|
210
|
-
/** Finish merge/redeem planning with live fee authority and
|
|
210
|
+
/** Finish merge/redeem planning with live fee authority and balance deltas. */
|
|
211
211
|
private finishReceivePlan;
|
|
212
212
|
/**
|
|
213
213
|
* Build the sole WSOL-to-native path without closing canonical authority.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/domain/position/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAET,WAAW,EACX,KAAK,sBAAsB,EAC5B,MAAM,iBAAiB,CAAC;AAezB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AA6BnD,OAAO,KAAK,EACV,QAAQ,IAAI,eAAe,EAC3B,oBAAoB,EACpB,qCAAqC,EACrC,0BAA0B,EAC1B,wBAAwB,EACxB,0BAA0B,EAC1B,qBAAqB,EACrB,yBAAyB,EACzB,2BAA2B,EAC3B,wBAAwB,EACxB,sBAAsB,EACtB,gCAAgC,EACjC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAE3B,KAAK,0BAA0B,EAChC,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EACL,cAAc,EACd,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,EAC3B,sBAAsB,EACtB,yBAAyB,EACzB,4BAA4B,EAC7B,MAAM,YAAY,CAAC;AAOpB;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GACrB,OAAO,GACP,OAAO,GACP,QAAQ,GACR,gBAAgB,GAChB,MAAM,GACN,WAAW,CAAC;AAEhB,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/domain/position/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAET,WAAW,EACX,KAAK,sBAAsB,EAC5B,MAAM,iBAAiB,CAAC;AAezB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AA6BnD,OAAO,KAAK,EACV,QAAQ,IAAI,eAAe,EAC3B,oBAAoB,EACpB,qCAAqC,EACrC,0BAA0B,EAC1B,wBAAwB,EACxB,0BAA0B,EAC1B,qBAAqB,EACrB,yBAAyB,EACzB,2BAA2B,EAC3B,wBAAwB,EACxB,sBAAsB,EACtB,gCAAgC,EACjC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAE3B,KAAK,0BAA0B,EAChC,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EACL,cAAc,EACd,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,EAC3B,sBAAsB,EACtB,yBAAyB,EACzB,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
*
|
|
155
|
-
* `minContextSlot` lower-bounds the
|
|
155
|
+
* `minContextSlot` lower-bounds the complete balance snapshot. Native SOL is
|
|
156
156
|
* required canonical nine-decimal text and remains outside the SPL map. The
|
|
157
157
|
* generic HTTP layer trusts that shape at runtime; WebSocket frames are decoded
|
|
158
158
|
* strictly, while malformed REST exact values fail later when state scales them.
|
|
@@ -195,21 +195,21 @@ class Positions {
|
|
|
195
195
|
* and `SyncNative`. Availability uses the ordinary reserve floor.
|
|
196
196
|
*
|
|
197
197
|
* Callers rebuild immediately before prepared submission. They retain the
|
|
198
|
-
* returned
|
|
198
|
+
* returned balance projection until a complete snapshot covers the confirmed
|
|
199
199
|
* slot. An uncertain outcome requires authoritative refresh before another plan.
|
|
200
200
|
*/
|
|
201
201
|
async planWrapSol(amountLamports, state) {
|
|
202
202
|
assertSolActionAmount(amountLamports, "wrap");
|
|
203
203
|
const wallet = this.conversionPlanningWallet(state);
|
|
204
|
-
const
|
|
204
|
+
const breakdown = state.solBalanceBreakdown();
|
|
205
205
|
const rpc = new rpc_1.Rpc(this.client);
|
|
206
206
|
const canonical = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, wallet);
|
|
207
207
|
const account = await rpc.canonicalWsolAccountInfo(canonical, wallet);
|
|
208
|
-
if (!account &&
|
|
208
|
+
if (!account && breakdown.canonicalWsolLamports > 0n) {
|
|
209
209
|
throw error_1.SdkError.validation("canonical WSOL balance is positive but its account is unavailable");
|
|
210
210
|
}
|
|
211
211
|
if (account &&
|
|
212
|
-
account.tokenAmountLamports !==
|
|
212
|
+
account.tokenAmountLamports !== breakdown.canonicalWsolLamports) {
|
|
213
213
|
throw error_1.SdkError.validation("live canonical WSOL amount does not match wallet balance state");
|
|
214
214
|
}
|
|
215
215
|
if (account &&
|
|
@@ -234,12 +234,12 @@ class Positions {
|
|
|
234
234
|
createsCanonicalWsolAccount,
|
|
235
235
|
sponsored: false,
|
|
236
236
|
};
|
|
237
|
-
const availability = (0, state_1.solBalanceAvailability)(
|
|
237
|
+
const availability = (0, state_1.solBalanceAvailability)(breakdown, costs);
|
|
238
238
|
const requiredNativeLamports = amountLamports + availability.reserveLamports;
|
|
239
239
|
if (requiredNativeLamports > MAX_U64) {
|
|
240
240
|
throw error_1.SdkError.validation("wrap amount and transaction reserve exceed u64 lamports");
|
|
241
241
|
}
|
|
242
|
-
if (
|
|
242
|
+
if (breakdown.nativeLamports < requiredNativeLamports) {
|
|
243
243
|
throw error_1.SdkError.validation("native SOL cannot fund the wrap amount and transaction reserve");
|
|
244
244
|
}
|
|
245
245
|
return {
|
|
@@ -265,14 +265,14 @@ class Positions {
|
|
|
265
265
|
* native SOL to fund that fee without relying on the later account transfer.
|
|
266
266
|
*
|
|
267
267
|
* Callers rebuild immediately before prepared submission. They retain the
|
|
268
|
-
* returned
|
|
268
|
+
* returned balance projection until a complete snapshot covers the confirmed
|
|
269
269
|
* slot. Signing, submission, or confirmation uncertainty requires authoritative
|
|
270
270
|
* refresh and does not authorize automatic resubmission.
|
|
271
271
|
*/
|
|
272
272
|
async planUnwrapWsolAll(state) {
|
|
273
273
|
const wallet = this.conversionPlanningWallet(state);
|
|
274
|
-
const
|
|
275
|
-
if (
|
|
274
|
+
const breakdown = state.solBalanceBreakdown();
|
|
275
|
+
if (breakdown.canonicalWsolLamports === 0n) {
|
|
276
276
|
throw error_1.SdkError.validation("unwrap-all requires a positive canonical WSOL balance");
|
|
277
277
|
}
|
|
278
278
|
const rpc = new rpc_1.Rpc(this.client);
|
|
@@ -281,7 +281,7 @@ class Positions {
|
|
|
281
281
|
if (!account) {
|
|
282
282
|
throw error_1.SdkError.validation("canonical WSOL account is required for unwrap-all");
|
|
283
283
|
}
|
|
284
|
-
if (account.tokenAmountLamports !==
|
|
284
|
+
if (account.tokenAmountLamports !== breakdown.canonicalWsolLamports) {
|
|
285
285
|
throw error_1.SdkError.validation("live canonical WSOL amount does not match wallet balance state");
|
|
286
286
|
}
|
|
287
287
|
const transaction = this.buildUnwrapWsolAllTransaction(wallet);
|
|
@@ -294,8 +294,8 @@ class Positions {
|
|
|
294
294
|
};
|
|
295
295
|
// Unwrap-all removes the persistent account, so its availability validates
|
|
296
296
|
// SolActionCosts and reserves the fee without the ordinary account floor.
|
|
297
|
-
const availability = (0, state_1.unwrapAllSolBalanceAvailability)(
|
|
298
|
-
const projectedNativeLamports =
|
|
297
|
+
const availability = (0, state_1.unwrapAllSolBalanceAvailability)(breakdown, costs);
|
|
298
|
+
const projectedNativeLamports = breakdown.nativeLamports + account.accountLamports - feeLamports;
|
|
299
299
|
if (projectedNativeLamports > MAX_U64) {
|
|
300
300
|
throw error_1.SdkError.validation("unwrap-all projected native SOL exceeds the transaction u64 range");
|
|
301
301
|
}
|
|
@@ -306,7 +306,7 @@ class Positions {
|
|
|
306
306
|
availability,
|
|
307
307
|
expectedDelta: {
|
|
308
308
|
nativeLamports: account.accountLamports - feeLamports,
|
|
309
|
-
canonicalWsolLamports: -
|
|
309
|
+
canonicalWsolLamports: -breakdown.canonicalWsolLamports,
|
|
310
310
|
},
|
|
311
311
|
};
|
|
312
312
|
}
|
|
@@ -319,15 +319,15 @@ class Positions {
|
|
|
319
319
|
assertUnsponsoredPlan(sponsored);
|
|
320
320
|
assertSolActionAmount(amountLamports, "split");
|
|
321
321
|
const wallet = this.planningWallet(state);
|
|
322
|
-
const
|
|
322
|
+
const breakdown = state.solBalanceBreakdown();
|
|
323
323
|
const rpc = new rpc_1.Rpc(this.client);
|
|
324
324
|
const canonical = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, wallet);
|
|
325
325
|
const canonicalExists = await rpc.canonicalWsolAccountExists(canonical, wallet);
|
|
326
|
-
if (
|
|
326
|
+
if (breakdown.canonicalWsolLamports > 0n && !canonicalExists) {
|
|
327
327
|
throw error_1.SdkError.validation("canonical WSOL balance is positive but its account is unavailable");
|
|
328
328
|
}
|
|
329
|
-
const shortfall = amountLamports >
|
|
330
|
-
? amountLamports -
|
|
329
|
+
const shortfall = amountLamports > breakdown.canonicalWsolLamports
|
|
330
|
+
? amountLamports - breakdown.canonicalWsolLamports
|
|
331
331
|
: 0n;
|
|
332
332
|
const upfrontRentLamports = canonicalExists
|
|
333
333
|
? 0n
|
|
@@ -352,11 +352,11 @@ class Positions {
|
|
|
352
352
|
createsCanonicalWsolAccount: !canonicalExists,
|
|
353
353
|
sponsored,
|
|
354
354
|
};
|
|
355
|
-
const availability = (0, state_1.solBalanceAvailability)(
|
|
355
|
+
const availability = (0, state_1.solBalanceAvailability)(breakdown, costs);
|
|
356
356
|
if (amountLamports > availability.spendableLamports) {
|
|
357
357
|
throw error_1.SdkError.validation("split amount exceeds spendable SOL after transaction reserve");
|
|
358
358
|
}
|
|
359
|
-
if (shortfall + availability.reserveLamports >
|
|
359
|
+
if (shortfall + availability.reserveLamports > breakdown.nativeLamports) {
|
|
360
360
|
throw error_1.SdkError.validation("native SOL cannot fund the wrap shortfall and transaction reserve");
|
|
361
361
|
}
|
|
362
362
|
const walletCosts = sponsored ? 0n : feeLamports + upfrontRentLamports;
|
|
@@ -381,7 +381,7 @@ class Positions {
|
|
|
381
381
|
assertSolActionAmount(amountLamports, "merge");
|
|
382
382
|
const wallet = this.planningWallet(state);
|
|
383
383
|
const transaction = new web3_js_1.Transaction({ feePayer: wallet });
|
|
384
|
-
const { rpc,
|
|
384
|
+
const { rpc, breakdown, canonicalExists, upfrontRentLamports } = await this.receivePlanContext(wallet, state);
|
|
385
385
|
if (!canonicalExists) {
|
|
386
386
|
transaction.add(this.createCanonicalWsolAccount(wallet));
|
|
387
387
|
}
|
|
@@ -391,7 +391,7 @@ class Positions {
|
|
|
391
391
|
depositMint: spl_token_1.NATIVE_MINT,
|
|
392
392
|
amount: amountLamports,
|
|
393
393
|
}, market.numOutcomes, this.client.programId));
|
|
394
|
-
return this.finishReceivePlan("merge", amountLamports, transaction, rpc,
|
|
394
|
+
return this.finishReceivePlan("merge", amountLamports, transaction, rpc, breakdown, upfrontRentLamports, !canonicalExists, sponsored);
|
|
395
395
|
}
|
|
396
396
|
/**
|
|
397
397
|
* Plan a redemption that leaves returned WSOL in the persistent canonical ATA.
|
|
@@ -405,7 +405,7 @@ class Positions {
|
|
|
405
405
|
(0, utils_1.validateOutcomeIndex)(outcomeIndex, numOutcomes);
|
|
406
406
|
const wallet = this.planningWallet(state);
|
|
407
407
|
const transaction = new web3_js_1.Transaction({ feePayer: wallet });
|
|
408
|
-
const { rpc,
|
|
408
|
+
const { rpc, breakdown, canonicalExists, upfrontRentLamports } = await this.receivePlanContext(wallet, state);
|
|
409
409
|
if (!canonicalExists) {
|
|
410
410
|
transaction.add(this.createCanonicalWsolAccount(wallet));
|
|
411
411
|
}
|
|
@@ -415,7 +415,7 @@ class Positions {
|
|
|
415
415
|
depositMint: spl_token_1.NATIVE_MINT,
|
|
416
416
|
amount: amountLamports,
|
|
417
417
|
}, outcomeIndex, this.client.programId));
|
|
418
|
-
return this.finishReceivePlan("redeem", amountLamports, transaction, rpc,
|
|
418
|
+
return this.finishReceivePlan("redeem", amountLamports, transaction, rpc, breakdown, upfrontRentLamports, !canonicalExists, sponsored);
|
|
419
419
|
}
|
|
420
420
|
/**
|
|
421
421
|
* Plan exact native SOL delivery without closing the canonical WSOL ATA.
|
|
@@ -430,7 +430,7 @@ class Positions {
|
|
|
430
430
|
assertUnsponsoredPlan(sponsored);
|
|
431
431
|
assertSolActionAmount(amountLamports, "withdraw");
|
|
432
432
|
const wallet = this.planningWallet(state);
|
|
433
|
-
const
|
|
433
|
+
const breakdown = state.solBalanceBreakdown();
|
|
434
434
|
const rpc = new rpc_1.Rpc(this.client);
|
|
435
435
|
const direct = new web3_js_1.Transaction({ feePayer: wallet }).add(web3_js_1.SystemProgram.transfer({ fromPubkey: wallet, toPubkey: recipient, lamports: amountLamports }));
|
|
436
436
|
const directFee = await rpc.prepareAndEstimateTransactionFee(direct);
|
|
@@ -440,11 +440,11 @@ class Positions {
|
|
|
440
440
|
createsCanonicalWsolAccount: false,
|
|
441
441
|
sponsored,
|
|
442
442
|
};
|
|
443
|
-
const directAvailability = (0, state_1.solBalanceAvailability)(
|
|
443
|
+
const directAvailability = (0, state_1.solBalanceAvailability)(breakdown, directCosts);
|
|
444
444
|
if (amountLamports > directAvailability.spendableLamports) {
|
|
445
445
|
throw error_1.SdkError.validation("withdraw amount exceeds spendable SOL after transaction reserve");
|
|
446
446
|
}
|
|
447
|
-
if (
|
|
447
|
+
if (breakdown.nativeLamports >=
|
|
448
448
|
amountLamports + directAvailability.reserveLamports) {
|
|
449
449
|
return {
|
|
450
450
|
kind: "nativeWithdraw",
|
|
@@ -488,12 +488,12 @@ class Positions {
|
|
|
488
488
|
createsCanonicalWsolAccount: false,
|
|
489
489
|
sponsored,
|
|
490
490
|
};
|
|
491
|
-
const initialAvailability = (0, state_1.solBalanceAvailability)(
|
|
491
|
+
const initialAvailability = (0, state_1.solBalanceAvailability)(breakdown, initialCosts);
|
|
492
492
|
const initialRequired = amountLamports + initialAvailability.reserveLamports;
|
|
493
|
-
if (initialRequired <
|
|
493
|
+
if (initialRequired < breakdown.nativeLamports) {
|
|
494
494
|
throw error_1.SdkError.validation("invalid temporary withdrawal requirement");
|
|
495
495
|
}
|
|
496
|
-
const initialTransfer = initialRequired -
|
|
496
|
+
const initialTransfer = initialRequired - breakdown.nativeLamports;
|
|
497
497
|
transaction = this.buildTemporaryNativeWithdrawal(wallet, recipient, amountLamports, initialTransfer, temporaryRent, seed, temporary);
|
|
498
498
|
transaction.recentBlockhash = blockhash;
|
|
499
499
|
transaction.lastValidBlockHeight = lastValidBlockHeight;
|
|
@@ -504,13 +504,13 @@ class Positions {
|
|
|
504
504
|
createsCanonicalWsolAccount: false,
|
|
505
505
|
sponsored,
|
|
506
506
|
};
|
|
507
|
-
const availability = (0, state_1.solBalanceAvailability)(
|
|
507
|
+
const availability = (0, state_1.solBalanceAvailability)(breakdown, costs);
|
|
508
508
|
const finalRequired = amountLamports + availability.reserveLamports;
|
|
509
|
-
if (finalRequired <
|
|
509
|
+
if (finalRequired < breakdown.nativeLamports) {
|
|
510
510
|
throw error_1.SdkError.validation("invalid temporary withdrawal requirement");
|
|
511
511
|
}
|
|
512
|
-
const canonicalTransfer = finalRequired -
|
|
513
|
-
if (canonicalTransfer >
|
|
512
|
+
const canonicalTransfer = finalRequired - breakdown.nativeLamports;
|
|
513
|
+
if (canonicalTransfer > breakdown.canonicalWsolLamports) {
|
|
514
514
|
throw error_1.SdkError.validation("canonical WSOL cannot fund the native withdrawal shortfall");
|
|
515
515
|
}
|
|
516
516
|
if (canonicalTransfer !== initialTransfer) {
|
|
@@ -631,21 +631,21 @@ class Positions {
|
|
|
631
631
|
const rpc = new rpc_1.Rpc(this.client);
|
|
632
632
|
const canonical = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, wallet);
|
|
633
633
|
const canonicalExists = await rpc.canonicalWsolAccountExists(canonical, wallet);
|
|
634
|
-
const
|
|
635
|
-
if (
|
|
634
|
+
const breakdown = state.solBalanceBreakdown();
|
|
635
|
+
if (breakdown.canonicalWsolLamports > 0n && !canonicalExists) {
|
|
636
636
|
throw error_1.SdkError.validation("canonical WSOL balance is positive but its account is unavailable");
|
|
637
637
|
}
|
|
638
638
|
return {
|
|
639
639
|
rpc,
|
|
640
|
-
|
|
640
|
+
breakdown,
|
|
641
641
|
canonicalExists,
|
|
642
642
|
upfrontRentLamports: canonicalExists
|
|
643
643
|
? 0n
|
|
644
644
|
: await rpc.minimumBalanceForRentExemption(TOKEN_ACCOUNT_SPACE),
|
|
645
645
|
};
|
|
646
646
|
}
|
|
647
|
-
/** Finish merge/redeem planning with live fee authority and
|
|
648
|
-
async finishReceivePlan(kind, amountLamports, transaction, rpc,
|
|
647
|
+
/** Finish merge/redeem planning with live fee authority and balance deltas. */
|
|
648
|
+
async finishReceivePlan(kind, amountLamports, transaction, rpc, breakdown, upfrontRentLamports, createsCanonicalWsolAccount, sponsored) {
|
|
649
649
|
const feeLamports = await rpc.prepareAndEstimateTransactionFee(transaction);
|
|
650
650
|
const costs = {
|
|
651
651
|
feeLamports,
|
|
@@ -653,7 +653,7 @@ class Positions {
|
|
|
653
653
|
createsCanonicalWsolAccount,
|
|
654
654
|
sponsored,
|
|
655
655
|
};
|
|
656
|
-
const availability = (0, state_1.solBalanceAvailability)(
|
|
656
|
+
const availability = (0, state_1.solBalanceAvailability)(breakdown, costs);
|
|
657
657
|
const walletCosts = sponsored ? 0n : feeLamports + upfrontRentLamports;
|
|
658
658
|
return {
|
|
659
659
|
kind,
|