Skip to content

Commit

Permalink
Add shanking for types (#148)
Browse files Browse the repository at this point in the history
* Add shanking for types

* fix index
  • Loading branch information
brittcyr authored Oct 8, 2024
1 parent 8f78fd2 commit 892d8c5
Show file tree
Hide file tree
Showing 26 changed files with 952 additions and 11 deletions.
48 changes: 48 additions & 0 deletions client/idl/generateIdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,29 @@ function modifyIdlCore(programName) {
}
}

for (const idlType of idl.types) {
if (idlType.type && idlType.type.fields) {
idlType.type.fields = idlType.type.fields.map((field) => {
if (field.type.defined == 'PodBool') {
field.type = 'bool';
}
if (field.type.defined == 'BaseAtoms') {
field.type = 'u64';
}
if (field.type.defined == 'QuoteAtoms') {
field.type = 'u64';
}
if (field.type.defined == 'GlobalAtoms') {
field.type = 'u64';
}
if (field.type.defined == 'QuoteAtomsPerBaseAtom') {
field.type = 'u128';
}
return field;
});
}
}

for (const instruction of idl.instructions) {
switch (instruction.name) {
case 'CreateMarket': {
Expand Down Expand Up @@ -243,12 +266,25 @@ function modifyIdlCore(programName) {
},
});

// TODO: Make a helper for this that is shared
for (const idlType of idl.types) {
if (idlType.type && idlType.type.fields) {
idlType.type.fields = idlType.type.fields.map((field) => {
if (field.type.defined == 'PodBool') {
field.type = 'bool';
}
if (field.type.defined == 'BaseAtoms') {
field.type = 'u64';
}
if (field.type.defined == 'QuoteAtoms') {
field.type = 'u64';
}
if (field.type.defined == 'GlobalAtoms') {
field.type = 'u64';
}
if (field.type.defined == 'QuoteAtomsPerBaseAtom') {
field.type = 'u128';
}
return field;
});
}
Expand Down Expand Up @@ -352,6 +388,18 @@ function modifyIdlCore(programName) {
if (field.type.defined == 'PodBool') {
field.type = 'bool';
}
if (field.type.defined == 'BaseAtoms') {
field.type = 'u64';
}
if (field.type.defined == 'QuoteAtoms') {
field.type = 'u64';
}
if (field.type.defined == 'GlobalAtoms') {
field.type = 'u64';
}
if (field.type.defined == 'QuoteAtomsPerBaseAtom') {
field.type = 'u128';
}
return field;
});
}
Expand Down
287 changes: 287 additions & 0 deletions client/idl/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,293 @@
]
}
},
{
"name": "ClaimedSeat",
"type": {
"kind": "struct",
"fields": [
{
"name": "trader",
"type": "publicKey"
},
{
"name": "baseWithdrawableBalance",
"type": "u64"
},
{
"name": "quoteWithdrawableBalance",
"type": "u64"
},
{
"name": "quoteVolume",
"type": "u64"
},
{
"name": "padding",
"type": {
"array": [
"u8",
8
]
}
}
]
}
},
{
"name": "GlobalFixed",
"type": {
"kind": "struct",
"fields": [
{
"name": "discriminant",
"type": "u64"
},
{
"name": "mint",
"type": "publicKey"
},
{
"name": "vault",
"type": "publicKey"
},
{
"name": "globalTradersRootIndex",
"type": "u32"
},
{
"name": "globalDepositsRootIndex",
"type": "u32"
},
{
"name": "globalDepositsMaxIndex",
"type": "u32"
},
{
"name": "freeListHeadIndex",
"type": "u32"
},
{
"name": "numBytesAllocated",
"type": "u32"
},
{
"name": "vaultBump",
"type": "u8"
},
{
"name": "globalBump",
"type": "u8"
},
{
"name": "numSeatsClaimed",
"type": "u16"
}
]
}
},
{
"name": "GlobalTrader",
"type": {
"kind": "struct",
"fields": [
{
"name": "trader",
"type": "publicKey"
},
{
"name": "unclaimedGasDeposits",
"type": "u32"
},
{
"name": "depositIndex",
"type": "u32"
},
{
"name": "padding",
"type": "u64"
}
]
}
},
{
"name": "GlobalDeposit",
"type": {
"kind": "struct",
"fields": [
{
"name": "trader",
"type": "publicKey"
},
{
"name": "balanceAtoms",
"type": "u64"
},
{
"name": "padding",
"type": "u64"
}
]
}
},
{
"name": "MarketFixed",
"type": {
"kind": "struct",
"fields": [
{
"name": "discriminant",
"type": "u64"
},
{
"name": "version",
"type": "u8"
},
{
"name": "baseMintDecimals",
"type": "u8"
},
{
"name": "quoteMintDecimals",
"type": "u8"
},
{
"name": "baseVaultBump",
"type": "u8"
},
{
"name": "quoteVaultBump",
"type": "u8"
},
{
"name": "padding1",
"type": {
"array": [
"u8",
3
]
}
},
{
"name": "baseMint",
"type": "publicKey"
},
{
"name": "quoteMint",
"type": "publicKey"
},
{
"name": "baseVault",
"type": "publicKey"
},
{
"name": "quoteVault",
"type": "publicKey"
},
{
"name": "orderSequenceNumber",
"type": "u64"
},
{
"name": "numBytesAllocated",
"type": "u32"
},
{
"name": "bidsRootIndex",
"type": "u32"
},
{
"name": "bidsBestIndex",
"type": "u32"
},
{
"name": "asksRootIndex",
"type": "u32"
},
{
"name": "asksBestIndex",
"type": "u32"
},
{
"name": "claimedSeatsRootIndex",
"type": "u32"
},
{
"name": "freeListHeadIndex",
"type": "u32"
},
{
"name": "padding2",
"type": {
"array": [
"u32",
1
]
}
},
{
"name": "quoteVolume",
"type": "u64"
},
{
"name": "padding3",
"type": {
"array": [
"u64",
8
]
}
}
]
}
},
{
"name": "RestingOrder",
"type": {
"kind": "struct",
"fields": [
{
"name": "price",
"type": "u128"
},
{
"name": "numBaseAtoms",
"type": "u64"
},
{
"name": "sequenceNumber",
"type": "u64"
},
{
"name": "traderIndex",
"type": "u32"
},
{
"name": "lastValidSlot",
"type": "u32"
},
{
"name": "isBid",
"type": "bool"
},
{
"name": "orderType",
"type": {
"defined": "OrderType"
}
},
{
"name": "padding",
"type": {
"array": [
"u8",
22
]
}
}
]
}
},
{
"name": "OrderType",
"type": {
Expand Down
Loading

0 comments on commit 892d8c5

Please sign in to comment.