Skip to content

Commit

Permalink
Changes to allow devnet usage, MarketManager defaults to mainnet (#68)
Browse files Browse the repository at this point in the history
* Changes to allow devnet usage, MarketManager defaults to mainnet

* Change test to use serum program instance instead of static class
  • Loading branch information
hoakbuilds authored Jan 31, 2022
1 parent 5827fe5 commit eba508b
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 70 deletions.
2 changes: 1 addition & 1 deletion SharedBuildProperties.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Product>Solnet.Serum</Product>
<Version>1.1.1</Version>
<Version>1.2.0</Version>
<Copyright>Copyright 2021 &#169; Solnet</Copyright>
<Authors>blockmountain</Authors>
<PublisherName>blockmountain</PublisherName>
Expand Down
14 changes: 8 additions & 6 deletions Solnet.Serum.Examples/CloseOpenOrdersExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ public class CloseOpenOrdersExample : IRunnableExample
private readonly IMarketManager _marketManager;
private readonly Wallet.Wallet _wallet;
private readonly SolanaKeyStoreService _keyStore;
private readonly SerumProgram _serum;

public CloseOpenOrdersExample()
{
Console.WriteLine($"Initializing {ToString()}");
// init stuff
_keyStore = new SolanaKeyStoreService();
_serum = SerumProgram.CreateMainNet();

// get the wallet
_wallet = _keyStore.RestoreKeystoreFromFile("/path/to/wallet.json");
Expand Down Expand Up @@ -74,7 +76,7 @@ public async Task CloseAllOpenOrders()
new MemCmp { Offset = 45, Bytes = _wallet.Account.PublicKey }
};
RequestResult<List<AccountKeyPair>> accounts = await
_serumClient.RpcClient.GetProgramAccountsAsync(SerumProgram.ProgramIdKey,
_serumClient.RpcClient.GetProgramAccountsAsync(SerumProgram.MainNetProgramIdKeyV3,
dataSize: OpenOrdersAccount.Layout.SpanLength, memCmpList: filters);

Console.WriteLine($"Found {accounts.Result.Count} open orders account for market {_marketAddress}");
Expand All @@ -88,13 +90,13 @@ public async Task CloseAllOpenOrders()
var txBytes = new TransactionBuilder()
.SetFeePayer(_wallet.Account)
.SetRecentBlockHash(blockhash.Result.Value.Blockhash)
.AddInstruction(SerumProgram.SettleFunds(
.AddInstruction(_serum.SettleFunds(
_marketManager.Market,
new (openOrdersAccount.PublicKey),
_wallet.Account,
_marketManager.BaseTokenAccountAddress,
_marketManager.QuoteTokenAccountAddress))
.AddInstruction(SerumProgram.CloseOpenOrders(
.AddInstruction(_serum.CloseOpenOrders(
new (openOrdersAccount.PublicKey),
_wallet.Account,
_wallet.Account,
Expand Down Expand Up @@ -125,8 +127,8 @@ public async Task CreateOpenOrders()
openOrdersAccount,
rentExemption.Result,
OpenOrdersAccount.Layout.SpanLength,
SerumProgram.ProgramIdKey))
.AddInstruction(SerumProgram.InitOpenOrders(
_serum.ProgramIdKey))
.AddInstruction(_serum.InitOpenOrders(
openOrdersAccount,
_wallet.Account,
_marketAddress))
Expand Down Expand Up @@ -167,7 +169,7 @@ public async void Run()
var txBytes = new TransactionBuilder()
.SetFeePayer(_wallet.Account)
.SetRecentBlockHash(blockhash.Result.Value.Blockhash)
.AddInstruction(SerumProgram.CloseOpenOrders(
.AddInstruction(_serum.CloseOpenOrders(
_marketManager.OpenOrdersAddress, _wallet.Account, _wallet.Account, _marketAddress))
.CompileMessage();

Expand Down
2 changes: 1 addition & 1 deletion Solnet.Serum.Examples/ExampleExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ExampleExplorer
{
public static void Main(string[] args)
{
InstructionDecoder.Register(SerumProgram.ProgramIdKey, SerumProgram.Decode);
InstructionDecoder.Register(SerumProgram.MainNetProgramIdKeyV3, SerumProgram.Decode);
List<Type> examples = Assembly.GetEntryAssembly()?.GetExportedTypes().Where(t => t.IsAssignableTo(typeof(IRunnableExample))).ToList();
if (examples == null)
return;
Expand Down
2 changes: 1 addition & 1 deletion Solnet.Serum.Examples/FindOpenOrdersAccounts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void Run()
new MemCmp{ Offset = 45, Bytes = OwnerAddress }
};
RequestResult<List<AccountKeyPair>> accounts =
RpcClient.GetProgramAccounts(SerumProgram.ProgramIdKey, dataSize: OpenOrdersAccount.Layout.SpanLength, memCmpList: filters);
RpcClient.GetProgramAccounts(SerumProgram.MainNetProgramIdKeyV3, dataSize: OpenOrdersAccount.Layout.SpanLength, memCmpList: filters);

/* Print all of the found open orders accounts */
foreach (AccountKeyPair account in accounts.Result)
Expand Down
6 changes: 4 additions & 2 deletions Solnet.Serum.Examples/MarketManagerOrdersExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class MarketManagerMultipleOrdersExample : IRunnableExample
private readonly ISerumClient _serumClient;
private readonly IMarketManager _marketManager;
private readonly Wallet.Wallet _wallet;
private readonly SerumProgram _serum;
private OrderBook _orderBook;
private List<Order> _bids;
private List<Order> _asks;
Expand All @@ -35,6 +36,7 @@ public MarketManagerMultipleOrdersExample()
Console.WriteLine($"Initializing {ToString()}");
// init stuff
SolanaKeyStoreService keyStore = new ();
_serum = SerumProgram.CreateMainNet();

// get the wallet
_wallet = keyStore.RestoreKeystoreFromFile("/path/to/wallet.json");
Expand Down Expand Up @@ -133,7 +135,7 @@ private async Task<IList<SignatureConfirmation>> NewOrdersAsync(IList<Order> ord

SignatureConfirmation sigConf = null;

TransactionInstruction settleIx = SerumProgram.SettleFunds(
TransactionInstruction settleIx = _serum.SettleFunds(
_marketManager.Market,
_marketManager.OpenOrdersAddress,
_wallet.Account,
Expand All @@ -144,7 +146,7 @@ private async Task<IList<SignatureConfirmation>> NewOrdersAsync(IList<Order> ord
{
orders[i].ConvertOrderValues(_marketManager.BaseDecimals, _marketManager.QuoteDecimals, _marketManager.Market);

TransactionInstruction txInstruction = SerumProgram.NewOrderV3(
TransactionInstruction txInstruction = _serum.NewOrderV3(
_marketManager.Market,
_marketManager.OpenOrdersAddress,
orders[i].Side == Side.Buy ?
Expand Down
2 changes: 1 addition & 1 deletion Solnet.Serum.Test/InstructionDecoderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class InstructionDecoderTest
[ClassInitialize]
public static void Setup(TestContext tc)
{
InstructionDecoder.Register(SerumProgram.ProgramIdKey, SerumProgram.Decode);
InstructionDecoder.Register(SerumProgram.MainNetProgramIdKeyV3, SerumProgram.Decode);
}

[TestMethod]
Expand Down
2 changes: 1 addition & 1 deletion Solnet.Serum.Test/MarketManagerTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected void MockGetProgramAccountsAsync(Mock<IRpcClient> rpcMock, string mark
{
rpcMock
.Setup(s => s.GetProgramAccountsAsync(
It.Is<string>(s1 => s1 == SerumProgram.ProgramIdKey),
It.Is<string>(s1 => s1 == SerumProgram.MainNetProgramIdKeyV3),
It.Is<Commitment>(c => c == commitment),
It.Is<int>(i => i == OpenOrdersAccount.Layout.SpanLength),
It.Is<List<MemCmp>>(
Expand Down
Loading

0 comments on commit eba508b

Please sign in to comment.