From 44c9a65ececfb0afd56ebbb73720cfdb99d22d05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enol=20=C3=81lvarez?= Date: Tue, 11 Mar 2025 19:19:48 +0100 Subject: [PATCH 1/7] Upgrade Anchor version --- sol-anchor/templates/Cargo.toml.gotmpl | 2 +- sol-anchor/templates/src/lib.rs.gotmpl | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sol-anchor/templates/Cargo.toml.gotmpl b/sol-anchor/templates/Cargo.toml.gotmpl index 76cf26f..d902c74 100644 --- a/sol-anchor/templates/Cargo.toml.gotmpl +++ b/sol-anchor/templates/Cargo.toml.gotmpl @@ -13,7 +13,7 @@ prost-types = "0.13" substreams = "0.6" substreams-solana = "0.14" substreams-solana-program-instructions = "0.2" -anchor-lang = ">=0.30.1" +anchor-lang = ">=0.31.0" sologger_log_context = "0.1.2" base64 = "0.22.1" diff --git a/sol-anchor/templates/src/lib.rs.gotmpl b/sol-anchor/templates/src/lib.rs.gotmpl index 09124d3..182d4b7 100644 --- a/sol-anchor/templates/src/lib.rs.gotmpl +++ b/sol-anchor/templates/src/lib.rs.gotmpl @@ -59,8 +59,9 @@ fn map_program_data(blk: Block) -> Data { let slice_u8: &mut &[u8] = &mut &decoded[..]; let slice_discriminator: [u8; 8] = slice_u8[0..8].try_into().expect("error"); + let static_discriminator_slice: &'static [u8] = Box::leak(Box::new(slice_discriminator)); - match slice_discriminator { + match static_discriminator_slice { {{- range $i, $event := .Idl.Events }} idl::idl::program::events::{{$event.Name}}::DISCRIMINATOR => { if let Ok(event) = @@ -93,8 +94,8 @@ fn map_program_data(blk: Block) -> Data { .for_each(|inst| { let slice_u8: &[u8] = &inst.data()[..]; - {{- range $i, $instruction := .Idl.Instructions -}} - if slice_u8[0..8] == idl::idl::program::client::args::{{ $instruction.PascalCaseName }}::DISCRIMINATOR { + {{- range $i, $instruction := .Idl.Instructions }} + if &slice_u8[0..8] == idl::idl::program::client::args::{{ $instruction.PascalCaseName }}::DISCRIMINATOR { if let Ok(instruction) = idl::idl::program::client::args::{{ $instruction.PascalCaseName }}::deserialize(&mut &slice_u8[8..]) { From 5944820d67e4af9e59b1b84e1b58cd69295312a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enol=20=C3=81lvarez?= Date: Fri, 14 Mar 2025 16:18:42 +0100 Subject: [PATCH 2/7] WIP --- sol-anchor/idl.go | 25 + sol-anchor/idl_accounts.go | 12 - sol-anchor/idl_fields.go | 24 +- sol-anchor/idl_instructions.go | 19 +- sol-anchor/idl_test.go | 29 +- sol-anchor/idls/raydium_amm.json | 2672 +++++++++++++++++ .../templates/proto/program.proto.gotmpl | 10 +- sol-anchor/templates/src/lib.rs.gotmpl | 54 +- 8 files changed, 2798 insertions(+), 47 deletions(-) delete mode 100644 sol-anchor/idl_accounts.go create mode 100644 sol-anchor/idls/raydium_amm.json diff --git a/sol-anchor/idl.go b/sol-anchor/idl.go index 53dd339..acb5ca4 100644 --- a/sol-anchor/idl.go +++ b/sol-anchor/idl.go @@ -8,10 +8,15 @@ type IDL struct { Address string `json:"address"` // seen in the 'secret' program Events []Event `json:"events"` Instructions []Instruction `json:"instructions"` + Accounts []Type `json:"accounts"` Metadata Metadata `json:"metadata"` Types []Type `json:"types"` } +func (i *IDL) AccountsAndTypes() []Type { + return append(i.Types, i.Accounts...) +} + func (i *IDL) ProgramID() string { if i.Metadata.Address != "" { return i.Metadata.Address @@ -44,6 +49,22 @@ func (i *IDL) IsTypeUsed(typeName string) bool { } } + for _, tp := range i.Accounts { + if tp.Type.IsStruct() { + for _, arg := range tp.Type.Struct.Fields { + if arg.Type.IsTypeUsed(typeName) && i.IsTypeUsed(tp.Name) { + return true + } + } + } else if tp.Type.IsEnum() { + for _, arg := range tp.Type.Enum.Variants { + if arg.Name == typeName && i.IsTypeUsed(tp.Name) { + return true + } + } + } + } + for _, event := range i.Events { for _, field := range event.Fields { if field.Type.IsTypeUsed(typeName) { @@ -101,6 +122,10 @@ func ToProtobufType(rustType string) string { return rustType } +func IsPublicKey(idlType string) bool { + return idlType == "publicKey" || idlType == "pubkey" +} + func CastInRustIfNeeded(rustType string) string { switch rustType { case "u8": diff --git a/sol-anchor/idl_accounts.go b/sol-anchor/idl_accounts.go deleted file mode 100644 index 74c6ad4..0000000 --- a/sol-anchor/idl_accounts.go +++ /dev/null @@ -1,12 +0,0 @@ -package solanchor - -type Account struct { - Name string `json:"name"` - Writable bool `json:"writable"` - Signer bool `json:"signer"` - Address string `json:"address"` -} - -func (a *Account) SnakeCaseName() string { - return toSnakeCase(a.Name, true) -} diff --git a/sol-anchor/idl_fields.go b/sol-anchor/idl_fields.go index 4602c85..5473b41 100644 --- a/sol-anchor/idl_fields.go +++ b/sol-anchor/idl_fields.go @@ -70,7 +70,7 @@ func (t *FieldType) IsSimple() bool { } func (t *FieldType) IsSimplePubKey() bool { - return t.Simple == "publicKey" || t.Simple == "pubkey" + return IsPublicKey(t.Simple) } func (t *FieldType) IsDefined() bool { @@ -188,18 +188,18 @@ func PrintDefined(typeName string, fieldName string, variableName string, types return fmt.Sprintf("%s: map_enum_%s(%s.%s),", toSnakeCase(fieldName, false), t.SnakeCaseName(), toSnakeCase(variableName, true), toSnakeCase(fieldName, true)) } else { var fieldsInString strings.Builder + var fieldString string + + if isOption { + return fmt.Sprintf("%s: map_option_%s(%s.%s),", toSnakeCase(fieldName, true), toSnakeCase(typeName, true), toSnakeCase(variableName, true), toSnakeCase(fieldName, true)) + } + for _, structField := range t.Type.Struct.Fields { - fieldString := fmt.Sprintf("%s.%s", toSnakeCase(variableName, true), toSnakeCase(fieldName, true)) + fieldString = fmt.Sprintf("%s.%s", toSnakeCase(variableName, true), toSnakeCase(fieldName, true)) if variableName == "" { fieldString = toSnakeCase(fieldName, true) } - if isOption { - fieldString = fmt.Sprintf("%s: map_option_%s(%s.%s),", toSnakeCase(fieldName, true), toSnakeCase(fieldName, true), toSnakeCase(variableName, true), toSnakeCase(fieldName, true)) - fieldsInString.WriteString(fieldString) - continue - } - fieldsInString.WriteString(structField.Type.Print(structField.Name, fieldString, types)) } @@ -209,10 +209,6 @@ func PrintDefined(typeName string, fieldName string, variableName string, types }`, t.Name, fieldsInString.String()) } - if isOption { - return fieldsInString.String() - } - return fmt.Sprintf(`%s: Some(%s { %s }),`, toSnakeCase(fieldName, false), t.Name, fieldsInString.String()) @@ -240,6 +236,10 @@ func (f *FieldType) Print(fieldName string, variableName string, types []Type) s } if f.IsArray() { + if IsPublicKey(f.Array.Type) { + return fmt.Sprintf("%s: %s.%s.into_iter().map(|f| f.to_string()).collect(),", fieldNameSnakeCaseWithoutInitialUnderscore, variableName, fieldNameSnakeCase) + } + cast := CastInRustIfNeeded(f.Array.Type) if cast == "" { return fmt.Sprintf("%s: %s.%s.to_vec(),", fieldNameSnakeCaseWithoutInitialUnderscore, variableName, fieldNameSnakeCase) diff --git a/sol-anchor/idl_instructions.go b/sol-anchor/idl_instructions.go index ce9cb7e..8735cdf 100644 --- a/sol-anchor/idl_instructions.go +++ b/sol-anchor/idl_instructions.go @@ -4,12 +4,23 @@ import ( "github.com/golang-cz/textcase" ) +type InstructionAccount struct { + Name string `json:"name"` + Writable bool `json:"writable"` + Signer bool `json:"signer"` + Address string `json:"address"` +} + +func (a *InstructionAccount) SnakeCaseName() string { + return toSnakeCase(a.Name, true) +} + // --- INSTRUCTIONS type Instruction struct { - Name string `json:"name"` - Args []Field `json:"args"` - Accounts []Account `json:"accounts"` - Discriminator []uint8 `json:"discriminator"` + Name string `json:"name"` + Args []Field `json:"args"` + Accounts []InstructionAccount `json:"accounts"` + Discriminator []uint8 `json:"discriminator"` } func (i *Instruction) PascalCaseName() string { diff --git a/sol-anchor/idl_test.go b/sol-anchor/idl_test.go index 3c6aa10..00a43b7 100644 --- a/sol-anchor/idl_test.go +++ b/sol-anchor/idl_test.go @@ -14,7 +14,7 @@ func TestPumpFunIDL(t *testing.T) { result := &IDL{} err := json.Unmarshal(idl, &result) - + fmt.Println(len(result.Accounts)) assert.Nil(t, err) assert.Equal(t, "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P", result.Metadata.Address) assert.Equal(t, 6, len(result.Instructions)) @@ -69,7 +69,7 @@ func TestOrbitLen(t *testing.T) { assert.Nil(t, err) assert.Equal(t, "QoB7dVkkZr3oLb95DMpSptvUF8mTygDHNjFQh5y5RAb", result.Address) - + } func TestIthaca(t *testing.T) { @@ -81,6 +81,31 @@ func TestIthaca(t *testing.T) { assert.Nil(t, err) } +func TestRaydiumAMM(t *testing.T) { + idl := readFromFile("raydium_amm") + + result := &IDL{} + err := json.Unmarshal(idl, &result) + + for _, i := range result.Instructions { + if i.Name == "simulateInfo" { + for _, a := range i.Args { + if a.Type.IsOption() && a.Type.Option.Defined != nil { + fmt.Println(*a.Type.Option.Defined) + } + + fmt.Printf("%s\n", a.Name) + } + } + } + + fmt.Println("-------------------------") + + fmt.Println(PrintDefined("SwapInstructionBaseIn", "instruction", "instruction", result.Types, false, true)) + + assert.Nil(t, err) +} + func readFromFile(idlName string) []byte { data, err := os.ReadFile("idls/" + idlName + ".json") if err != nil { diff --git a/sol-anchor/idls/raydium_amm.json b/sol-anchor/idls/raydium_amm.json new file mode 100644 index 0000000..a9d7b04 --- /dev/null +++ b/sol-anchor/idls/raydium_amm.json @@ -0,0 +1,2672 @@ +{ + "version": "0.3.0", + "name": "raydium_amm", + "instructions": [ + { + "name": "initialize", + "accounts": [ + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "amm", + "isMut": true, + "isSigner": false + }, + { + "name": "ammAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "ammOpenOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "lpMintAddress", + "isMut": true, + "isSigner": false + }, + { + "name": "coinMintAddress", + "isMut": false, + "isSigner": false + }, + { + "name": "pcMintAddress", + "isMut": false, + "isSigner": false + }, + { + "name": "poolCoinTokenAccount", + "isMut": false, + "isSigner": false + }, + { + "name": "poolPcTokenAccount", + "isMut": false, + "isSigner": false + }, + { + "name": "poolWithdrawQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "poolTargetOrdersAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "userLpTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "poolTempLpTokenAccount", + "isMut": false, + "isSigner": false + }, + { + "name": "serumProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumMarket", + "isMut": false, + "isSigner": false + }, + { + "name": "userWallet", + "isMut": true, + "isSigner": true + } + ], + "args": [ + { + "name": "nonce", + "type": "u8" + }, + { + "name": "openTime", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 0 + } + }, + { + "name": "initialize2", + "accounts": [ + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "splAssociatedTokenAccount", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "amm", + "isMut": true, + "isSigner": false + }, + { + "name": "ammAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "ammOpenOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "lpMint", + "isMut": true, + "isSigner": false + }, + { + "name": "coinMint", + "isMut": false, + "isSigner": false + }, + { + "name": "pcMint", + "isMut": false, + "isSigner": false + }, + { + "name": "poolCoinTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "poolPcTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "poolWithdrawQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "ammTargetOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "poolTempLp", + "isMut": true, + "isSigner": false + }, + { + "name": "serumProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumMarket", + "isMut": false, + "isSigner": false + }, + { + "name": "userWallet", + "isMut": true, + "isSigner": true + }, + { + "name": "userTokenCoin", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenPc", + "isMut": true, + "isSigner": false + }, + { + "name": "userLpTokenAccount", + "isMut": true, + "isSigner": false + } + ], + "args": [ + { + "name": "nonce", + "type": "u8" + }, + { + "name": "openTime", + "type": "u64" + }, + { + "name": "initPcAmount", + "type": "u64" + }, + { + "name": "initCoinAmount", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 1 + } + }, + { + "name": "monitorStep", + "accounts": [ + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "clock", + "isMut": false, + "isSigner": false + }, + { + "name": "amm", + "isMut": true, + "isSigner": false + }, + { + "name": "ammAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "ammOpenOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "ammTargetOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "poolCoinTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "poolPcTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "poolWithdrawQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "serumProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumMarket", + "isMut": true, + "isSigner": false + }, + { + "name": "serumCoinVaultAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "serumPcVaultAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "serumVaultSigner", + "isMut": false, + "isSigner": false + }, + { + "name": "serumReqQ", + "isMut": true, + "isSigner": false + }, + { + "name": "serumEventQ", + "isMut": true, + "isSigner": false + }, + { + "name": "serumBids", + "isMut": true, + "isSigner": false + }, + { + "name": "serumAsks", + "isMut": true, + "isSigner": false + }, + { + "name": "serumFeeDiscount", + "isMut": true, + "isSigner": false, + "isOptional": true + }, + { + "name": "referrerPcAccount", + "isMut": true, + "isSigner": false, + "isOptional": true + } + ], + "args": [ + { + "name": "planOrderLimit", + "type": "u16" + }, + { + "name": "placeOrderLimit", + "type": "u16" + }, + { + "name": "cancelOrderLimit", + "type": "u16" + } + ], + "discriminant": { + "type": "u8", + "value": 2 + } + }, + { + "name": "deposit", + "accounts": [ + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "amm", + "isMut": true, + "isSigner": false + }, + { + "name": "ammAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "ammOpenOrders", + "isMut": false, + "isSigner": false + }, + { + "name": "ammTargetOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "lpMintAddress", + "isMut": true, + "isSigner": false + }, + { + "name": "poolCoinTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "poolPcTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "serumMarket", + "isMut": false, + "isSigner": false + }, + { + "name": "userCoinTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "userPcTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "userLpTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "userOwner", + "isMut": false, + "isSigner": true + }, + { + "name": "serumEventQueue", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "maxCoinAmount", + "type": "u64" + }, + { + "name": "maxPcAmount", + "type": "u64" + }, + { + "name": "baseSide", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 3 + } + }, + { + "name": "withdraw", + "accounts": [ + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "amm", + "isMut": true, + "isSigner": false + }, + { + "name": "ammAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "ammOpenOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "ammTargetOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "lpMintAddress", + "isMut": true, + "isSigner": false + }, + { + "name": "poolCoinTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "poolPcTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "poolWithdrawQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "poolTempLpTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "serumProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumMarket", + "isMut": true, + "isSigner": false + }, + { + "name": "serumCoinVaultAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "serumPcVaultAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "serumVaultSigner", + "isMut": false, + "isSigner": false + }, + { + "name": "userLpTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "userCoinTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "userPcTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "userOwner", + "isMut": false, + "isSigner": true + }, + { + "name": "serumEventQ", + "isMut": true, + "isSigner": false + }, + { + "name": "serumBids", + "isMut": true, + "isSigner": false + }, + { + "name": "serumAsks", + "isMut": true, + "isSigner": false + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 4 + } + }, + { + "name": "migrateToOpenBook", + "accounts": [ + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "amm", + "isMut": true, + "isSigner": false + }, + { + "name": "ammAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "ammOpenOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "ammTokenCoin", + "isMut": true, + "isSigner": false + }, + { + "name": "ammTokenPc", + "isMut": true, + "isSigner": false + }, + { + "name": "ammTargetOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "serumProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumMarket", + "isMut": true, + "isSigner": false + }, + { + "name": "serumBids", + "isMut": true, + "isSigner": false + }, + { + "name": "serumAsks", + "isMut": true, + "isSigner": false + }, + { + "name": "serumEventQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "serumCoinVault", + "isMut": true, + "isSigner": false + }, + { + "name": "serumPcVault", + "isMut": true, + "isSigner": false + }, + { + "name": "serumVaultSigner", + "isMut": false, + "isSigner": false + }, + { + "name": "newAmmOpenOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "newSerumProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "newSerumMarket", + "isMut": false, + "isSigner": false + }, + { + "name": "admin", + "isMut": true, + "isSigner": true + } + ], + "args": [], + "discriminant": { + "type": "u8", + "value": 5 + } + }, + { + "name": "setParams", + "accounts": [ + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "amm", + "isMut": true, + "isSigner": false + }, + { + "name": "ammAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "ammOpenOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "ammTargetOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "ammCoinVault", + "isMut": true, + "isSigner": false + }, + { + "name": "ammPcVault", + "isMut": true, + "isSigner": false + }, + { + "name": "serumProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumMarket", + "isMut": true, + "isSigner": false + }, + { + "name": "serumCoinVault", + "isMut": true, + "isSigner": false + }, + { + "name": "serumPcVault", + "isMut": true, + "isSigner": false + }, + { + "name": "serumVaultSigner", + "isMut": false, + "isSigner": false + }, + { + "name": "serumEventQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "serumBids", + "isMut": true, + "isSigner": false + }, + { + "name": "serumAsks", + "isMut": true, + "isSigner": false + }, + { + "name": "ammAdminAccount", + "isMut": false, + "isSigner": true + }, + { + "name": "newAmmOpenOrdersAccount", + "isMut": false, + "isSigner": false, + "isOptional": true + } + ], + "args": [ + { + "name": "param", + "type": "u8" + }, + { + "name": "value", + "type": { + "option": "u64" + } + }, + { + "name": "newPubkey", + "type": { + "option": "publicKey" + } + }, + { + "name": "fees", + "type": { + "option": { + "defined": "Fees" + } + } + }, + { + "name": "lastOrderDistance", + "type": { + "option": { + "defined": "LastOrderDistance" + } + } + }, + { + "name": "needTakeAmounts", + "type": { + "option": { + "defined": "NeedTake" + } + } + } + ], + "discriminant": { + "type": "u8", + "value": 6 + } + }, + { + "name": "withdrawPnl", + "accounts": [ + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "amm", + "isMut": true, + "isSigner": false + }, + { + "name": "ammConfig", + "isMut": false, + "isSigner": false + }, + { + "name": "ammAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "ammOpenOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "poolCoinTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "poolPcTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "coinPnlTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "pcPnlTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "pnlOwnerAccount", + "isMut": false, + "isSigner": true + }, + { + "name": "ammTargetOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "serumProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumMarket", + "isMut": true, + "isSigner": false + }, + { + "name": "serumEventQueue", + "isMut": false, + "isSigner": false + }, + { + "name": "serumCoinVaultAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "serumPcVaultAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "serumVaultSigner", + "isMut": false, + "isSigner": false + }, + { + "name": "referrerPcAccount", + "isMut": false, + "isSigner": false, + "isOptional": true + } + ], + "args": [], + "discriminant": { + "type": "u8", + "value": 7 + } + }, + { + "name": "withdrawSrm", + "accounts": [ + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "amm", + "isMut": false, + "isSigner": false + }, + { + "name": "ammOwnerAccount", + "isMut": false, + "isSigner": true + }, + { + "name": "ammAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "srmToken", + "isMut": true, + "isSigner": false + }, + { + "name": "destSrmToken", + "isMut": true, + "isSigner": false + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 8 + } + }, + { + "name": "swapBaseIn", + "accounts": [ + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "amm", + "isMut": true, + "isSigner": false + }, + { + "name": "ammAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "ammOpenOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "ammTargetOrders", + "isMut": true, + "isSigner": false, + "isOptional": true + }, + { + "name": "poolCoinTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "poolPcTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "serumProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumMarket", + "isMut": true, + "isSigner": false + }, + { + "name": "serumBids", + "isMut": true, + "isSigner": false + }, + { + "name": "serumAsks", + "isMut": true, + "isSigner": false + }, + { + "name": "serumEventQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "serumCoinVaultAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "serumPcVaultAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "serumVaultSigner", + "isMut": false, + "isSigner": false + }, + { + "name": "userSourceTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "userDestinationTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "userSourceOwner", + "isMut": false, + "isSigner": true + } + ], + "args": [ + { + "name": "amountIn", + "type": "u64" + }, + { + "name": "minimumAmountOut", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 9 + } + }, + { + "name": "preInitialize", + "accounts": [ + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "ammTargetOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "poolWithdrawQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "ammAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "lpMintAddress", + "isMut": true, + "isSigner": false + }, + { + "name": "coinMintAddress", + "isMut": false, + "isSigner": false + }, + { + "name": "pcMintAddress", + "isMut": false, + "isSigner": false + }, + { + "name": "poolCoinTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "poolPcTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "poolTempLpTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "serumMarket", + "isMut": false, + "isSigner": false + }, + { + "name": "userWallet", + "isMut": true, + "isSigner": true + } + ], + "args": [ + { + "name": "nonce", + "type": "u8" + } + ], + "discriminant": { + "type": "u8", + "value": 10 + } + }, + { + "name": "swapBaseOut", + "accounts": [ + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "amm", + "isMut": true, + "isSigner": false + }, + { + "name": "ammAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "ammOpenOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "ammTargetOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "poolCoinTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "poolPcTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "serumProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumMarket", + "isMut": true, + "isSigner": false + }, + { + "name": "serumBids", + "isMut": true, + "isSigner": false + }, + { + "name": "serumAsks", + "isMut": true, + "isSigner": false + }, + { + "name": "serumEventQueue", + "isMut": true, + "isSigner": false + }, + { + "name": "serumCoinVaultAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "serumPcVaultAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "serumVaultSigner", + "isMut": false, + "isSigner": false + }, + { + "name": "userSourceTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "userDestinationTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "userSourceOwner", + "isMut": false, + "isSigner": true + } + ], + "args": [ + { + "name": "maxAmountIn", + "type": "u64" + }, + { + "name": "amountOut", + "type": "u64" + } + ], + "discriminant": { + "type": "u8", + "value": 11 + } + }, + { + "name": "simulateInfo", + "accounts": [ + { + "name": "amm", + "isMut": false, + "isSigner": false + }, + { + "name": "ammAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "ammOpenOrders", + "isMut": false, + "isSigner": false + }, + { + "name": "poolCoinTokenAccount", + "isMut": false, + "isSigner": false + }, + { + "name": "poolPcTokenAccount", + "isMut": false, + "isSigner": false + }, + { + "name": "lpMintAddress", + "isMut": false, + "isSigner": false + }, + { + "name": "serumMarket", + "isMut": false, + "isSigner": false + }, + { + "name": "serumEventQueue", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "param", + "type": "u8" + }, + { + "name": "swapBaseInValue", + "type": { + "option": { + "defined": "SwapInstructionBaseIn" + } + } + }, + { + "name": "swapBaseOutValue", + "type": { + "option": { + "defined": "SwapInstructionBaseOut" + } + } + } + ], + "discriminant": { + "type": "u8", + "value": 12 + } + }, + { + "name": "adminCancelOrders", + "accounts": [ + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "amm", + "isMut": false, + "isSigner": false + }, + { + "name": "ammAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "ammOpenOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "ammTargetOrders", + "isMut": true, + "isSigner": false + }, + { + "name": "poolCoinTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "poolPcTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "ammOwnerAccount", + "isMut": false, + "isSigner": true + }, + { + "name": "ammConfig", + "isMut": true, + "isSigner": false + }, + { + "name": "serumProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "serumMarket", + "isMut": true, + "isSigner": false + }, + { + "name": "serumCoinVaultAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "serumPcVaultAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "serumVaultSigner", + "isMut": false, + "isSigner": false + }, + { + "name": "serumEventQ", + "isMut": true, + "isSigner": false + }, + { + "name": "serumBids", + "isMut": true, + "isSigner": false + }, + { + "name": "serumAsks", + "isMut": true, + "isSigner": false + } + ], + "args": [ + { + "name": "limit", + "type": "u16" + } + ], + "discriminant": { + "type": "u8", + "value": 13 + } + }, + { + "name": "createConfigAccount", + "accounts": [ + { + "name": "admin", + "isMut": true, + "isSigner": true + }, + { + "name": "ammConfig", + "isMut": true, + "isSigner": false + }, + { + "name": "owner", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + } + ], + "args": [], + "discriminant": { + "type": "u8", + "value": 14 + } + }, + { + "name": "updateConfigAccount", + "accounts": [ + { + "name": "admin", + "isMut": false, + "isSigner": true + }, + { + "name": "ammConfig", + "isMut": true, + "isSigner": false + } + ], + "args": [ + { + "name": "param", + "type": "u8" + }, + { + "name": "owner", + "type": "publicKey" + } + ], + "discriminant": { + "type": "u8", + "value": 15 + } + } + ], + "accounts": [ + { + "name": "TargetOrders", + "type": { + "kind": "struct", + "fields": [ + { + "name": "owner", + "type": { + "array": [ + "u64", + 4 + ] + } + }, + { + "name": "buyOrders", + "type": { + "array": [ + { + "defined": "TargetOrder" + }, + 50 + ] + } + }, + { + "name": "padding1", + "type": { + "array": [ + "u64", + 8 + ] + } + }, + { + "name": "targetX", + "type": "u128" + }, + { + "name": "targetY", + "type": "u128" + }, + { + "name": "planXBuy", + "type": "u128" + }, + { + "name": "planYBuy", + "type": "u128" + }, + { + "name": "planXSell", + "type": "u128" + }, + { + "name": "planYSell", + "type": "u128" + }, + { + "name": "placedX", + "type": "u128" + }, + { + "name": "placedY", + "type": "u128" + }, + { + "name": "calcPnlX", + "type": "u128" + }, + { + "name": "calcPnlY", + "type": "u128" + }, + { + "name": "sellOrders", + "type": { + "array": [ + { + "defined": "TargetOrder" + }, + 50 + ] + } + }, + { + "name": "padding2", + "type": { + "array": [ + "u64", + 6 + ] + } + }, + { + "name": "replaceBuyClientId", + "type": { + "array": [ + "u64", + 10 + ] + } + }, + { + "name": "replaceSellClientId", + "type": { + "array": [ + "u64", + 10 + ] + } + }, + { + "name": "lastOrderNumerator", + "type": "u64" + }, + { + "name": "lastOrderDenominator", + "type": "u64" + }, + { + "name": "planOrdersCur", + "type": "u64" + }, + { + "name": "placeOrdersCur", + "type": "u64" + }, + { + "name": "validBuyOrderNum", + "type": "u64" + }, + { + "name": "validSellOrderNum", + "type": "u64" + }, + { + "name": "padding3", + "type": { + "array": [ + "u64", + 10 + ] + } + }, + { + "name": "freeSlotBits", + "type": "u128" + } + ] + } + }, + { + "name": "Fees", + "type": { + "kind": "struct", + "fields": [ + { + "name": "minSeparateNumerator", + "type": "u64" + }, + { + "name": "minSeparateDenominator", + "type": "u64" + }, + { + "name": "tradeFeeNumerator", + "type": "u64" + }, + { + "name": "tradeFeeDenominator", + "type": "u64" + }, + { + "name": "pnlNumerator", + "type": "u64" + }, + { + "name": "pnlDenominator", + "type": "u64" + }, + { + "name": "swapFeeNumerator", + "type": "u64" + }, + { + "name": "swapFeeDenominator", + "type": "u64" + } + ] + } + }, + { + "name": "AmmInfo", + "type": { + "kind": "struct", + "fields": [ + { + "name": "status", + "type": "u64" + }, + { + "name": "nonce", + "type": "u64" + }, + { + "name": "orderNum", + "type": "u64" + }, + { + "name": "depth", + "type": "u64" + }, + { + "name": "coinDecimals", + "type": "u64" + }, + { + "name": "pcDecimals", + "type": "u64" + }, + { + "name": "state", + "type": "u64" + }, + { + "name": "resetFlag", + "type": "u64" + }, + { + "name": "minSize", + "type": "u64" + }, + { + "name": "volMaxCutRatio", + "type": "u64" + }, + { + "name": "amountWave", + "type": "u64" + }, + { + "name": "coinLotSize", + "type": "u64" + }, + { + "name": "pcLotSize", + "type": "u64" + }, + { + "name": "minPriceMultiplier", + "type": "u64" + }, + { + "name": "maxPriceMultiplier", + "type": "u64" + }, + { + "name": "sysDecimalValue", + "type": "u64" + }, + { + "name": "fees", + "type": { + "defined": "Fees" + } + }, + { + "name": "outPut", + "type": { + "defined": "OutPutData" + } + }, + { + "name": "tokenCoin", + "type": "publicKey" + }, + { + "name": "tokenPc", + "type": "publicKey" + }, + { + "name": "coinMint", + "type": "publicKey" + }, + { + "name": "pcMint", + "type": "publicKey" + }, + { + "name": "lpMint", + "type": "publicKey" + }, + { + "name": "openOrders", + "type": "publicKey" + }, + { + "name": "market", + "type": "publicKey" + }, + { + "name": "serumDex", + "type": "publicKey" + }, + { + "name": "targetOrders", + "type": "publicKey" + }, + { + "name": "withdrawQueue", + "type": "publicKey" + }, + { + "name": "tokenTempLp", + "type": "publicKey" + }, + { + "name": "ammOwner", + "type": "publicKey" + }, + { + "name": "lpAmount", + "type": "u64" + }, + { + "name": "clientOrderId", + "type": "u64" + }, + { + "name": "padding", + "type": { + "array": [ + "u64", + 2 + ] + } + } + ] + } + } + ], + "types": [ + { + "name": "WithdrawDestToken", + "type": { + "kind": "struct", + "fields": [ + { + "name": "withdrawAmount", + "type": "u64" + }, + { + "name": "coinAmount", + "type": "u64" + }, + { + "name": "pcAmount", + "type": "u64" + }, + { + "name": "destTokenCoin", + "type": "publicKey" + }, + { + "name": "destTokenPc", + "type": "publicKey" + } + ] + } + }, + { + "name": "WithdrawQueue", + "type": { + "kind": "struct", + "fields": [ + { + "name": "owner", + "type": { + "array": [ + "u64", + 4 + ] + } + }, + { + "name": "head", + "type": "u64" + }, + { + "name": "count", + "type": "u64" + }, + { + "name": "buf", + "type": { + "array": [ + { + "defined": "WithdrawDestToken" + }, + 64 + ] + } + } + ] + } + }, + { + "name": "TargetOrder", + "type": { + "kind": "struct", + "fields": [ + { + "name": "price", + "type": "u64" + }, + { + "name": "vol", + "type": "u64" + } + ] + } + }, + { + "name": "OutPutData", + "type": { + "kind": "struct", + "fields": [ + { + "name": "needTakePnlCoin", + "type": "u64" + }, + { + "name": "needTakePnlPc", + "type": "u64" + }, + { + "name": "totalPnlPc", + "type": "u64" + }, + { + "name": "totalPnlCoin", + "type": "u64" + }, + { + "name": "poolOpenTime", + "type": "u64" + }, + { + "name": "punishPcAmount", + "type": "u64" + }, + { + "name": "punishCoinAmount", + "type": "u64" + }, + { + "name": "orderbookToInitTime", + "type": "u64" + }, + { + "name": "swapCoinInAmount", + "type": "u128" + }, + { + "name": "swapPcOutAmount", + "type": "u128" + }, + { + "name": "swapTakePcFee", + "type": "u64" + }, + { + "name": "swapPcInAmount", + "type": "u128" + }, + { + "name": "swapCoinOutAmount", + "type": "u128" + }, + { + "name": "swapTakeCoinFee", + "type": "u64" + } + ] + } + }, + { + "name": "AmmConfig", + "type": { + "kind": "struct", + "fields": [ + { + "name": "pnlOwner", + "type": "publicKey" + }, + { + "name": "cancelOwner", + "type": "publicKey" + }, + { + "name": "pending1", + "type": { + "array": [ + "u64", + 28 + ] + } + }, + { + "name": "pending2", + "type": { + "array": [ + "u64", + 32 + ] + } + } + ] + } + }, + { + "name": "LastOrderDistance", + "type": { + "kind": "struct", + "fields": [ + { + "name": "lastOrderNumerator", + "type": "u64" + }, + { + "name": "lastOrderDenominator", + "type": "u64" + } + ] + } + }, + { + "name": "NeedTake", + "type": { + "kind": "struct", + "fields": [ + { + "name": "needTakePc", + "type": "u64" + }, + { + "name": "needTakeCoin", + "type": "u64" + } + ] + } + }, + { + "name": "SwapInstructionBaseIn", + "type": { + "kind": "struct", + "fields": [ + { + "name": "amountIn", + "type": "u64" + }, + { + "name": "minimumAmountOut", + "type": "u64" + } + ] + } + }, + { + "name": "SwapInstructionBaseOut", + "type": { + "kind": "struct", + "fields": [ + { + "name": "maxAmountIn", + "type": "u64" + }, + { + "name": "amountOut", + "type": "u64" + } + ] + } + } + ], + "errors": [ + { + "code": 0, + "name": "AlreadyInUse", + "msg": "AlreadyInUse" + }, + { + "code": 1, + "name": "InvalidProgramAddress", + "msg": "InvalidProgramAddress" + }, + { + "code": 2, + "name": "ExpectedMint", + "msg": "ExpectedMint" + }, + { + "code": 3, + "name": "ExpectedAccount", + "msg": "ExpectedAccount" + }, + { + "code": 4, + "name": "InvalidCoinVault", + "msg": "InvalidCoinVault" + }, + { + "code": 5, + "name": "InvalidPCVault", + "msg": "InvalidPCVault" + }, + { + "code": 6, + "name": "InvalidTokenLP", + "msg": "InvalidTokenLP" + }, + { + "code": 7, + "name": "InvalidDestTokenCoin", + "msg": "InvalidDestTokenCoin" + }, + { + "code": 8, + "name": "InvalidDestTokenPC", + "msg": "InvalidDestTokenPC" + }, + { + "code": 9, + "name": "InvalidPoolMint", + "msg": "InvalidPoolMint" + }, + { + "code": 10, + "name": "InvalidOpenOrders", + "msg": "InvalidOpenOrders" + }, + { + "code": 11, + "name": "InvalidSerumMarket", + "msg": "InvalidSerumMarket" + }, + { + "code": 12, + "name": "InvalidSerumProgram", + "msg": "InvalidSerumProgram" + }, + { + "code": 13, + "name": "InvalidTargetOrders", + "msg": "InvalidTargetOrders" + }, + { + "code": 14, + "name": "InvalidWithdrawQueue", + "msg": "InvalidWithdrawQueue" + }, + { + "code": 15, + "name": "InvalidTempLp", + "msg": "InvalidTempLp" + }, + { + "code": 16, + "name": "InvalidCoinMint", + "msg": "InvalidCoinMint" + }, + { + "code": 17, + "name": "InvalidPCMint", + "msg": "InvalidPCMint" + }, + { + "code": 18, + "name": "InvalidOwner", + "msg": "InvalidOwner" + }, + { + "code": 19, + "name": "InvalidSupply", + "msg": "InvalidSupply" + }, + { + "code": 20, + "name": "InvalidDelegate", + "msg": "InvalidDelegate" + }, + { + "code": 21, + "name": "InvalidSignAccount", + "msg": "Invalid Sign Account" + }, + { + "code": 22, + "name": "InvalidStatus", + "msg": "InvalidStatus" + }, + { + "code": 23, + "name": "InvalidInstruction", + "msg": "Invalid instruction" + }, + { + "code": 24, + "name": "WrongAccountsNumber", + "msg": "Wrong accounts number" + }, + { + "code": 25, + "name": "WithdrawTransferBusy", + "msg": "Withdraw_transfer is busy" + }, + { + "code": 26, + "name": "WithdrawQueueFull", + "msg": "WithdrawQueue is full" + }, + { + "code": 27, + "name": "WithdrawQueueEmpty", + "msg": "WithdrawQueue is empty" + }, + { + "code": 28, + "name": "InvalidParamsSet", + "msg": "Params Set is invalid" + }, + { + "code": 29, + "name": "InvalidInput", + "msg": "InvalidInput" + }, + { + "code": 30, + "name": "ExceededSlippage", + "msg": "instruction exceeds desired slippage limit" + }, + { + "code": 31, + "name": "CalculationExRateFailure", + "msg": "CalculationExRateFailure" + }, + { + "code": 32, + "name": "CheckedSubOverflow", + "msg": "Checked_Sub Overflow" + }, + { + "code": 33, + "name": "CheckedAddOverflow", + "msg": "Checked_Add Overflow" + }, + { + "code": 34, + "name": "CheckedMulOverflow", + "msg": "Checked_Mul Overflow" + }, + { + "code": 35, + "name": "CheckedDivOverflow", + "msg": "Checked_Div Overflow" + }, + { + "code": 36, + "name": "CheckedEmptyFunds", + "msg": "Empty Funds" + }, + { + "code": 37, + "name": "CalcPnlError", + "msg": "Calc pnl error" + }, + { + "code": 38, + "name": "InvalidSplTokenProgram", + "msg": "InvalidSplTokenProgram" + }, + { + "code": 39, + "name": "TakePnlError", + "msg": "Take Pnl error" + }, + { + "code": 40, + "name": "InsufficientFunds", + "msg": "Insufficient funds" + }, + { + "code": 41, + "name": "ConversionFailure", + "msg": "Conversion to u64 failed with an overflow or underflow" + }, + { + "code": 42, + "name": "InvalidUserToken", + "msg": "user token input does not match amm" + }, + { + "code": 43, + "name": "InvalidSrmMint", + "msg": "InvalidSrmMint" + }, + { + "code": 44, + "name": "InvalidSrmToken", + "msg": "InvalidSrmToken" + }, + { + "code": 45, + "name": "TooManyOpenOrders", + "msg": "TooManyOpenOrders" + }, + { + "code": 46, + "name": "OrderAtSlotIsPlaced", + "msg": "OrderAtSlotIsPlaced" + }, + { + "code": 47, + "name": "InvalidSysProgramAddress", + "msg": "InvalidSysProgramAddress" + }, + { + "code": 48, + "name": "InvalidFee", + "msg": "The provided fee does not match the program owner's constraints" + }, + { + "code": 49, + "name": "RepeatCreateAmm", + "msg": "Repeat create amm about market" + }, + { + "code": 50, + "name": "NotAllowZeroLP", + "msg": "Not allow Zero LP" + }, + { + "code": 51, + "name": "InvalidCloseAuthority", + "msg": "Token account has a close authority" + }, + { + "code": 52, + "name": "InvalidFreezeAuthority", + "msg": "Pool token mint has a freeze authority" + }, + { + "code": 53, + "name": "InvalidReferPCMint", + "msg": "InvalidReferPCMint" + }, + { + "code": 54, + "name": "InvalidConfigAccount", + "msg": "InvalidConfigAccount" + }, + { + "code": 55, + "name": "RepeatCreateConfigAccount", + "msg": "Repeat create staking config account" + }, + { + "code": 56, + "name": "UnknownAmmError", + "msg": "Unknown Amm Error" + } + ], + "events": [ + { + "name": "Init", + "fields": [ + { + "name": "logType", + "index": false, + "type": "u8" + }, + { + "name": "time", + "index": false, + "type": "u64" + }, + { + "name": "pcDecimals", + "index": false, + "type": "u8" + }, + { + "name": "coinDecimals", + "index": false, + "type": "u8" + }, + { + "name": "pcLotSize", + "index": false, + "type": "u64" + }, + { + "name": "coinLotSize", + "index": false, + "type": "u64" + }, + { + "name": "pcAmount", + "index": false, + "type": "u64" + }, + { + "name": "coinAmount", + "index": false, + "type": "u64" + }, + { + "name": "market", + "index": false, + "type": "publicKey" + } + ] + }, + { + "name": "Deposit", + "fields": [ + { + "name": "logType", + "index": false, + "type": "u8" + }, + { + "name": "maxCoin", + "index": false, + "type": "u64" + }, + { + "name": "maxPc", + "index": false, + "type": "u64" + }, + { + "name": "base", + "index": false, + "type": "u64" + }, + { + "name": "poolCoin", + "index": false, + "type": "u64" + }, + { + "name": "poolPc", + "index": false, + "type": "u64" + }, + { + "name": "poolLp", + "index": false, + "type": "u64" + }, + { + "name": "calcPnlX", + "index": false, + "type": "u128" + }, + { + "name": "calcPnlY", + "index": false, + "type": "u128" + }, + { + "name": "deductCoin", + "index": false, + "type": "u64" + }, + { + "name": "deductPc", + "index": false, + "type": "u64" + }, + { + "name": "mintLp", + "index": false, + "type": "u64" + } + ] + }, + { + "name": "Withdraw", + "fields": [ + { + "name": "logType", + "index": false, + "type": "u8" + }, + { + "name": "withdrawLP", + "index": false, + "type": "u64" + }, + { + "name": "userLP", + "index": false, + "type": "u64" + }, + { + "name": "poolCoin", + "index": false, + "type": "u64" + }, + { + "name": "poolPC", + "index": false, + "type": "u64" + }, + { + "name": "poolLP", + "index": false, + "type": "u64" + }, + { + "name": "calcPnlX", + "index": false, + "type": "u128" + }, + { + "name": "calcPnlY", + "index": false, + "type": "u128" + }, + { + "name": "outCoin", + "index": false, + "type": "u64" + }, + { + "name": "outPC", + "index": false, + "type": "u64" + } + ] + }, + { + "name": "SwapBaseIn", + "fields": [ + { + "name": "logType", + "index": false, + "type": "u8" + }, + { + "name": "amountIn", + "index": false, + "type": "u64" + }, + { + "name": "minimumAmountOut", + "index": false, + "type": "u64" + }, + { + "name": "direction", + "index": false, + "type": "u64" + }, + { + "name": "userSource", + "index": false, + "type": "u64" + }, + { + "name": "poolCoin", + "index": false, + "type": "u64" + }, + { + "name": "poolPc", + "index": false, + "type": "u64" + }, + { + "name": "outAmount", + "index": false, + "type": "u64" + } + ] + }, + { + "name": "SwapBaseOut", + "fields": [ + { + "name": "logType", + "index": false, + "type": "u8" + }, + { + "name": "maxAmountIn", + "index": false, + "type": "u64" + }, + { + "name": "amountOut", + "index": false, + "type": "u64" + }, + { + "name": "direction", + "index": false, + "type": "u64" + }, + { + "name": "userSource", + "index": false, + "type": "u64" + }, + { + "name": "poolCoin", + "index": false, + "type": "u64" + }, + { + "name": "poolPc", + "index": false, + "type": "u64" + }, + { + "name": "deductIn", + "index": false, + "type": "u64" + } + ] + } + ], + "metadata": { + "address": "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8", + "origin": "shank" + } +} \ No newline at end of file diff --git a/sol-anchor/templates/proto/program.proto.gotmpl b/sol-anchor/templates/proto/program.proto.gotmpl index fe20c3c..b18cb02 100644 --- a/sol-anchor/templates/proto/program.proto.gotmpl +++ b/sol-anchor/templates/proto/program.proto.gotmpl @@ -6,16 +6,16 @@ message Data { {{- $counter := 0 }} {{- range $i, $event := .Idl.Events }} {{- $counter = add $counter 1 }} - repeated {{ $event.Name }} {{ $event.SnakeCaseName }}_list = {{ $counter }}; + repeated {{ $event.Name }}_Event {{ $event.SnakeCaseName }}_event_list = {{ $counter }}; {{- end}} {{- range $i, $instruction := .Idl.Instructions -}} {{- $counter = add $counter 1 }} - repeated {{ $instruction.PascalCaseName }} {{ $instruction.SnakeCaseName }}_list = {{ $counter }}; + repeated {{ $instruction.PascalCaseName }}_Instruction {{ $instruction.SnakeCaseName }}_instruction_list = {{ $counter }}; {{- end }} } {{ range $i, $event := .Idl.Events -}} -message {{$event.Name}} { +message {{$event.Name}}_Event { string trx_hash = 1; {{- $counter := 1 }} {{- range $i, $field := $event.Fields }} @@ -25,7 +25,7 @@ message {{$event.Name}} { } {{- end}} {{ range $i, $instruction := .Idl.Instructions }} -message {{$instruction.PascalCaseName}} { +message {{$instruction.PascalCaseName}}_Instruction { string trx_hash = 1; {{- $counter := 1 }} {{- range $i, $arg := $instruction.Args }} @@ -41,7 +41,7 @@ message {{$instruction.PascalCaseName}} { } {{- end}} -{{ range $i, $type := .Idl.Types }} +{{ range $i, $type := .Idl.AccountsAndTypes }} {{- if $.Idl.IsTypeUsed $type.Name }} {{- if $type.Type.IsStruct }} message {{$type.Name}} { diff --git a/sol-anchor/templates/src/lib.rs.gotmpl b/sol-anchor/templates/src/lib.rs.gotmpl index 182d4b7..70dc905 100644 --- a/sol-anchor/templates/src/lib.rs.gotmpl +++ b/sol-anchor/templates/src/lib.rs.gotmpl @@ -7,14 +7,14 @@ use base64::prelude::*; use pb::substreams::v1::program::Data; {{- range $i, $event := .Idl.Events }} -use pb::substreams::v1::program::{{$event.Name}}; +use pb::substreams::v1::program::{{$event.Name}}Event; {{- end}} {{- range $i, $instruction := .Idl.Instructions }} -use pb::substreams::v1::program::{{$instruction.PascalCaseName}}; +use pb::substreams::v1::program::{{$instruction.PascalCaseName}}Instruction; {{- end}} -{{- range $i, $type := .Idl.Types }} +{{- range $i, $type := .Idl.AccountsAndTypes }} {{ if $.Idl.IsTypeUsed $type.Name }} {{ if $type.Type.IsEnum }} use pb::substreams::v1::program::{{$type.Name}}Enum; @@ -34,11 +34,11 @@ const PROGRAM_ID: &str = "{{.Idl.ProgramID}}"; fn map_program_data(blk: Block) -> Data { {{- range $i, $event := .Idl.Events }} - let mut {{ $event.SnakeCaseName }}_list: Vec<{{$event.Name}}> = Vec::new(); + let mut {{ $event.SnakeCaseName }}_event_list: Vec<{{$event.Name}}Event> = Vec::new(); {{- end}} {{- range $i, $instruction := .Idl.Instructions }} - let mut {{ $instruction.SnakeCaseName }}_list: Vec<{{$instruction.PascalCaseName}}> = Vec::new(); + let mut {{ $instruction.SnakeCaseName }}_instruction_list: Vec<{{$instruction.PascalCaseName}}Instruction> = Vec::new(); {{- end}} blk.transactions().for_each(|transaction| { @@ -69,10 +69,10 @@ fn map_program_data(blk: Block) -> Data { &mut &slice_u8[8..], ) { - {{ $event.SnakeCaseName }}_list.push({{ $event.Name }} { + {{ $event.SnakeCaseName }}_event_list.push({{ $event.Name }}Event { trx_hash: transaction.id(), {{- range $i, $arg := $event.Fields }} - {{ $arg.Type.Print $arg.Name "event" $.Idl.Types }} + {{ $arg.Type.Print $arg.Name "event" $.Idl.AccountsAndTypes }} {{- end}} }); } @@ -100,10 +100,10 @@ fn map_program_data(blk: Block) -> Data { idl::idl::program::client::args::{{ $instruction.PascalCaseName }}::deserialize(&mut &slice_u8[8..]) { let accts = inst.accounts(); - {{ $instruction.SnakeCaseName }}_list.push({{ $instruction.PascalCaseName }} { + {{ $instruction.SnakeCaseName }}_instruction_list.push({{ $instruction.PascalCaseName }}Instruction { trx_hash: transaction.id(), {{- range $i, $arg := $instruction.Args }} - {{ $arg.Type.Print $arg.Name "instruction" $.Idl.Types }} + {{ $arg.Type.Print $arg.Name "instruction" $.Idl.AccountsAndTypes }} {{- end }} {{- range $i, $acc := $instruction.Accounts }} {{- if not $acc.Address }} @@ -121,11 +121,11 @@ fn map_program_data(blk: Block) -> Data { Data { {{- range $i, $event := .Idl.Events }} - {{ $event.SnakeCaseName }}_list, + {{ $event.SnakeCaseName }}_event_list, {{- end }} {{- range $i, $instruction := .Idl.Instructions }} - {{ $instruction.SnakeCaseName }}_list, + {{ $instruction.SnakeCaseName }}_instruction_list, {{- end }} } } @@ -147,7 +147,37 @@ fn map_option_{{$type.SnakeCaseName}}(value: Option { return Some({{$type.PascalCaseName}} { {{- range $i, $field := $type.Type.Struct.Fields }} - {{ $field.Type.Print $field.Name $type.SnakeCaseName $.Idl.Types }} + {{ $field.Type.Print $field.Name $type.SnakeCaseName $.Idl.AccountsAndTypes }} + {{- end}} + }) + }, + None => { + return None; + } + } +} +{{ end }} +{{ end }} +{{- end }} + +{{ range $i, $type := .Idl.Accounts }} +{{- if $type.Type.IsEnum -}} +fn map_enum_{{$type.SnakeCaseName}}(value: idl::idl::program::accounts::{{ $type.Name }}) -> i32 { + match value { + {{- range $j, $variant := $type.Type.Enum.Variants }} + idl::idl::program::types::{{ $type.Name }}::{{ $variant.Name }} => return {{ $j }}, + {{- end}} + _ => 0, + } +} +{{ else }} +{{ if $.Idl.IsTypeUsed $type.Name }} +fn map_option_{{$type.SnakeCaseName}}(value: Option) -> Option<{{ $type.Name }}> { + match value { + Some({{$type.SnakeCaseName}}) => { + return Some({{$type.PascalCaseName}} { + {{- range $i, $field := $type.Type.Struct.Fields }} + {{ $field.Type.Print $field.Name $type.SnakeCaseName $.Idl.AccountsAndTypes }} {{- end}} }) }, From 303f1956805bae832508d2e62d0a26dc13d56422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enol=20=C3=81lvarez?= Date: Fri, 21 Mar 2025 13:04:54 +0100 Subject: [PATCH 3/7] wip --- sol-anchor/idl_fields.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/sol-anchor/idl_fields.go b/sol-anchor/idl_fields.go index 5473b41..313c07a 100644 --- a/sol-anchor/idl_fields.go +++ b/sol-anchor/idl_fields.go @@ -32,6 +32,7 @@ type FieldTypeArray struct { type FieldTypeVec struct { Type string IsDefined bool + IsArray bool } type FieldTypeOption struct { @@ -301,8 +302,8 @@ func unmarshalSimple(data []byte) string { /* Return types: - bool: isDefined (true/false) - string: type (simple/defined) + string: "simple/defined/array" + string: type */ func unmarshalVec(data []byte) (bool, string) { // Try simple @@ -314,6 +315,18 @@ func unmarshalVec(data []byte) (bool, string) { return false, vecSimpleType.Vec } + // Try array + type ArrayType struct { + Array []interface{} `json:"array"` + } + var vecArrayType struct { + Vec ArrayType `json:"vec"` + } + err = json.Unmarshal(data, &vecArrayType) + if err == nil { + return false, vecSimpleType.Vec + } + // Try defined type DefinedType struct { Defined string `json:"defined"` From bf9dc271fb268b8bbfcf400db5825cf46554c056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enol=20=C3=81lvarez?= Date: Sun, 23 Mar 2025 23:15:33 +0100 Subject: [PATCH 4/7] add vec --- sol-anchor/idl_fields.go | 83 ++-- sol-anchor/idl_test.go | 13 +- sol-anchor/idls/proof_of_play.json | 593 +++++++++++++++++++++++++++++ 3 files changed, 662 insertions(+), 27 deletions(-) create mode 100644 sol-anchor/idls/proof_of_play.json diff --git a/sol-anchor/idl_fields.go b/sol-anchor/idl_fields.go index 313c07a..f152b4f 100644 --- a/sol-anchor/idl_fields.go +++ b/sol-anchor/idl_fields.go @@ -32,7 +32,7 @@ type FieldTypeArray struct { type FieldTypeVec struct { Type string IsDefined bool - IsArray bool + IsArray bool } type FieldTypeOption struct { @@ -134,6 +134,9 @@ func (t *FieldType) Resolve() string { } if t.IsVec() { + if t.Vec.IsArray { + return "bytes" + } return t.Vec.Type } @@ -249,11 +252,15 @@ func (f *FieldType) Print(fieldName string, variableName string, types []Type) s return fmt.Sprintf("%s: %s.%s.into_iter().map(|f| f as %s).collect(),", fieldNameSnakeCaseWithoutInitialUnderscore, variableName, fieldNameSnakeCase, cast) } + if f.IsVec() && f.Vec.IsArray { + return fmt.Sprintf("%s: %s.%s.into_iter().map(|%s| %s.to_vec()).collect(),", fieldNameSnakeCaseWithoutInitialUnderscore, variableName, fieldNameSnakeCase, fieldNameSnakeCase, fieldNameSnakeCase) + } + if f.IsVec() && f.Vec.IsDefined { return fmt.Sprintf("%s: %s.%s.into_iter().map(|%s| %s).collect(),", fieldNameSnakeCaseWithoutInitialUnderscore, variableName, fieldNameSnakeCase, fieldNameSnakeCase, PrintDefined(f.Vec.Type, fieldNameSnakeCase, "", types, true, false)) } - if f.IsVec() && !f.Vec.IsDefined { + if f.IsVec() && !f.Vec.IsDefined && !f.Vec.IsArray { return fmt.Sprintf("%s: %s.%s,", fieldNameSnakeCaseWithoutInitialUnderscore, variableName, fieldNameSnakeCase) } @@ -305,26 +312,14 @@ Return types: string: "simple/defined/array" string: type */ -func unmarshalVec(data []byte) (bool, string) { +func unmarshalVec(data []byte) (string, string) { // Try simple var vecSimpleType struct { Vec string `json:"vec"` } err := json.Unmarshal(data, &vecSimpleType) if err == nil { - return false, vecSimpleType.Vec - } - - // Try array - type ArrayType struct { - Array []interface{} `json:"array"` - } - var vecArrayType struct { - Vec ArrayType `json:"vec"` - } - err = json.Unmarshal(data, &vecArrayType) - if err == nil { - return false, vecSimpleType.Vec + return "simple", vecSimpleType.Vec } // Try defined @@ -335,8 +330,8 @@ func unmarshalVec(data []byte) (bool, string) { Vec DefinedType `json:"vec"` } err = json.Unmarshal(data, &vecDefinedType) - if err == nil { - return true, vecDefinedType.Vec.Defined + if err == nil && vecDefinedType.Vec.Defined != "" { + return "defined", vecDefinedType.Vec.Defined } /* @@ -375,11 +370,34 @@ func unmarshalVec(data []byte) (bool, string) { Vec DefinedTypeWithName `json:"vec"` } err = json.Unmarshal(data, &vecDefinedTypeWithName) + if err == nil && vecDefinedType.Vec.Defined != "" { + return "defined", vecDefinedTypeWithName.Vec.Defined.Name + } + + // Try array + type ArrayType struct { + Array []interface{} `json:"array"` + } + var vecArrayType struct { + Vec ArrayType `json:"vec"` + } + err = json.Unmarshal(data, &vecArrayType) if err == nil { - return true, vecDefinedTypeWithName.Vec.Defined.Name + if len(vecArrayType.Vec.Array) == 2 { + typeStr, ok1 := vecArrayType.Vec.Array[0].(string) + _, ok2 := vecArrayType.Vec.Array[1].(float64) // JSON numbers are decoded as float64 + + if ok1 && ok2 { + return "array", typeStr + } else { + return "", "" + } + } else { + return "", "" + } } - return false, "" + return "", "" } /* @@ -462,11 +480,26 @@ func (t *FieldType) UnmarshalJSON(data []byte) error { return nil } - isDefined, result := unmarshalVec(data) - if result != "" { - t.Vec = &FieldTypeVec{ - Type: result, - IsDefined: isDefined, + kind, kindType := unmarshalVec(data) + if kind != "" && kindType != "" { + if kind == "simple" { + t.Vec = &FieldTypeVec{ + Type: kindType, + IsDefined: false, + IsArray: false, + } + } else if kind == "defined" { + t.Vec = &FieldTypeVec{ + Type: kindType, + IsDefined: true, + IsArray: false, + } + } else { + t.Vec = &FieldTypeVec{ + Type: kindType, + IsDefined: false, + IsArray: true, + } } return nil diff --git a/sol-anchor/idl_test.go b/sol-anchor/idl_test.go index 00a43b7..7537ef4 100644 --- a/sol-anchor/idl_test.go +++ b/sol-anchor/idl_test.go @@ -99,13 +99,22 @@ func TestRaydiumAMM(t *testing.T) { } } - fmt.Println("-------------------------") - fmt.Println(PrintDefined("SwapInstructionBaseIn", "instruction", "instruction", result.Types, false, true)) assert.Nil(t, err) } + +func TestProofOfPlay(t *testing.T) { + idl := readFromFile("proof_of_play") + + result := &IDL{} + err := json.Unmarshal(idl, &result) + + assert.Nil(t, err) +} + + func readFromFile(idlName string) []byte { data, err := os.ReadFile("idls/" + idlName + ".json") if err != nil { diff --git a/sol-anchor/idls/proof_of_play.json b/sol-anchor/idls/proof_of_play.json new file mode 100644 index 0000000..af31e06 --- /dev/null +++ b/sol-anchor/idls/proof_of_play.json @@ -0,0 +1,593 @@ +{ + "address": "7fohpwD3H5ceMK8xVM4cTPBJa2bxf6qD6FjqEA4FMNj6", + "metadata": { + "name": "proof_of_play", + "version": "0.1.0", + "spec": "0.1.0", + "description": "Created with Anchor" + }, + "instructions": [ + { + "name": "claim", + "discriminator": [ + 62, + 198, + 214, + 193, + 213, + 159, + 108, + 210 + ], + "accounts": [ + { + "name": "merkle_root", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 97, + 117, + 116, + 104, + 111, + 114, + 105, + 116, + 121 + ] + } + ] + } + }, + { + "name": "token_mint" + }, + { + "name": "claimer", + "writable": true, + "signer": true + }, + { + "name": "claimer_token_account", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "account", + "path": "claimer" + }, + { + "kind": "account", + "path": "token_program" + }, + { + "kind": "account", + "path": "token_mint" + } + ], + "program": { + "kind": "const", + "value": [ + 140, + 151, + 37, + 143, + 78, + 36, + 137, + 241, + 187, + 61, + 16, + 41, + 20, + 142, + 13, + 131, + 11, + 90, + 19, + 153, + 218, + 255, + 16, + 132, + 4, + 142, + 123, + 216, + 219, + 233, + 248, + 89 + ] + } + } + }, + { + "name": "claim_record", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 99, + 108, + 97, + 105, + 109, + 95, + 114, + 101, + 99, + 111, + 114, + 100 + ] + }, + { + "kind": "account", + "path": "claimer" + } + ] + } + }, + { + "name": "vault_holder", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 118, + 97, + 117, + 108, + 116, + 95, + 104, + 111, + 108, + 100, + 101, + 114 + ] + } + ] + } + }, + { + "name": "vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "account", + "path": "vault_holder" + }, + { + "kind": "account", + "path": "token_program" + }, + { + "kind": "account", + "path": "token_mint" + } + ], + "program": { + "kind": "const", + "value": [ + 140, + 151, + 37, + 143, + 78, + 36, + 137, + 241, + 187, + 61, + 16, + 41, + 20, + 142, + 13, + 131, + 11, + 90, + 19, + 153, + 218, + 255, + 16, + 132, + 4, + 142, + 123, + 216, + 219, + 233, + 248, + 89 + ] + } + } + }, + { + "name": "associated_token_program", + "address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" + }, + { + "name": "token_program" + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" + } + ], + "args": [ + { + "name": "value", + "type": "u64" + }, + { + "name": "proof", + "type": { + "vec": { + "array": [ + "u8", + 32 + ] + } + } + } + ] + }, + { + "name": "initialize", + "discriminator": [ + 175, + 175, + 109, + 31, + 13, + 152, + 155, + 237 + ], + "accounts": [ + { + "name": "merkle_root", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 97, + 117, + 116, + 104, + 111, + 114, + 105, + 116, + 121 + ] + } + ] + } + }, + { + "name": "token_mint" + }, + { + "name": "signer_token_account", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "account", + "path": "signer" + }, + { + "kind": "account", + "path": "token_program" + }, + { + "kind": "account", + "path": "token_mint" + } + ], + "program": { + "kind": "const", + "value": [ + 140, + 151, + 37, + 143, + 78, + 36, + 137, + 241, + 187, + 61, + 16, + 41, + 20, + 142, + 13, + 131, + 11, + 90, + 19, + 153, + 218, + 255, + 16, + 132, + 4, + 142, + 123, + 216, + 219, + 233, + 248, + 89 + ] + } + } + }, + { + "name": "vault_holder", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 118, + 97, + 117, + 108, + 116, + 95, + 104, + 111, + 108, + 100, + 101, + 114 + ] + } + ] + } + }, + { + "name": "vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "account", + "path": "vault_holder" + }, + { + "kind": "account", + "path": "token_program" + }, + { + "kind": "account", + "path": "token_mint" + } + ], + "program": { + "kind": "const", + "value": [ + 140, + 151, + 37, + 143, + 78, + 36, + 137, + 241, + 187, + 61, + 16, + 41, + 20, + 142, + 13, + 131, + 11, + 90, + 19, + 153, + 218, + 255, + 16, + 132, + 4, + 142, + 123, + 216, + 219, + 233, + 248, + 89 + ] + } + } + }, + { + "name": "signer", + "writable": true, + "signer": true + }, + { + "name": "associated_token_program", + "address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" + }, + { + "name": "token_program" + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" + } + ], + "args": [ + { + "name": "root", + "type": { + "array": [ + "u8", + 32 + ] + } + }, + { + "name": "offered_amount", + "type": "u64" + } + ] + } + ], + "accounts": [ + { + "name": "ClaimRecord", + "discriminator": [ + 57, + 229, + 0, + 9, + 65, + 62, + 96, + 7 + ] + }, + { + "name": "MerkleRoot", + "discriminator": [ + 30, + 240, + 94, + 145, + 74, + 59, + 138, + 185 + ] + }, + { + "name": "TokenVault", + "discriminator": [ + 121, + 7, + 84, + 254, + 151, + 228, + 43, + 144 + ] + } + ], + "errors": [ + { + "code": 6000, + "name": "InvalidRoot", + "msg": "Invalid Merkle root" + }, + { + "code": 6001, + "name": "InvalidProof", + "msg": "Invalid Merkle proof provided." + }, + { + "code": 6002, + "name": "Unauthorized", + "msg": "Unauthorized access." + }, + { + "code": 6003, + "name": "AlreadyClaimed", + "msg": "Already claimed." + } + ], + "types": [ + { + "name": "ClaimRecord", + "type": { + "kind": "struct", + "fields": [ + { + "name": "is_claimed", + "type": "bool" + }, + { + "name": "claimer", + "type": "pubkey" + }, + { + "name": "claimed_at", + "type": "i64" + }, + { + "name": "bump", + "type": "u8" + } + ] + } + }, + { + "name": "MerkleRoot", + "type": { + "kind": "struct", + "fields": [ + { + "name": "root", + "type": { + "array": [ + "u8", + 32 + ] + } + }, + { + "name": "authority", + "type": "pubkey" + }, + { + "name": "bump", + "type": "u8" + } + ] + } + }, + { + "name": "TokenVault", + "type": { + "kind": "struct", + "fields": [ + { + "name": "bump", + "type": "u8" + } + ] + } + } + ], + "constants": [ + { + "name": "AUTHORITY_SEED", + "type": "bytes", + "value": "[97, 117, 116, 104, 111, 114, 105, 116, 121]" + } + ] +} \ No newline at end of file From a870ffb6475c03e443e6859d3bffb29c9f536273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enol=20=C3=81lvarez?= Date: Sun, 23 Mar 2025 23:40:31 +0100 Subject: [PATCH 5/7] fix --- sol-anchor/idl_fields.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sol-anchor/idl_fields.go b/sol-anchor/idl_fields.go index f152b4f..a052d29 100644 --- a/sol-anchor/idl_fields.go +++ b/sol-anchor/idl_fields.go @@ -370,7 +370,7 @@ func unmarshalVec(data []byte) (string, string) { Vec DefinedTypeWithName `json:"vec"` } err = json.Unmarshal(data, &vecDefinedTypeWithName) - if err == nil && vecDefinedType.Vec.Defined != "" { + if err == nil && vecDefinedTypeWithName.Vec.Defined.Name != "" { return "defined", vecDefinedTypeWithName.Vec.Defined.Name } From df054760f1a92a6dc8eae9e2ce2ff5ecc9d0dadd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enol=20=C3=81lvarez?= Date: Mon, 24 Mar 2025 00:01:30 +0100 Subject: [PATCH 6/7] fix --- sol-anchor/idl_fields_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sol-anchor/idl_fields_test.go b/sol-anchor/idl_fields_test.go index 3dfdaf9..cfae22a 100644 --- a/sol-anchor/idl_fields_test.go +++ b/sol-anchor/idl_fields_test.go @@ -36,19 +36,19 @@ func TestUnmarshalSimple(t *testing.T) { func TestUnmarshalVecSimple(t *testing.T) { json := []byte(`{"vec": "string"}`) - isDefined, result := unmarshalVec(json) + kind, kindType := unmarshalVec(json) - assert.Equal(t, false, isDefined) - assert.Equal(t, "string", result) + assert.Equal(t, "simple", kind) + assert.Equal(t, "string", kindType) } func TestUnmarshalVecDefined(t *testing.T) { json := []byte(`{"vec": {"defined": "string"}}`) - isDefined, result := unmarshalVec(json) + kind, kindType := unmarshalVec(json) - assert.Equal(t, true, isDefined) - assert.Equal(t, "string", result) + assert.Equal(t, "defined", kind) + assert.Equal(t, "string", kindType) } // Test unmarshalOption From 023df162f91818e99824f147330796e090eee5e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enol=20=C3=81lvarez?= Date: Mon, 24 Mar 2025 17:53:41 +0100 Subject: [PATCH 7/7] add version 3 of the CLI as required --- server/handler_convo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/handler_convo.go b/server/handler_convo.go index 7540df5..faa5bc7 100644 --- a/server/handler_convo.go +++ b/server/handler_convo.go @@ -92,7 +92,7 @@ func (s *server) Converse(ctx context.Context, stream *connect.BidiStream[pbconv return fmt.Errorf("begin with UserInput_Start message") } - if start.Start.Version < 1 || (start.Start.GeneratorId == "sol-anchor-beta" && start.Start.Version <= 1) { + if start.Start.Version < 3 { return fmt.Errorf("\nunsupported protocol version %d, please upgrade your `substreams` CLI to the latest version\n\n- If you installed it through Brew, just execute:\n`brew upgrade substreams`.\n\n- You can also upgrade the CLI using one of the releases in GitHub: `https://github.com/streamingfast/substreams/releases`\n", start.Start.Version) }