@velocity-exchange/sdk 0.10.0 → 0.11.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/lib/browser/adminClient.d.ts +2 -1
- package/lib/browser/adminClient.js +2 -2
- package/lib/browser/idl/velocity.d.ts +117 -2
- package/lib/browser/idl/velocity.json +117 -2
- package/lib/browser/math/amm.d.ts +6 -5
- package/lib/browser/math/amm.js +39 -19
- package/lib/browser/types.d.ts +2 -0
- package/lib/browser/velocityClient.d.ts +39 -0
- package/lib/browser/velocityClient.js +69 -0
- package/lib/node/adminClient.d.ts +2 -1
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/adminClient.js +2 -2
- package/lib/node/idl/velocity.d.ts +117 -2
- package/lib/node/idl/velocity.d.ts.map +1 -1
- package/lib/node/idl/velocity.json +117 -2
- package/lib/node/math/amm.d.ts +6 -5
- package/lib/node/math/amm.d.ts.map +1 -1
- package/lib/node/math/amm.js +39 -19
- package/lib/node/types.d.ts +2 -0
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/velocityClient.d.ts +39 -0
- package/lib/node/velocityClient.d.ts.map +1 -1
- package/lib/node/velocityClient.js +69 -0
- package/package.json +1 -1
|
@@ -2604,5 +2604,6 @@ export declare enum HotRole {
|
|
|
2604
2604
|
VaultDeposit = "vaultDeposit",
|
|
2605
2605
|
MmOracleCrank = "mmOracleCrank",
|
|
2606
2606
|
AmmSpreadAdjust = "ammSpreadAdjust",
|
|
2607
|
-
FeeWithdraw = "feeWithdraw"
|
|
2607
|
+
FeeWithdraw = "feeWithdraw",
|
|
2608
|
+
AccountExtension = "accountExtension"
|
|
2608
2609
|
}
|
|
@@ -793,8 +793,7 @@ class AdminClient extends velocityClient_1.VelocityClient {
|
|
|
793
793
|
*/
|
|
794
794
|
async getMoveAmmToPriceIx(perpMarketIndex, targetPrice) {
|
|
795
795
|
const perpMarket = this.getPerpMarketAccountOrThrow(perpMarketIndex);
|
|
796
|
-
const [direction, tradeSize, _] = (0, trade_1.calculateTargetPriceTrade)(perpMarket, targetPrice, new anchor_1.BN(1000), 'quote',
|
|
797
|
-
);
|
|
796
|
+
const [direction, tradeSize, _] = (0, trade_1.calculateTargetPriceTrade)(perpMarket, targetPrice, new anchor_1.BN(1000), 'quote', this.getMMOracleDataForPerpMarket(perpMarketIndex));
|
|
798
797
|
const [newQuoteAssetAmount, newBaseAssetAmount] = (0, amm_1.calculateAmmReservesAfterSwap)(perpMarket.amm, 'quote', tradeSize, (0, amm_1.getSwapDirection)('quote', direction));
|
|
799
798
|
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
800
799
|
return await this.program.instruction.moveAmmPrice(newBaseAssetAmount, newQuoteAssetAmount, perpMarket.amm.sqrtK, {
|
|
@@ -5111,6 +5110,7 @@ var HotRole;
|
|
|
5111
5110
|
HotRole["MmOracleCrank"] = "mmOracleCrank";
|
|
5112
5111
|
HotRole["AmmSpreadAdjust"] = "ammSpreadAdjust";
|
|
5113
5112
|
HotRole["FeeWithdraw"] = "feeWithdraw";
|
|
5113
|
+
HotRole["AccountExtension"] = "accountExtension";
|
|
5114
5114
|
})(HotRole || (exports.HotRole = HotRole = {}));
|
|
5115
5115
|
/** Anchor encodes Rust enums as `{ <variant>: {} }`. */
|
|
5116
5116
|
function encodeHotRole(role) {
|
|
@@ -8,7 +8,7 @@ export type Velocity = {
|
|
|
8
8
|
"address": "vELoC1audYbSYVRXn1vPaV8Axoa9oU6BYmNGZZBDZ1P";
|
|
9
9
|
"metadata": {
|
|
10
10
|
"name": "velocity";
|
|
11
|
-
"version": "2.
|
|
11
|
+
"version": "2.165.0";
|
|
12
12
|
"spec": "0.1.0";
|
|
13
13
|
"description": "Created with Anchor";
|
|
14
14
|
};
|
|
@@ -2194,6 +2194,104 @@ export type Velocity = {
|
|
|
2194
2194
|
}
|
|
2195
2195
|
];
|
|
2196
2196
|
},
|
|
2197
|
+
{
|
|
2198
|
+
"name": "extendAccount";
|
|
2199
|
+
"docs": [
|
|
2200
|
+
"Grow a zero-copy account to the size this program build compiles in",
|
|
2201
|
+
"for its type (resolved from the account discriminator). The migration",
|
|
2202
|
+
"crank after an upgrade that appends fields to an account struct; no-op",
|
|
2203
|
+
"when already at size. Payer covers the rent-exempt shortfall (auth:",
|
|
2204
|
+
"`AccountExtension` hot key, or warm/cold admin). See",
|
|
2205
|
+
"`docs/ACCOUNT-EXTENSION.md`."
|
|
2206
|
+
];
|
|
2207
|
+
"discriminator": [
|
|
2208
|
+
234,
|
|
2209
|
+
102,
|
|
2210
|
+
194,
|
|
2211
|
+
203,
|
|
2212
|
+
150,
|
|
2213
|
+
72,
|
|
2214
|
+
62,
|
|
2215
|
+
229
|
|
2216
|
+
];
|
|
2217
|
+
"accounts": [
|
|
2218
|
+
{
|
|
2219
|
+
"name": "state";
|
|
2220
|
+
},
|
|
2221
|
+
{
|
|
2222
|
+
"name": "payer";
|
|
2223
|
+
"writable": true;
|
|
2224
|
+
"signer": true;
|
|
2225
|
+
},
|
|
2226
|
+
{
|
|
2227
|
+
"name": "authority";
|
|
2228
|
+
"signer": true;
|
|
2229
|
+
},
|
|
2230
|
+
{
|
|
2231
|
+
"name": "account";
|
|
2232
|
+
"docs": [
|
|
2233
|
+
"size) from the account discriminator"
|
|
2234
|
+
];
|
|
2235
|
+
"writable": true;
|
|
2236
|
+
},
|
|
2237
|
+
{
|
|
2238
|
+
"name": "systemProgram";
|
|
2239
|
+
"address": "11111111111111111111111111111111";
|
|
2240
|
+
}
|
|
2241
|
+
];
|
|
2242
|
+
"args": [];
|
|
2243
|
+
},
|
|
2244
|
+
{
|
|
2245
|
+
"name": "extendAccountDevnet";
|
|
2246
|
+
"docs": [
|
|
2247
|
+
"Devnet/test-only: grow a zero-copy account to an arbitrary larger size",
|
|
2248
|
+
"to exercise the extension flow before a real struct extension exists.",
|
|
2249
|
+
"Stripped from production mainnet builds; `anchor-test` keeps it so the",
|
|
2250
|
+
"integration suite (which builds with default features + `anchor-test`)",
|
|
2251
|
+
"can exercise extension end to end."
|
|
2252
|
+
];
|
|
2253
|
+
"discriminator": [
|
|
2254
|
+
58,
|
|
2255
|
+
206,
|
|
2256
|
+
231,
|
|
2257
|
+
21,
|
|
2258
|
+
136,
|
|
2259
|
+
141,
|
|
2260
|
+
180,
|
|
2261
|
+
252
|
|
2262
|
+
];
|
|
2263
|
+
"accounts": [
|
|
2264
|
+
{
|
|
2265
|
+
"name": "state";
|
|
2266
|
+
},
|
|
2267
|
+
{
|
|
2268
|
+
"name": "payer";
|
|
2269
|
+
"writable": true;
|
|
2270
|
+
"signer": true;
|
|
2271
|
+
},
|
|
2272
|
+
{
|
|
2273
|
+
"name": "authority";
|
|
2274
|
+
"signer": true;
|
|
2275
|
+
},
|
|
2276
|
+
{
|
|
2277
|
+
"name": "account";
|
|
2278
|
+
"docs": [
|
|
2279
|
+
"zero-copy discriminator"
|
|
2280
|
+
];
|
|
2281
|
+
"writable": true;
|
|
2282
|
+
},
|
|
2283
|
+
{
|
|
2284
|
+
"name": "systemProgram";
|
|
2285
|
+
"address": "11111111111111111111111111111111";
|
|
2286
|
+
}
|
|
2287
|
+
];
|
|
2288
|
+
"args": [
|
|
2289
|
+
{
|
|
2290
|
+
"name": "newLen";
|
|
2291
|
+
"type": "u64";
|
|
2292
|
+
}
|
|
2293
|
+
];
|
|
2294
|
+
},
|
|
2197
2295
|
{
|
|
2198
2296
|
"name": "fillPerpOrder";
|
|
2199
2297
|
"discriminator": [
|
|
@@ -16370,6 +16468,11 @@ export type Velocity = {
|
|
|
16370
16468
|
"code": 6366;
|
|
16371
16469
|
"name": "cannotModifyBuilderOrder";
|
|
16372
16470
|
"msg": "Cannot modify a builder-coded order; cancel and re-place instead";
|
|
16471
|
+
},
|
|
16472
|
+
{
|
|
16473
|
+
"code": 6367;
|
|
16474
|
+
"name": "invalidAccountExtension";
|
|
16475
|
+
"msg": "Invalid account extension";
|
|
16373
16476
|
}
|
|
16374
16477
|
];
|
|
16375
16478
|
"types": [
|
|
@@ -18217,6 +18320,9 @@ export type Velocity = {
|
|
|
18217
18320
|
},
|
|
18218
18321
|
{
|
|
18219
18322
|
"name": "feeWithdraw";
|
|
18323
|
+
},
|
|
18324
|
+
{
|
|
18325
|
+
"name": "accountExtension";
|
|
18220
18326
|
}
|
|
18221
18327
|
];
|
|
18222
18328
|
};
|
|
@@ -23699,12 +23805,21 @@ export type Velocity = {
|
|
|
23699
23805
|
];
|
|
23700
23806
|
"type": "pubkey";
|
|
23701
23807
|
},
|
|
23808
|
+
{
|
|
23809
|
+
"name": "hotAccountExtension";
|
|
23810
|
+
"docs": [
|
|
23811
|
+
"Hot key authorized for the `AccountExtension` role (grows zero-copy",
|
|
23812
|
+
"accounts to the deployed program's size after a struct-extending",
|
|
23813
|
+
"upgrade)."
|
|
23814
|
+
];
|
|
23815
|
+
"type": "pubkey";
|
|
23816
|
+
},
|
|
23702
23817
|
{
|
|
23703
23818
|
"name": "padding";
|
|
23704
23819
|
"type": {
|
|
23705
23820
|
"array": [
|
|
23706
23821
|
"u8",
|
|
23707
|
-
|
|
23822
|
+
239
|
|
23708
23823
|
];
|
|
23709
23824
|
};
|
|
23710
23825
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"address": "vELoC1audYbSYVRXn1vPaV8Axoa9oU6BYmNGZZBDZ1P",
|
|
3
3
|
"metadata": {
|
|
4
4
|
"name": "velocity",
|
|
5
|
-
"version": "2.
|
|
5
|
+
"version": "2.165.0",
|
|
6
6
|
"spec": "0.1.0",
|
|
7
7
|
"description": "Created with Anchor"
|
|
8
8
|
},
|
|
@@ -2188,6 +2188,104 @@
|
|
|
2188
2188
|
}
|
|
2189
2189
|
]
|
|
2190
2190
|
},
|
|
2191
|
+
{
|
|
2192
|
+
"name": "extend_account",
|
|
2193
|
+
"docs": [
|
|
2194
|
+
"Grow a zero-copy account to the size this program build compiles in",
|
|
2195
|
+
"for its type (resolved from the account discriminator). The migration",
|
|
2196
|
+
"crank after an upgrade that appends fields to an account struct; no-op",
|
|
2197
|
+
"when already at size. Payer covers the rent-exempt shortfall (auth:",
|
|
2198
|
+
"`AccountExtension` hot key, or warm/cold admin). See",
|
|
2199
|
+
"`docs/ACCOUNT-EXTENSION.md`."
|
|
2200
|
+
],
|
|
2201
|
+
"discriminator": [
|
|
2202
|
+
234,
|
|
2203
|
+
102,
|
|
2204
|
+
194,
|
|
2205
|
+
203,
|
|
2206
|
+
150,
|
|
2207
|
+
72,
|
|
2208
|
+
62,
|
|
2209
|
+
229
|
|
2210
|
+
],
|
|
2211
|
+
"accounts": [
|
|
2212
|
+
{
|
|
2213
|
+
"name": "state"
|
|
2214
|
+
},
|
|
2215
|
+
{
|
|
2216
|
+
"name": "payer",
|
|
2217
|
+
"writable": true,
|
|
2218
|
+
"signer": true
|
|
2219
|
+
},
|
|
2220
|
+
{
|
|
2221
|
+
"name": "authority",
|
|
2222
|
+
"signer": true
|
|
2223
|
+
},
|
|
2224
|
+
{
|
|
2225
|
+
"name": "account",
|
|
2226
|
+
"docs": [
|
|
2227
|
+
"size) from the account discriminator"
|
|
2228
|
+
],
|
|
2229
|
+
"writable": true
|
|
2230
|
+
},
|
|
2231
|
+
{
|
|
2232
|
+
"name": "system_program",
|
|
2233
|
+
"address": "11111111111111111111111111111111"
|
|
2234
|
+
}
|
|
2235
|
+
],
|
|
2236
|
+
"args": []
|
|
2237
|
+
},
|
|
2238
|
+
{
|
|
2239
|
+
"name": "extend_account_devnet",
|
|
2240
|
+
"docs": [
|
|
2241
|
+
"Devnet/test-only: grow a zero-copy account to an arbitrary larger size",
|
|
2242
|
+
"to exercise the extension flow before a real struct extension exists.",
|
|
2243
|
+
"Stripped from production mainnet builds; `anchor-test` keeps it so the",
|
|
2244
|
+
"integration suite (which builds with default features + `anchor-test`)",
|
|
2245
|
+
"can exercise extension end to end."
|
|
2246
|
+
],
|
|
2247
|
+
"discriminator": [
|
|
2248
|
+
58,
|
|
2249
|
+
206,
|
|
2250
|
+
231,
|
|
2251
|
+
21,
|
|
2252
|
+
136,
|
|
2253
|
+
141,
|
|
2254
|
+
180,
|
|
2255
|
+
252
|
|
2256
|
+
],
|
|
2257
|
+
"accounts": [
|
|
2258
|
+
{
|
|
2259
|
+
"name": "state"
|
|
2260
|
+
},
|
|
2261
|
+
{
|
|
2262
|
+
"name": "payer",
|
|
2263
|
+
"writable": true,
|
|
2264
|
+
"signer": true
|
|
2265
|
+
},
|
|
2266
|
+
{
|
|
2267
|
+
"name": "authority",
|
|
2268
|
+
"signer": true
|
|
2269
|
+
},
|
|
2270
|
+
{
|
|
2271
|
+
"name": "account",
|
|
2272
|
+
"docs": [
|
|
2273
|
+
"zero-copy discriminator"
|
|
2274
|
+
],
|
|
2275
|
+
"writable": true
|
|
2276
|
+
},
|
|
2277
|
+
{
|
|
2278
|
+
"name": "system_program",
|
|
2279
|
+
"address": "11111111111111111111111111111111"
|
|
2280
|
+
}
|
|
2281
|
+
],
|
|
2282
|
+
"args": [
|
|
2283
|
+
{
|
|
2284
|
+
"name": "new_len",
|
|
2285
|
+
"type": "u64"
|
|
2286
|
+
}
|
|
2287
|
+
]
|
|
2288
|
+
},
|
|
2191
2289
|
{
|
|
2192
2290
|
"name": "fill_perp_order",
|
|
2193
2291
|
"discriminator": [
|
|
@@ -16364,6 +16462,11 @@
|
|
|
16364
16462
|
"code": 6366,
|
|
16365
16463
|
"name": "CannotModifyBuilderOrder",
|
|
16366
16464
|
"msg": "Cannot modify a builder-coded order; cancel and re-place instead"
|
|
16465
|
+
},
|
|
16466
|
+
{
|
|
16467
|
+
"code": 6367,
|
|
16468
|
+
"name": "InvalidAccountExtension",
|
|
16469
|
+
"msg": "Invalid account extension"
|
|
16367
16470
|
}
|
|
16368
16471
|
],
|
|
16369
16472
|
"types": [
|
|
@@ -18211,6 +18314,9 @@
|
|
|
18211
18314
|
},
|
|
18212
18315
|
{
|
|
18213
18316
|
"name": "FeeWithdraw"
|
|
18317
|
+
},
|
|
18318
|
+
{
|
|
18319
|
+
"name": "AccountExtension"
|
|
18214
18320
|
}
|
|
18215
18321
|
]
|
|
18216
18322
|
}
|
|
@@ -23693,12 +23799,21 @@
|
|
|
23693
23799
|
],
|
|
23694
23800
|
"type": "pubkey"
|
|
23695
23801
|
},
|
|
23802
|
+
{
|
|
23803
|
+
"name": "hot_account_extension",
|
|
23804
|
+
"docs": [
|
|
23805
|
+
"Hot key authorized for the `AccountExtension` role (grows zero-copy",
|
|
23806
|
+
"accounts to the deployed program's size after a struct-extending",
|
|
23807
|
+
"upgrade)."
|
|
23808
|
+
],
|
|
23809
|
+
"type": "pubkey"
|
|
23810
|
+
},
|
|
23696
23811
|
{
|
|
23697
23812
|
"name": "padding",
|
|
23698
23813
|
"type": {
|
|
23699
23814
|
"array": [
|
|
23700
23815
|
"u8",
|
|
23701
|
-
|
|
23816
|
+
239
|
|
23702
23817
|
]
|
|
23703
23818
|
}
|
|
23704
23819
|
}
|
|
@@ -327,15 +327,16 @@ export declare function calculateSpreadBN(baseSpread: number, lastOracleReserveP
|
|
|
327
327
|
* Convenience wrapper around `calculateSpreadBN` that derives its lower-level inputs
|
|
328
328
|
* (reserve price, oracle-vs-reserve spread, live oracle std, and confidence interval) from
|
|
329
329
|
* `amm`/`marketStats`/`oraclePriceData` directly, then applies the market's manual
|
|
330
|
-
* `ammSpreadAdjustment` (%, shrink if negative/grow if positive, floored at 1) on top.
|
|
331
|
-
* `
|
|
332
|
-
* `curveUpdateIntensity` is zero
|
|
330
|
+
* `ammSpreadAdjustment` (%, shrink if negative/grow if positive, floored at 1) on top.
|
|
331
|
+
* Mirrors `update_spreads` in `vlp/amm/math/spread.rs`: the dynamic spread is computed
|
|
332
|
+
* whenever `curveUpdateIntensity` is nonzero, and only a zero `curveUpdateIntensity`
|
|
333
|
+
* falls back to `[baseSpread/2, baseSpread/2]` (truncated).
|
|
333
334
|
* @param amm AMM state to price the spread for.
|
|
334
335
|
* @param marketStats Market stats needed for volatility/funding-bias inputs.
|
|
335
|
-
* @param oraclePriceData Current oracle price data; required unless `
|
|
336
|
+
* @param oraclePriceData Current oracle price data; required unless `curveUpdateIntensity` is zero.
|
|
336
337
|
* @param now Current unix timestamp (seconds); defaults to wall-clock time if omitted.
|
|
337
338
|
* @param reservePrice Current AMM reserve price, PRICE_PRECISION (1e6); computed from `amm`'s reserves if omitted.
|
|
338
|
-
* @throws if `oraclePriceData` is omitted while `
|
|
339
|
+
* @throws if `oraclePriceData` is omitted while `curveUpdateIntensity` is nonzero.
|
|
339
340
|
* @returns `[longSpread, shortSpread]`, both BID_ASK_SPREAD_PRECISION (1e6) fraction-of-price units.
|
|
340
341
|
*/
|
|
341
342
|
export declare function calculateSpread(amm: AMM, marketStats: MarketStats, oraclePriceData?: Pick<OraclePriceData, 'price' | 'confidence'>, now?: BN, reservePrice?: BN): [number, number];
|
package/lib/browser/math/amm.js
CHANGED
|
@@ -699,27 +699,57 @@ function calculateSpreadBN(baseSpread, lastOracleReservePriceSpreadPct, lastOrac
|
|
|
699
699
|
return [longSpread, shortSpread];
|
|
700
700
|
}
|
|
701
701
|
exports.calculateSpreadBN = calculateSpreadBN;
|
|
702
|
+
/**
|
|
703
|
+
* Applies the market's manual `ammSpreadAdjustment` (%, grow if positive / shrink if
|
|
704
|
+
* negative, floored at 1) to an already-computed spread pair. Mirrors the tail of
|
|
705
|
+
* `update_spreads` in `vlp/amm/math/spread.rs`, which applies it to the frozen-curve
|
|
706
|
+
* branch as well as the dynamic one, and rounds as integer math (ceil when growing,
|
|
707
|
+
* floor when shrinking).
|
|
708
|
+
* @param amm AMM state holding `ammSpreadAdjustment`.
|
|
709
|
+
* @param longSpread Long-side spread before adjustment.
|
|
710
|
+
* @param shortSpread Short-side spread before adjustment.
|
|
711
|
+
* @returns `[longSpread, shortSpread]` after adjustment.
|
|
712
|
+
*/
|
|
713
|
+
function applyAmmSpreadAdjustment(amm, longSpread, shortSpread) {
|
|
714
|
+
if (amm.ammSpreadAdjustment > 0) {
|
|
715
|
+
const grow = (spread) => Math.max(spread + Math.ceil((spread * amm.ammSpreadAdjustment) / 100), 1);
|
|
716
|
+
return [grow(longSpread), grow(shortSpread)];
|
|
717
|
+
}
|
|
718
|
+
if (amm.ammSpreadAdjustment < 0) {
|
|
719
|
+
const shrink = (spread) => Math.max(spread - Math.floor((spread * -amm.ammSpreadAdjustment) / 100), 1);
|
|
720
|
+
return [shrink(longSpread), shrink(shortSpread)];
|
|
721
|
+
}
|
|
722
|
+
return [longSpread, shortSpread];
|
|
723
|
+
}
|
|
702
724
|
/**
|
|
703
725
|
* Convenience wrapper around `calculateSpreadBN` that derives its lower-level inputs
|
|
704
726
|
* (reserve price, oracle-vs-reserve spread, live oracle std, and confidence interval) from
|
|
705
727
|
* `amm`/`marketStats`/`oraclePriceData` directly, then applies the market's manual
|
|
706
|
-
* `ammSpreadAdjustment` (%, shrink if negative/grow if positive, floored at 1) on top.
|
|
707
|
-
* `
|
|
708
|
-
* `curveUpdateIntensity` is zero
|
|
728
|
+
* `ammSpreadAdjustment` (%, shrink if negative/grow if positive, floored at 1) on top.
|
|
729
|
+
* Mirrors `update_spreads` in `vlp/amm/math/spread.rs`: the dynamic spread is computed
|
|
730
|
+
* whenever `curveUpdateIntensity` is nonzero, and only a zero `curveUpdateIntensity`
|
|
731
|
+
* falls back to `[baseSpread/2, baseSpread/2]` (truncated).
|
|
709
732
|
* @param amm AMM state to price the spread for.
|
|
710
733
|
* @param marketStats Market stats needed for volatility/funding-bias inputs.
|
|
711
|
-
* @param oraclePriceData Current oracle price data; required unless `
|
|
734
|
+
* @param oraclePriceData Current oracle price data; required unless `curveUpdateIntensity` is zero.
|
|
712
735
|
* @param now Current unix timestamp (seconds); defaults to wall-clock time if omitted.
|
|
713
736
|
* @param reservePrice Current AMM reserve price, PRICE_PRECISION (1e6); computed from `amm`'s reserves if omitted.
|
|
714
|
-
* @throws if `oraclePriceData` is omitted while `
|
|
737
|
+
* @throws if `oraclePriceData` is omitted while `curveUpdateIntensity` is nonzero.
|
|
715
738
|
* @returns `[longSpread, shortSpread]`, both BID_ASK_SPREAD_PRECISION (1e6) fraction-of-price units.
|
|
716
739
|
*/
|
|
717
740
|
function calculateSpread(amm, marketStats, oraclePriceData, now, reservePrice) {
|
|
718
|
-
|
|
719
|
-
|
|
741
|
+
// On chain the dynamic spread is computed whenever curveUpdateIntensity > 0; a
|
|
742
|
+
// baseSpread of 0 does NOT disable it, it only lowers the floor that the vol
|
|
743
|
+
// spread is maxed against. Short-circuiting on baseSpread == 0 made the SDK
|
|
744
|
+
// report a zero-width vAMM spread on markets configured with baseSpread 0,
|
|
745
|
+
// while the program was quoting an inventory-skewed spread of >10%.
|
|
746
|
+
if (amm.curveUpdateIntensity == 0) {
|
|
747
|
+
// integer division on chain: `base_spread.safe_div(2)`
|
|
748
|
+
const halfBaseSpread = Math.floor(amm.baseSpread / 2);
|
|
749
|
+
return applyAmmSpreadAdjustment(amm, halfBaseSpread, halfBaseSpread);
|
|
720
750
|
}
|
|
721
751
|
if (!oraclePriceData) {
|
|
722
|
-
throw new Error('calculateSpread: oraclePriceData is required when
|
|
752
|
+
throw new Error('calculateSpread: oraclePriceData is required when curveUpdateIntensity is nonzero');
|
|
723
753
|
}
|
|
724
754
|
if (!reservePrice) {
|
|
725
755
|
reservePrice = calculatePrice(amm.baseAssetReserve, amm.quoteAssetReserve, amm.pegMultiplier);
|
|
@@ -733,17 +763,7 @@ function calculateSpread(amm, marketStats, oraclePriceData, now, reservePrice) {
|
|
|
733
763
|
const liveOracleStd = (0, oracles_1.calculateLiveOracleStd)(marketStats, oraclePriceData, now);
|
|
734
764
|
const confIntervalPct = (0, oracles_1.getNewOracleConfPct)(marketStats, oraclePriceData, reservePrice, now);
|
|
735
765
|
const spreads = calculateSpreadBN(amm.baseSpread, targetMarkSpreadPct, confIntervalPct, amm.maxSpread, amm.quoteAssetReserve, amm.terminalQuoteAssetReserve, amm.pegMultiplier, amm.baseAssetAmountWithAmm, reservePrice, amm.totalFeeMinusDistributions, amm.netRevenueSinceLastFunding, amm.baseAssetReserve, amm.minBaseAssetReserve, amm.maxBaseAssetReserve, marketStats.markStd, liveOracleStd, marketStats.longIntensityVolume, marketStats.shortIntensityVolume, marketStats.volume24H, amm.ammInventorySpreadAdjustment, marketStats.last24HAvgFundingRate, marketStats.lastFundingOracleTwap, amm.fundingBiasSensitivity);
|
|
736
|
-
|
|
737
|
-
let shortSpread = spreads[1];
|
|
738
|
-
if (amm.ammSpreadAdjustment > 0) {
|
|
739
|
-
longSpread = Math.max(longSpread + (longSpread * amm.ammSpreadAdjustment) / 100, 1);
|
|
740
|
-
shortSpread = Math.max(shortSpread + (shortSpread * amm.ammSpreadAdjustment) / 100, 1);
|
|
741
|
-
}
|
|
742
|
-
else if (amm.ammSpreadAdjustment < 0) {
|
|
743
|
-
longSpread = Math.max(longSpread - (longSpread * -amm.ammSpreadAdjustment) / 100, 1);
|
|
744
|
-
shortSpread = Math.max(shortSpread - (shortSpread * -amm.ammSpreadAdjustment) / 100, 1);
|
|
745
|
-
}
|
|
746
|
-
return [longSpread, shortSpread];
|
|
766
|
+
return applyAmmSpreadAdjustment(amm, spreads[0], spreads[1]);
|
|
747
767
|
}
|
|
748
768
|
exports.calculateSpread = calculateSpread;
|
|
749
769
|
/**
|
package/lib/browser/types.d.ts
CHANGED
|
@@ -1125,6 +1125,8 @@ export type StateAccount = {
|
|
|
1125
1125
|
hotAmmSpreadAdjust: PublicKey;
|
|
1126
1126
|
/** hot key authorized to trigger protocol-fee withdrawals to `protocolFeeRecipientPerp`/`protocolFeeRecipientSpot` */
|
|
1127
1127
|
hotFeeWithdraw: PublicKey;
|
|
1128
|
+
/** hot key authorized to grow zero-copy accounts to the deployed program's size (`extendAccount`) */
|
|
1129
|
+
hotAccountExtension: PublicKey;
|
|
1128
1130
|
/** treasury PERP protocol fees are withdrawn to (settable only by `coldAdmin`); `PublicKey.default()` makes perp fee withdrawals inert */
|
|
1129
1131
|
protocolFeeRecipientPerp: PublicKey;
|
|
1130
1132
|
/** treasury SPOT protocol fees are withdrawn to (settable only by `coldAdmin`); `PublicKey.default()` makes spot fee withdrawals inert */
|
|
@@ -450,6 +450,45 @@ export declare class VelocityClient {
|
|
|
450
450
|
* @returns The resize instruction.
|
|
451
451
|
*/
|
|
452
452
|
getResizeSignedMsgUserOrdersInstruction(authority: PublicKey, numOrders: number): Promise<TransactionInstruction>;
|
|
453
|
+
/**
|
|
454
|
+
* Grows a zero-copy account (User, PerpMarket, SpotMarket, State, ...) to the size the
|
|
455
|
+
* deployed program compiles in for its type, as part of an account-size migration after a
|
|
456
|
+
* program upgrade that appended fields. Requires `HotRole.AccountExtension` (cold, warm, or
|
|
457
|
+
* the configured account-extension hot key) — the wallet must hold that role. The payer
|
|
458
|
+
* covers the rent-exempt shortfall and the program zero-fills the new tail. No-op when the
|
|
459
|
+
* account is already at size, so cranking is idempotent. See `docs/ACCOUNT-EXTENSION.md`.
|
|
460
|
+
* @param account - The account to extend.
|
|
461
|
+
* @param txParams - Optional compute-unit/priority-fee overrides for the transaction.
|
|
462
|
+
* @returns The transaction signature.
|
|
463
|
+
*/
|
|
464
|
+
extendAccount(account: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
|
|
465
|
+
/**
|
|
466
|
+
* Builds the `extendAccount` instruction. See `extendAccount` for semantics.
|
|
467
|
+
* @param account - The account to extend.
|
|
468
|
+
* @param payer - Rent payer; defaults to the wallet.
|
|
469
|
+
* @param authority - `HotRole.AccountExtension` holder; defaults to the wallet.
|
|
470
|
+
* @returns The extend instruction.
|
|
471
|
+
*/
|
|
472
|
+
getExtendAccountIx(account: PublicKey, payer?: PublicKey, authority?: PublicKey): Promise<TransactionInstruction>;
|
|
473
|
+
/**
|
|
474
|
+
* Devnet/test only: grows a zero-copy account to an arbitrary larger size, simulating the
|
|
475
|
+
* state right after a struct-growing program upgrade. Requires `HotRole.AccountExtension`
|
|
476
|
+
* like `extendAccount`. The instruction is compiled out of mainnet program builds.
|
|
477
|
+
* @param account - The account to extend.
|
|
478
|
+
* @param newLen - Target account data length in bytes (must be >= the current length).
|
|
479
|
+
* @param txParams - Optional compute-unit/priority-fee overrides for the transaction.
|
|
480
|
+
* @returns The transaction signature.
|
|
481
|
+
*/
|
|
482
|
+
extendAccountDevnet(account: PublicKey, newLen: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
483
|
+
/**
|
|
484
|
+
* Builds the `extendAccountDevnet` instruction. See `extendAccountDevnet` for semantics.
|
|
485
|
+
* @param account - The account to extend.
|
|
486
|
+
* @param newLen - Target account data length in bytes.
|
|
487
|
+
* @param payer - Rent payer; defaults to the wallet.
|
|
488
|
+
* @param authority - `HotRole.AccountExtension` holder; defaults to the wallet.
|
|
489
|
+
* @returns The extend instruction.
|
|
490
|
+
*/
|
|
491
|
+
getExtendAccountDevnetIx(account: PublicKey, newLen: number, payer?: PublicKey, authority?: PublicKey): Promise<TransactionInstruction>;
|
|
453
492
|
/**
|
|
454
493
|
* Initializes `authority`'s `SignedMsgWsDelegates` account, which lists wallets authorized to
|
|
455
494
|
* co-sign/relay that authority's signed-message ("swift") orders over a websocket connection
|
|
@@ -930,6 +930,75 @@ class VelocityClient {
|
|
|
930
930
|
});
|
|
931
931
|
return resizeUserAccountIx;
|
|
932
932
|
}
|
|
933
|
+
/**
|
|
934
|
+
* Grows a zero-copy account (User, PerpMarket, SpotMarket, State, ...) to the size the
|
|
935
|
+
* deployed program compiles in for its type, as part of an account-size migration after a
|
|
936
|
+
* program upgrade that appended fields. Requires `HotRole.AccountExtension` (cold, warm, or
|
|
937
|
+
* the configured account-extension hot key) — the wallet must hold that role. The payer
|
|
938
|
+
* covers the rent-exempt shortfall and the program zero-fills the new tail. No-op when the
|
|
939
|
+
* account is already at size, so cranking is idempotent. See `docs/ACCOUNT-EXTENSION.md`.
|
|
940
|
+
* @param account - The account to extend.
|
|
941
|
+
* @param txParams - Optional compute-unit/priority-fee overrides for the transaction.
|
|
942
|
+
* @returns The transaction signature.
|
|
943
|
+
*/
|
|
944
|
+
async extendAccount(account, txParams) {
|
|
945
|
+
const extendAccountIx = await this.getExtendAccountIx(account);
|
|
946
|
+
const tx = await this.buildTransaction([extendAccountIx], txParams);
|
|
947
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
948
|
+
return txSig;
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Builds the `extendAccount` instruction. See `extendAccount` for semantics.
|
|
952
|
+
* @param account - The account to extend.
|
|
953
|
+
* @param payer - Rent payer; defaults to the wallet.
|
|
954
|
+
* @param authority - `HotRole.AccountExtension` holder; defaults to the wallet.
|
|
955
|
+
* @returns The extend instruction.
|
|
956
|
+
*/
|
|
957
|
+
async getExtendAccountIx(account, payer, authority) {
|
|
958
|
+
return await this.program.instruction.extendAccount({
|
|
959
|
+
accounts: {
|
|
960
|
+
state: await this.getStatePublicKey(),
|
|
961
|
+
payer: payer !== null && payer !== void 0 ? payer : this.wallet.publicKey,
|
|
962
|
+
authority: authority !== null && authority !== void 0 ? authority : this.wallet.publicKey,
|
|
963
|
+
account,
|
|
964
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
965
|
+
},
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* Devnet/test only: grows a zero-copy account to an arbitrary larger size, simulating the
|
|
970
|
+
* state right after a struct-growing program upgrade. Requires `HotRole.AccountExtension`
|
|
971
|
+
* like `extendAccount`. The instruction is compiled out of mainnet program builds.
|
|
972
|
+
* @param account - The account to extend.
|
|
973
|
+
* @param newLen - Target account data length in bytes (must be >= the current length).
|
|
974
|
+
* @param txParams - Optional compute-unit/priority-fee overrides for the transaction.
|
|
975
|
+
* @returns The transaction signature.
|
|
976
|
+
*/
|
|
977
|
+
async extendAccountDevnet(account, newLen, txParams) {
|
|
978
|
+
const extendAccountIx = await this.getExtendAccountDevnetIx(account, newLen);
|
|
979
|
+
const tx = await this.buildTransaction([extendAccountIx], txParams);
|
|
980
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
981
|
+
return txSig;
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* Builds the `extendAccountDevnet` instruction. See `extendAccountDevnet` for semantics.
|
|
985
|
+
* @param account - The account to extend.
|
|
986
|
+
* @param newLen - Target account data length in bytes.
|
|
987
|
+
* @param payer - Rent payer; defaults to the wallet.
|
|
988
|
+
* @param authority - `HotRole.AccountExtension` holder; defaults to the wallet.
|
|
989
|
+
* @returns The extend instruction.
|
|
990
|
+
*/
|
|
991
|
+
async getExtendAccountDevnetIx(account, newLen, payer, authority) {
|
|
992
|
+
return await this.program.instruction.extendAccountDevnet(new anchor_1.BN(newLen), {
|
|
993
|
+
accounts: {
|
|
994
|
+
state: await this.getStatePublicKey(),
|
|
995
|
+
payer: payer !== null && payer !== void 0 ? payer : this.wallet.publicKey,
|
|
996
|
+
authority: authority !== null && authority !== void 0 ? authority : this.wallet.publicKey,
|
|
997
|
+
account,
|
|
998
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
999
|
+
},
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
933
1002
|
/**
|
|
934
1003
|
* Initializes `authority`'s `SignedMsgWsDelegates` account, which lists wallets authorized to
|
|
935
1004
|
* co-sign/relay that authority's signed-message ("swift") orders over a websocket connection
|
|
@@ -2604,6 +2604,7 @@ export declare enum HotRole {
|
|
|
2604
2604
|
VaultDeposit = "vaultDeposit",
|
|
2605
2605
|
MmOracleCrank = "mmOracleCrank",
|
|
2606
2606
|
AmmSpreadAdjust = "ammSpreadAdjust",
|
|
2607
|
-
FeeWithdraw = "feeWithdraw"
|
|
2607
|
+
FeeWithdraw = "feeWithdraw",
|
|
2608
|
+
AccountExtension = "accountExtension"
|
|
2608
2609
|
}
|
|
2609
2610
|
//# sourceMappingURL=adminClient.d.ts.map
|