Skip to content

Commit 1c08fda

Browse files
committed
Added IDL, generated code and example.
1 parent 39487f5 commit 1c08fda

16 files changed

+455
-214
lines changed

PLACEHOLDER.md

Lines changed: 0 additions & 35 deletions
This file was deleted.

README.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,34 @@
1-
# Solnet.Template
1+
# Solnet.SequenceEnforcer
22

3-
Template repository to easily bootstrap new program implementations using Solnet.
3+
SequenceEnforcer repository with automatic code generated.
44

5-
## Instructions
5+
Solnet.SequenceEnforcer.Examples contains small exemple how to create and submit instructions.
66

7-
To quickly bootstrap a new project using the current "standard" project structure for program implementations using Solnet do the following:
7+
Note: all the code in Solnet.SequenceEnforcer is generated. For this specific case, a few optimizations could be done:
8+
* In the SequenceEnforcerProgram methods, allocate a smaller _data buffer with stackalloc (these ixs are 80 bytes for set & reset, 105+Encoding.UTF8.GetByteCount(sym) bytes for acc initialization)
9+
* ResetSequenceNumberAccounts & CheckAndSetSequenceNumberAccounts could be collapsed into single class
10+
* Removal of SequenceEnforcerClient.SendCheckAndSetSequenceNumberAsync if not used
811

9-
- Click the `Use this template` button in the repository page.
12+
# Requirements
1013

11-
- Choose the desired name for the project (i.e. `Solnet.Serum`, `Solnet.Mango`, `Solnet.Pyth`).
14+
This code was generated using net6.0, but should work as is in net5.0.
1215

13-
- Clone the newly created repository.
1416

15-
- Change every `Solnet.Template` occurrence in the repository to the desired project name:
1617

17-
- Namespaces
18-
- `Solnet.Template.Examples` already features the `IRunnableExample` and the code to get the classes which implement the interface in the assembly
19-
- Directories
20-
- SharedBuildProperties
21-
- `build.cake`
22-
23-
- Add a "logo" to the `assets` directory.
18+
# Support
2419

25-
- Remove the `README.md` file and rename `PLACEHOLDER.md` to `README.md`.
20+
Consider supporting us:
2621

27-
- As you bootstrap the project, pipelines etc, change the badges accordingly.
22+
Sol Address: **oaksGKfwkFZwCniyCF35ZVxHDPexQ3keXNTiLa7RCSp**
23+
[Mango Ref Link](https://trade.mango.markets/?ref=MangoSharp)
2824

29-
- For generic guidelines on how you should bootstrap the project itself, in order to easily maintain the codebase of a program client implementation, see:
30-
- [Solnet.Programs](https://github.com/bmresearch/Solnet/tree/master/src/Solnet.Programs)
31-
- [Solnet.Serum](https://github.com/bmresearch/Solnet.Serum)
3225

33-
- ??????
3426

35-
- Profit.
27+
## Contributors
3628

29+
* **Hugo** - *Maintainer* - [murlokito](https://github.com/murlokito) [@hoakbuilds](twitter.com/hoakbuilds)
30+
* **Tiago** - *Maintainer* - [tiago](https://github.com/tiago18c) [@qtmoses](twitter.com/qtmoses)
3731

32+
## License
3833

34+
This project is licensed under the MIT License - see the [LICENSE](https://github.com/bmresearch/Solnet.Serum/blob/master/LICENSE) file for details

SharedBuildProperties.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<Project DefaultTargets="Build"
22
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4-
<Product>Solnet.Template</Product>
4+
<Product>Solnet.SequenceEnforcer</Product>
55
<Version>0.0.1</Version>
66
<Copyright>Copyright 2021 &#169; blockmountain</Copyright>
77
<Authors>blockmountain</Authors>
88
<PublisherName>blockmountain</PublisherName>
9-
<RepositoryUrl>https://github.com/bmresearch/Solnet.Template</RepositoryUrl>
9+
<RepositoryUrl>https://github.com/bmresearch/Solnet.SequenceEnforcer</RepositoryUrl>
1010
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1111
<LangVersion>latest</LangVersion>
1212
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1313
<PackageIcon>icon.png</PackageIcon>
14-
<PackageDescription>Solnet.Template is a .Net integration library for Template.</PackageDescription>
14+
<PackageDescription>Solnet.SequenceEnforcer is a .Net integration library for SequenceEnforcer.</PackageDescription>
1515
<PackageTags>solana;solnet;sol;net5</PackageTags>
16-
<PackageReleaseNotes>https://github.com/bmresearch/Solnet.Template/releases</PackageReleaseNotes>
16+
<PackageReleaseNotes>https://github.com/bmresearch/Solnet.SequenceEnforcer/releases</PackageReleaseNotes>
1717
<RepositoryType>git</RepositoryType>
1818
</PropertyGroup>
1919

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using SequenceEnforcer;
8+
using SequenceEnforcer.Program;
9+
using Solnet.Programs;
10+
using Solnet.Rpc.Builders;
11+
using Solnet.Wallet;
12+
13+
namespace Solnet.SequenceEnforcer.Examples
14+
{
15+
public class Example
16+
{
17+
public static void Main(string[] _)
18+
{
19+
var program = new PublicKey("GDDMwNyyx8uB6zrqwBFHjLLG3TBYk2F8Az4yrQC5RzMp");
20+
21+
22+
#warning need wallet here to work
23+
var mn = "insert mnemonic here";
24+
var wallet = new Wallet.Wallet(mn);
25+
26+
27+
var rpc = Solnet.Rpc.ClientFactory.GetClient(Rpc.Cluster.MainNet);
28+
29+
//creating client to be able to fetch accounts or effortlessly create accounts
30+
var client = new SequenceEnforcerClient(rpc, null);
31+
32+
33+
34+
// PDA DERIVATION FOR SequenceEnforcer program accounts
35+
// generate PDA, the order of seeds:
36+
// 1-"sym"
37+
// 2-owner key
38+
// I guess in a market making environment, sym is the name/address of the market,
39+
// and you use one sequence state acc per market to avoid resetting multiples when a single one fails?!
40+
var sym = "SOL/USDC";
41+
PublicKey.TryFindProgramAddress(new[] { Encoding.UTF8.GetBytes(sym), wallet.Account.PublicKey.KeyBytes }, program, out var accAddress, out var bump);
42+
43+
var initAccounts = new InitializeAccounts
44+
{
45+
Authority = wallet.Account.PublicKey,
46+
SequenceAccount = accAddress,
47+
SystemProgram = SystemProgram.ProgramIdKey
48+
};
49+
50+
51+
//creates & initializes the account the sequence account
52+
var res = client.SendInitializeAsync(initAccounts, bump, sym, wallet.Account,
53+
(payload, pk) => wallet.Sign(payload)).Result;
54+
55+
var acc = client.GetSequenceAccountAsync(accAddress).Result;
56+
57+
Console.WriteLine($"Current Seq number {acc.ParsedResult.SequenceNum}");
58+
59+
// given that the sequence enforcer program utility is to enforce actual sequences in txs,
60+
// the remaining client methods are mostly useless as the instructions are useful in composed transactions instead of standalone
61+
62+
63+
//crafting ixs
64+
65+
var advanceIx = SequenceEnforcerProgram.CheckAndSetSequenceNumber(accounts: new CheckAndSetSequenceNumberAccounts()
66+
{
67+
Authority = wallet.Account.PublicKey,
68+
SequenceAccount = accAddress
69+
}, sequenceNum: 12345ul);
70+
71+
72+
var resetx = SequenceEnforcerProgram.ResetSequenceNumber(accounts: new ResetSequenceNumberAccounts()
73+
{
74+
Authority = wallet.Account.PublicKey,
75+
SequenceAccount = accAddress
76+
}, sequenceNum: 12345ul);
77+
78+
79+
var recent = rpc.GetRecentBlockHash();
80+
81+
var tx = new TransactionBuilder()
82+
.SetFeePayer(wallet.Account.PublicKey)
83+
.AddInstruction(advanceIx)
84+
.AddInstruction(MemoProgram.NewMemoV2("Composed tx with sequence control")) // imagine this is a mango place perp order ix instead
85+
.SetRecentBlockHash(recent.Result.Value.Blockhash)
86+
.Build(wallet.Account);
87+
88+
var txResult = rpc.SendTransaction(tx);
89+
90+
//next step:
91+
// still need to add error generation, so we could get & decode error message from SequenceEnforcer instructions
92+
}
93+
}
94+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<RootNamespace>Solnet.SequenceEnforcer.Examples</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\Solnet.SequenceEnforcer\Solnet.SequenceEnforcer.csproj" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Solnet.Rpc" Version="6.0.0" />
15+
<PackageReference Include="Solnet.Wallet" Version="6.0.0" />
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
21
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.6.30114.105
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.1.32210.238
54
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solnet.Template.Test", "Solnet.Template.Test\Solnet.Template.Test.csproj", "{BD4EB2AF-3BB3-4B1A-8C75-4A690B209949}"
5+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Solnet.SequenceEnforcer", "Solnet.SequenceEnforcer\Solnet.SequenceEnforcer.csproj", "{71A4300E-545E-4754-99FD-BB1CBAD40CCA}"
76
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solnet.Template", "Solnet.Template\Solnet.Template.csproj", "{71A4300E-545E-4754-99FD-BB1CBAD40CCA}"
9-
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solnet.Template.Examples", "Solnet.Template.Examples\Solnet.Template.Examples.csproj", "{9AC72DCB-8418-43C7-AFAB-9865265F2A40}"
7+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Solnet.SequenceEnforcer.Examples", "Solnet.SequenceEnforcer.Examples\Solnet.SequenceEnforcer.Examples.csproj", "{9AC72DCB-8418-43C7-AFAB-9865265F2A40}"
118
EndProject
129
Global
1310
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -18,22 +15,7 @@ Global
1815
Release|x64 = Release|x64
1916
Release|x86 = Release|x86
2017
EndGlobalSection
21-
GlobalSection(SolutionProperties) = preSolution
22-
HideSolutionNode = FALSE
23-
EndGlobalSection
2418
GlobalSection(ProjectConfigurationPlatforms) = postSolution
25-
{BD4EB2AF-3BB3-4B1A-8C75-4A690B209949}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26-
{BD4EB2AF-3BB3-4B1A-8C75-4A690B209949}.Debug|Any CPU.Build.0 = Debug|Any CPU
27-
{BD4EB2AF-3BB3-4B1A-8C75-4A690B209949}.Debug|x64.ActiveCfg = Debug|Any CPU
28-
{BD4EB2AF-3BB3-4B1A-8C75-4A690B209949}.Debug|x64.Build.0 = Debug|Any CPU
29-
{BD4EB2AF-3BB3-4B1A-8C75-4A690B209949}.Debug|x86.ActiveCfg = Debug|Any CPU
30-
{BD4EB2AF-3BB3-4B1A-8C75-4A690B209949}.Debug|x86.Build.0 = Debug|Any CPU
31-
{BD4EB2AF-3BB3-4B1A-8C75-4A690B209949}.Release|Any CPU.ActiveCfg = Release|Any CPU
32-
{BD4EB2AF-3BB3-4B1A-8C75-4A690B209949}.Release|Any CPU.Build.0 = Release|Any CPU
33-
{BD4EB2AF-3BB3-4B1A-8C75-4A690B209949}.Release|x64.ActiveCfg = Release|Any CPU
34-
{BD4EB2AF-3BB3-4B1A-8C75-4A690B209949}.Release|x64.Build.0 = Release|Any CPU
35-
{BD4EB2AF-3BB3-4B1A-8C75-4A690B209949}.Release|x86.ActiveCfg = Release|Any CPU
36-
{BD4EB2AF-3BB3-4B1A-8C75-4A690B209949}.Release|x86.Build.0 = Release|Any CPU
3719
{71A4300E-545E-4754-99FD-BB1CBAD40CCA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3820
{71A4300E-545E-4754-99FD-BB1CBAD40CCA}.Debug|Any CPU.Build.0 = Debug|Any CPU
3921
{71A4300E-545E-4754-99FD-BB1CBAD40CCA}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -59,4 +41,10 @@ Global
5941
{9AC72DCB-8418-43C7-AFAB-9865265F2A40}.Release|x86.ActiveCfg = Release|Any CPU
6042
{9AC72DCB-8418-43C7-AFAB-9865265F2A40}.Release|x86.Build.0 = Release|Any CPU
6143
EndGlobalSection
44+
GlobalSection(SolutionProperties) = preSolution
45+
HideSolutionNode = FALSE
46+
EndGlobalSection
47+
GlobalSection(ExtensibilityGlobals) = postSolution
48+
SolutionGuid = {C4DDA773-BC31-4D37-831D-4E2742A97153}
49+
EndGlobalSection
6250
EndGlobal
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"version": "0.1.0",
3+
"name": "sequence_enforcer",
4+
"instructions": [
5+
{
6+
"name": "initialize",
7+
"accounts": [
8+
{
9+
"name": "sequenceAccount",
10+
"isMut": true,
11+
"isSigner": false
12+
},
13+
{
14+
"name": "authority",
15+
"isMut": false,
16+
"isSigner": true
17+
},
18+
{
19+
"name": "systemProgram",
20+
"isMut": false,
21+
"isSigner": false
22+
}
23+
],
24+
"args": [
25+
{
26+
"name": "bump",
27+
"type": "u8"
28+
},
29+
{
30+
"name": "sym",
31+
"type": "string"
32+
}
33+
]
34+
},
35+
{
36+
"name": "resetSequenceNumber",
37+
"accounts": [
38+
{
39+
"name": "sequenceAccount",
40+
"isMut": true,
41+
"isSigner": false
42+
},
43+
{
44+
"name": "authority",
45+
"isMut": false,
46+
"isSigner": true
47+
}
48+
],
49+
"args": [
50+
{
51+
"name": "sequenceNum",
52+
"type": "u64"
53+
}
54+
]
55+
},
56+
{
57+
"name": "checkAndSetSequenceNumber",
58+
"accounts": [
59+
{
60+
"name": "sequenceAccount",
61+
"isMut": true,
62+
"isSigner": false
63+
},
64+
{
65+
"name": "authority",
66+
"isMut": false,
67+
"isSigner": true
68+
}
69+
],
70+
"args": [
71+
{
72+
"name": "sequenceNum",
73+
"type": "u64"
74+
}
75+
]
76+
}
77+
],
78+
"accounts": [
79+
{
80+
"name": "SequenceAccount",
81+
"type": {
82+
"kind": "struct",
83+
"fields": [
84+
{
85+
"name": "sequenceNum",
86+
"type": "u64"
87+
},
88+
{
89+
"name": "authority",
90+
"type": "publicKey"
91+
}
92+
]
93+
}
94+
}
95+
],
96+
"errors": [
97+
{
98+
"code": 6000,
99+
"name": "SequenceOutOfOrder",
100+
"msg": "Sequence out of order"
101+
}
102+
]
103+
}

0 commit comments

Comments
 (0)