Skip to content

Commit

Permalink
frank/prediction markets idl constants type (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
soundsonacid authored Aug 2, 2024
1 parent 018dec3 commit ae0c539
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 10 deletions.
2 changes: 1 addition & 1 deletion protocol-v2
Submodule protocol-v2 updated 59 files
+31 −0 CHANGELOG.md
+1 −1 Cargo.lock
+0 −1 Cargo.toml
+1 −1 programs/drift/Cargo.toml
+6 −4 programs/drift/src/controller/insurance.rs
+462 −9 programs/drift/src/controller/liquidation.rs
+796 −0 programs/drift/src/controller/liquidation/tests.rs
+98 −68 programs/drift/src/controller/orders.rs
+24 −3 programs/drift/src/controller/orders/tests.rs
+89 −26 programs/drift/src/controller/token.rs
+4 −0 programs/drift/src/error.rs
+147 −21 programs/drift/src/instructions/admin.rs
+27 −14 programs/drift/src/instructions/if_staker.rs
+93 −20 programs/drift/src/instructions/keeper.rs
+39 −2 programs/drift/src/instructions/optional_accounts.rs
+72 −29 programs/drift/src/instructions/user.rs
+22 −8 programs/drift/src/lib.rs
+3 −1 programs/drift/src/math/auction.rs
+1 −1 programs/drift/src/math/constants.rs
+6 −2 programs/drift/src/math/fulfillment.rs
+14 −0 programs/drift/src/math/fulfillment/tests.rs
+43 −2 programs/drift/src/math/liquidation.rs
+3 −0 programs/drift/src/math/orders.rs
+14 −0 programs/drift/src/state/events.rs
+6 −1 programs/drift/src/state/fill_mode.rs
+8 −8 programs/drift/src/state/fulfillment_params/drift.rs
+4 −0 programs/drift/src/state/order_params.rs
+1 −0 programs/drift/src/state/perp_market.rs
+4 −2 programs/drift/src/state/spot_market.rs
+1 −1 sdk/VERSION
+4 −2 sdk/package.json
+10 −0 sdk/src/addresses/pda.ts
+46 −1 sdk/src/adminClient.ts
+2 −2 sdk/src/bankrun/bankrunConnection.ts
+3 −0 sdk/src/config.ts
+1 −1 sdk/src/constants/numericConstants.ts
+22 −2 sdk/src/constants/perpMarkets.ts
+23 −0 sdk/src/constants/spotMarkets.ts
+1 −1 sdk/src/dlob/orderBookLevels.ts
+198 −65 sdk/src/driftClient.ts
+5 −1 sdk/src/events/types.ts
+148 −6 sdk/src/idl/drift.json
+2 −0 sdk/src/index.ts
+28 −2 sdk/src/math/spotMarket.ts
+29 −0 sdk/src/openbook/openbookV2FulfillmentConfigMap.ts
+165 −0 sdk/src/openbook/openbookV2Subscriber.ts
+12 −0 sdk/src/types.ts
+3 −6 sdk/tests/ci/verifyConstants.ts
+58 −0 sdk/tests/subscriber/openbook.ts
+104 −8 sdk/yarn.lock
+4 −0 test-scripts/run-anchor-tests.sh
+1 −1 test-scripts/single-anchor-test.sh
+193 −0 tests/depositIntoSpotMarketVault.ts
+9 −9 tests/fuel.ts
+336 −0 tests/liquidatePerpWithFill.ts
+13 −0 tests/order.ts
+936 −0 tests/spotDepositWithdraw22.ts
+311 −0 tests/spotSwap22.ts
+22 −18 tests/testHelpers.ts
2 changes: 2 additions & 0 deletions src/driftpy/constants/numeric_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,5 @@
GOV_SPOT_MARKET_INDEX = 15

SWB_PRECISION = 10**12

MAX_PREDICTION_PRICE = PRICE_PRECISION
18 changes: 16 additions & 2 deletions src/driftpy/constants/perp_markets.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ class PerpMarketConfig:
symbol="W-PERP",
base_asset_symbol="W",
market_index=23,
oracle=Pubkey.from_string("4HbitGsdcFbtFotmYscikQFAAKJ3nYx4t7sV7fTvsk8U"),
oracle_source=OracleSource.PythPull(),
oracle=Pubkey.from_string("4iCi4DvXrubHQne8jzbMaWL3pd7v1Fip8iTe4H9vHNXB"),
oracle_source=OracleSource.SwitchboardOnDemand(),
),
PerpMarketConfig(
symbol="KMNO-PERP",
Expand All @@ -195,6 +195,20 @@ class PerpMarketConfig:
oracle=Pubkey.from_string("F47c7aJgYkfKXQ9gzrJaEpsNwUKHprysregTWXrtYLFp"),
oracle_source=OracleSource.Pyth1KPull(),
),
PerpMarketConfig(
symbol="TRUMP-WIN-2024-PREDICT",
base_asset_symbol="TRUMP-WIN-2024",
market_index=26,
oracle=Pubkey.from_string("3TVuLmEGBRfVgrmFRtYTheczXaaoRBwcHw1yibZHSeNA"),
oracle_source=OracleSource.Prelaunch(),
),
PerpMarketConfig(
symbol="KAMALA-POPULAR-VOTE-2024-PREDICT",
base_asset_symbol="KAMALA-POPULAR-VOTE",
market_index=27,
oracle=Pubkey.from_string("GU6CA7a2KCyhpfqZNb36UAfc9uzKBM8jHjGdt245QhYX"),
oracle_source=OracleSource.Prelaunch(),
),
]

mainnet_perp_market_configs: list[PerpMarketConfig] = [
Expand Down
7 changes: 7 additions & 0 deletions src/driftpy/constants/spot_markets.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,11 @@ class SpotMarketConfig:
oracle_source=OracleSource.Switchboard(),
mint=Pubkey.from_string("CLoUDKc4Ane7HeQcPpE3YHnznRxhMimJ4MyaUqyHFzAu"),
),
SpotMarketConfig(
symbol="PYUSD",
market_index=22,
oracle=Pubkey.from_string("HpMoKp3TCd3QT4MWYUKk2zCBwmhr5Df45fB6wdxYqEeh"),
oracle_source=OracleSource.PythPull(),
mint=Pubkey.from_string("2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo"),
),
]
154 changes: 148 additions & 6 deletions src/driftpy/idl/drift.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.86.0",
"version": "2.89.0",
"name": "drift",
"instructions": [
{
Expand Down Expand Up @@ -1675,6 +1675,47 @@
}
]
},
{
"name": "liquidatePerpWithFill",
"accounts": [
{
"name": "state",
"isMut": false,
"isSigner": false
},
{
"name": "authority",
"isMut": false,
"isSigner": true
},
{
"name": "liquidator",
"isMut": true,
"isSigner": false
},
{
"name": "liquidatorStats",
"isMut": true,
"isSigner": false
},
{
"name": "user",
"isMut": true,
"isSigner": false
},
{
"name": "userStats",
"isMut": true,
"isSigner": false
}
],
"args": [
{
"name": "marketIndex",
"type": "u16"
}
]
},
{
"name": "liquidateSpot",
"accounts": [
Expand Down Expand Up @@ -2341,7 +2382,7 @@
},
{
"name": "spotMarket",
"isMut": false,
"isMut": true,
"isSigner": false
},
{
Expand Down Expand Up @@ -2401,7 +2442,7 @@
"accounts": [
{
"name": "spotMarket",
"isMut": false,
"isMut": true,
"isSigner": false
},
{
Expand Down Expand Up @@ -2441,7 +2482,7 @@
"accounts": [
{
"name": "spotMarket",
"isMut": false,
"isMut": true,
"isSigner": false
},
{
Expand Down Expand Up @@ -2482,7 +2523,7 @@
},
{
"name": "spotMarket",
"isMut": false,
"isMut": true,
"isSigner": false
},
{
Expand Down Expand Up @@ -3593,6 +3634,47 @@
}
]
},
{
"name": "depositIntoSpotMarketVault",
"accounts": [
{
"name": "state",
"isMut": false,
"isSigner": false
},
{
"name": "spotMarket",
"isMut": true,
"isSigner": false
},
{
"name": "admin",
"isMut": false,
"isSigner": true
},
{
"name": "sourceVault",
"isMut": true,
"isSigner": false
},
{
"name": "spotMarketVault",
"isMut": true,
"isSigner": false
},
{
"name": "tokenProgram",
"isMut": false,
"isSigner": false
}
],
"args": [
{
"name": "amount",
"type": "u64"
}
]
},
{
"name": "depositIntoSpotMarketRevenuePool",
"accounts": [
Expand Down Expand Up @@ -6835,12 +6917,16 @@
],
"type": "u8"
},
{
"name": "tokenProgram",
"type": "u8"
},
{
"name": "padding",
"type": {
"array": [
"u8",
42
41
]
}
}
Expand Down Expand Up @@ -9833,6 +9919,9 @@
},
{
"name": "PlaceAndTake"
},
{
"name": "Liquidation"
}
]
}
Expand Down Expand Up @@ -10100,6 +10189,9 @@
},
{
"name": "Future"
},
{
"name": "Prediction"
}
]
}
Expand Down Expand Up @@ -11352,6 +11444,46 @@
"index": false
}
]
},
{
"name": "SpotMarketVaultDepositRecord",
"fields": [
{
"name": "ts",
"type": "i64",
"index": false
},
{
"name": "marketIndex",
"type": "u16",
"index": false
},
{
"name": "depositBalance",
"type": "u128",
"index": false
},
{
"name": "cumulativeDepositInterestBefore",
"type": "u128",
"index": false
},
{
"name": "cumulativeDepositInterestAfter",
"type": "u128",
"index": false
},
{
"name": "depositTokenAmountBefore",
"type": "u64",
"index": false
},
{
"name": "amount",
"type": "u64",
"index": false
}
]
}
],
"errors": [
Expand Down Expand Up @@ -12764,6 +12896,16 @@
"code": 6281,
"name": "InvalidOpenbookV2Market",
"msg": "InvalidOpenbookV2Market"
},
{
"code": 6282,
"name": "NonZeroTransferFee",
"msg": "Non zero transfer fee"
},
{
"code": 6283,
"name": "LiquidationOrderFailedToFill",
"msg": "Liquidation order failed to fill"
}
]
}
1 change: 1 addition & 0 deletions src/driftpy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ class MarketStatus:
class ContractType:
Perpetual = constructor()
Future = constructor()
Prediction = constructor()


@_rust_enum
Expand Down
2 changes: 1 addition & 1 deletion update_idl.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
git submodule update --remote --merge --recursive &&
cd protocol-v2/ &&
anchor build &&
cp target/idl/drift.json ../src/driftpy/idl/
cp target/idl/drift.json ../src/driftpy/idl/drift.json

0 comments on commit ae0c539

Please sign in to comment.