Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
fd42b56
feat: add support for tuple enum variants
Nov 5, 2023
aeb11a1
chore: update README.md and added fragmetric dummy IDL
dehypnosis Jul 3, 2024
6821b51
Merge pull request #1 from melaurent/main
hooNode Jul 3, 2024
a2d7a0c
feat: add compatibliity for anchor >= v0.30.0
hooNode Jul 5, 2024
baf6453
Merge pull request #3 from encrypt-x/feat/compatibility
hooNode Jul 5, 2024
6fcbeff
fix: instructionImplDef initialied with unkeyed fields issue
hooNode Jul 10, 2024
afdf71a
fix: rename go module anchor-go -> solana-anchor-go
hooNode Jul 10, 2024
c89098d
fix: reform idl.Name -> idl.Metadata.Name and publicKey -> pubkey
hooNode Jul 10, 2024
e3fcd51
fix: make generated idl stored directory if not exist
hooNode Jul 10, 2024
f6dda29
fix: prevent from automatically creating generate directory
hooNode Jul 10, 2024
9d75346
feat(events): parse events, added DecodeInstructions, DecodeEvents fns
dehypnosis Jul 11, 2024
c89219a
feat(unmarshaler): all unmarshalers assume there can be unknown extra…
dehypnosis Jul 11, 2024
36e49a7
feat: support complex enum type, rollbacked to strict unmarshal
dehypnosis Jul 12, 2024
bf3b504
feat: added missing constant accounts to instruction, and PDA helper fns
dehypnosis Jul 12, 2024
22e8c13
feat: generates errors.go and DecodeCustomError fn
dehypnosis Jul 12, 2024
a34dbc7
fix: fixed complex enum type generation, generate PDA helper fns for …
dehypnosis Jul 26, 2024
e01375e
fix: generate PDA finders as a method of each instruction structs
dehypnosis Jul 26, 2024
5983a49
feat: added MustFindBlablPDA syntax sugar
dehypnosis Jul 26, 2024
f3ffc04
feat: support f32, f64
dehypnosis Aug 6, 2024
91b82f7
fix: PDA helper fns respect optionally given programID
dehypnosis Aug 7, 2024
0fd0bc4
feat: elaborate event decoding exception msg
dehypnosis Aug 25, 2024
3c05817
tmp
dehypnosis Sep 9, 2024
f3871a6
feat: added "Addresses" map and "CONST_..." variables
dehypnosis Sep 9, 2024
377655d
feat: replace with golang.org/x/net due to deprecation(docker-mac-net…
hooNode Dec 17, 2024
1813e1c
feat: decode event with emited cpi
hooNode Dec 17, 2024
8181bc5
fix: add base58 decode
hooNode Dec 17, 2024
1989c44
fix: decode with transactionMeta
hooNode Dec 17, 2024
2d8793f
Merge pull request #4 from fragmetric-labs/feat/decode-event
hooNode Dec 17, 2024
706d7db
fix: add base58 decode
hooNode Dec 17, 2024
468f077
fix: modify base58 import
hooNode Dec 17, 2024
eb0d0b0
fix: can parse i64 constant, can comment valid UTF-8 string
dehypnosis Dec 21, 2024
6ae0117
test: fragmetric restaking v0.3.3 parsing test #87
dehypnosis Dec 21, 2024
4703384
feat: parse pda arg type
hooNode Dec 30, 2024
c56d275
fix: decode event
hooNode Dec 30, 2024
b592e99
fix: test with option field
hooNode Dec 30, 2024
a63d228
fix: make account meta slice to nil
hooNode Dec 30, 2024
88dc4c0
fix: restore decode interface type in testing
hooNode Dec 31, 2024
2128452
fix: generate test for restaking idl program
hooNode Dec 31, 2024
4c89a4b
feat: can set ALT to decode events
dehypnosis Jan 20, 2025
90eb459
fix: Modify instruction ProgramID address assignment
congmucc Feb 28, 2025
5bb8808
fix: correct instruction ProgramID address assignment
congmucc Feb 28, 2025
6ec8452
fix: remove unused imports
congmucc Mar 13, 2025
1d09cef
Merge pull request #6 from congmucc/main
hooNode Mar 13, 2025
32b6c64
release(v1.0.0): support complex enum
dehypnosis Mar 24, 2025
d4fbeee
feat: added constraint for event discriminator
hooNode Mar 27, 2025
73244cf
fix: modify idl event parser
hooNode Mar 28, 2025
cb7b550
Merge pull request #9 from fragmetric-labs/feat/event-parse
dehypnosis Mar 28, 2025
15e596d
fix: for 0.30.1
dimatima13 Apr 28, 2025
6c316f7
chore: generated code
dimatima13 Apr 28, 2025
1c60acb
refactor: update naming conventions to PascalCase
dimatima13 Apr 28, 2025
dd9d865
refactor: remove deprecated address map generation and associated file
dimatima13 Apr 28, 2025
26bcac5
refactor: remove custom error handling code and associated error defi…
dimatima13 Apr 28, 2025
ac048b1
refactor: remove pda
dimatima13 Apr 28, 2025
c8af723
refactor: remove DecodeInstructions function from generated files
dimatima13 Apr 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
generated/
# generated/
solana-anchor-go
anchor-go
.vscode
.idea
.anchor
idl.json
.cursorindexingignore
.specstory
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
restaking:
go build && rm -rf ./generated/restaking && \
./solana-anchor-go -src=./example/restaking_idl.json -pkg=restaking -dst=./generated/restaking && \
go test ./generated/restaking && \
go test ./example/restaking_test.go

test:
make dummy && make restaking
55 changes: 15 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,28 @@

![logo](logo.png)

## usage
## Usage

```bash
anchor-go --src=/path/to/idl.json
$ go build
$ ./solana-anchor-go -src=./example/dummy_idl.json -pkg=dummy -dst=./generated/dummy
```

Generated Code will be generated and saved to `./generated/`.
And check `./example/dummy_test.go` for generated code usage.

## TODO
## Test
Build and generate code, then run test.
```
$ make dummy
$ make restaking
```

## TODO
- [x] instructions
- [x] accounts
- [x] types
- [ ] events
- [ ] errors
- [ ] handle tuple types
- [ ] constants

## Future Development

TBD

## what is anchor-go?

`anchor-go` generates Go clients for [Solana](https://solana.com/) programs (smart contracts) written using the [anchor](https://github.com/project-serum/anchor) framework.

## what is anchor?

Link: https://github.com/project-serum/anchor

```
Anchor is a framework for Solana's Sealevel runtime providing several convenient developer tools for writing smart contracts.
```

## I have an anchor program; how do I generate a Go client for it? (step by step)

### example 1: metaplex nft candy machine

```bash
git clone https://github.com/metaplex-foundation/metaplex-program-library.git
cd metaplex-program-library
anchor idl parse -f candy-machine/program/src/lib.rs -o nft_candy_machine_v2.json
anchor-go --src=nft_candy_machine_v2.json
```

Note
----

- anchor-go is in active development, so all APIs are subject to change.
- This code is unaudited. Use at your own risk.
- [x] events
- [x] errors
- [x] handle tuple types
- [x] constants
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Config struct {
TypeID TypeIDName
Debug bool
DstDir string
Package string
ModPath string
RemoveAccountSuffix bool
}
Expand Down
113 changes: 113 additions & 0 deletions example/complex_enum_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package example

func toPtr[T any](x T) *T {
return &x
}

//
//func TestComplexEnum(t *testing.T) {
// src := restaking.OperatorRanFundCommand{
// ReceiptTokenMint: ag_solanago.MustPublicKeyFromBase58("GPKjBDTNexAsis6zqGnioAzhauvHzs6UzGXKxx37HdkA"),
// FundAccount: ag_solanago.MustPublicKeyFromBase58("HdZM8mzEH7JAcswjJNgCC8Zmbu97LCzYo4WCSvFkfWKx"),
// NextSequence: 123,
// NumOperated: 456,
// Command: &restaking.OperationCommand{
// Value: restaking.OperationCommandProcessWithdrawalBatchTuple{
// Elem0: restaking.ProcessWithdrawalBatchCommand{
// State: &restaking.ProcessWithdrawalBatchCommandState{Value: restaking.ProcessWithdrawalBatchCommandStateExecuteTuple{
// AssetTokenMint: nil,
// NumProcessingBatches: 1,
// ReceiptTokenAmount: 12345,
// }},
// Forced: true,
// },
// },
// },
// Result: &restaking.OperationCommandResult{
// Value: restaking.OperationCommandResultProcessWithdrawalBatchTuple{
// Elem0: restaking.ProcessWithdrawalBatchCommandResult{
// RequestedReceiptTokenAmount: 1,
// ProcessedReceiptTokenAmount: 2,
// AssetTokenMint: nil,
// RequiredAssetAmount: 3,
// ReservedAssetUserAmount: 4,
// DeductedAssetFeeAmount: 5,
// OffsettedAssetReceivables: nil,
// TransferredAssetRevenueAmount: 6,
// WithdrawalFeeRateBps: 7,
// },
// },
// },
// }
//
// // encoding
// buf := new(bytes.Buffer)
// require.NoError(t, ag_binary.NewBorshEncoder(buf).Encode(src), "1")
//
// dst := restaking.OperatorRanFundCommand{}
// require.NoError(t, ag_binary.NewBorshDecoder(buf.Bytes()).Decode(&dst), "2")
//
// printer := spew.ConfigState{
// Indent: " ",
// DisablePointerAddresses: true,
// DisableCapacities: true,
// }
// require.Equal(t, printer.Sdump(src), printer.Sdump(dst), "3")
// printer.Dump(src)
//}
//
//func TestComplexEnum2(t *testing.T) {
// src := restaking.TokenValue{
// Numerator: []restaking.Asset{
// {
// Value: restaking.AssetSOLTuple{
// Elem0: 7777,
// },
// },
// {
// Value: restaking.AssetTokenTuple{
// Elem0: ag_solanago.MustPublicKeyFromBase58("GPKjBDTNexAsis6zqGnioAzhauvHzs6UzGXKxx37HdkA"),
// Elem1: &restaking.TokenPricingSource{
// Value: restaking.TokenPricingSourceMarinadeStakePoolTuple{
// Address: ag_solanago.MustPublicKeyFromBase58("HdZM8mzEH7JAcswjJNgCC8Zmbu97LCzYo4WCSvFkfWKx"),
// },
// },
// Elem2: 8888,
// },
// },
// },
// Denominator: 1234567,
// }
//
// // encoding
// buf := new(bytes.Buffer)
// require.NoError(t, ag_binary.NewBorshEncoder(buf).Encode(src), "1")
//
// dst := restaking.TokenValue{}
// require.NoError(t, ag_binary.NewBorshDecoder(buf.Bytes()).Decode(&dst), "2")
//
// printer := spew.ConfigState{
// Indent: " ",
// DisablePointerAddresses: true,
// DisableCapacities: true,
// }
// require.Equal(t, printer.Sdump(src), printer.Sdump(dst), "3")
// printer.Dump(src)
//}
//
//func TestComplexEnum_DecodeRawEvent(t *testing.T) {
// eventData, err := hex.DecodeString("e445a52e51cb9a1d0a001dcc807de395d634089bb695733914837de852fbd24cff284e2722a63480697643ca75f76c92349707ef78937aa1fdee335943b8d8e3eabc7a07f9384299867f65d1a69d98080000f0050000000000000702000100e1f5050000000000010700e1f5050000000000000000000000000000e13c0600000000000000000000000000000000000000000000000000000000000000001400")
// require.NoError(t, err, "failed to decode bytes")
// buf := bytes.NewBuffer(eventData[8:])
//
// dst := restaking.OperatorRanFundCommandEventData{}
// require.NoError(t, ag_binary.NewBorshDecoder(buf.Bytes()).Decode(&dst), "2")
//
// printer := spew.ConfigState{
// Indent: " ",
// DisablePointerAddresses: true,
// DisableCapacities: true,
// }
// printer.Dump(dst)
// require.NotEmpty(t, dst.Result, "result is empty .. see: https://explorer.solana.com/tx/48CL5KorgSLNmSSpS2SgZaNPsjKNkC9qoax9bTBPcZ3td57eDdiwDvQ2m1UPzxG6JcjNBqmUMJ8mEqE5eyqmDg7P?cluster=devnet")
//}
Loading