-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04eb648
commit 90bdb87
Showing
9 changed files
with
295 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,6 +220,7 @@ private static bool SetFeeTo(byte[] feeTo) | |
return true; | ||
} | ||
|
||
|
||
|
||
/// <summary> | ||
/// 获取pair | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
Swap/flamingo-contract-swap/FlamingoSwapPairWhiteList/FlamingoSwapPairWhiteList.Admin.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Neo.SmartContract.Framework; | ||
using Neo.SmartContract.Framework.Services.Neo; | ||
|
||
namespace FlamingoSwapPairWhiteList | ||
{ | ||
partial class FlamingoSwapPairWhiteList | ||
{ | ||
#region Admin | ||
|
||
static readonly byte[] superAdmin = "AZaCs7GwthGy9fku2nFXtbrdKBRmrUQoFP".ToScriptHash(); | ||
const string AdminKey = nameof(superAdmin); | ||
|
||
|
||
/// <summary> | ||
/// 获取合约管理员 | ||
/// </summary> | ||
/// <returns></returns> | ||
public static byte[] GetAdmin() | ||
{ | ||
var admin = Storage.Get(AdminKey); | ||
return admin.Length == 20 ? admin : superAdmin; | ||
} | ||
|
||
/// <summary> | ||
/// 设置合约管理员 | ||
/// </summary> | ||
/// <param name="admin"></param> | ||
/// <returns></returns> | ||
public static bool SetAdmin(byte[] admin) | ||
{ | ||
Assert(admin.Length == 20, "NewAdmin Invalid"); | ||
Assert(Runtime.CheckWitness(GetAdmin()), "Forbidden"); | ||
Storage.Put(AdminKey, admin); | ||
return true; | ||
} | ||
|
||
|
||
|
||
#endregion | ||
|
||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
Swap/flamingo-contract-swap/FlamingoSwapPairWhiteList/FlamingoSwapPairWhiteList.Helper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Neo.SmartContract.Framework; | ||
using Neo.SmartContract.Framework.Services.Neo; | ||
|
||
namespace FlamingoSwapPairWhiteList | ||
{ | ||
partial class FlamingoSwapPairWhiteList | ||
{ | ||
/// <summary> | ||
/// 断言 | ||
/// </summary> | ||
/// <param name="condition"></param> | ||
/// <param name="message"></param> | ||
private static void Assert(bool condition, string message) | ||
{ | ||
if (!condition) | ||
{ | ||
Runtime.Notify("Fault:" + message); | ||
throw new Exception(message); | ||
} | ||
} | ||
|
||
///// <summary> | ||
///// 断言,节约gas | ||
///// </summary> | ||
///// <param name="condition"></param> | ||
///// <param name="message"></param> | ||
//[OpCode(OpCode.THROWIFNOT)] | ||
//[OpCode(OpCode.DROP)] | ||
//private static extern void Assert(bool condition, string message); | ||
|
||
|
||
[OpCode(OpCode.APPEND)] | ||
private static extern void Append<T>(T[] array, T newItem); | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
Swap/flamingo-contract-swap/FlamingoSwapPairWhiteList/FlamingoSwapPairWhiteList.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Numerics; | ||
using Neo.SmartContract.Framework; | ||
using Neo.SmartContract.Framework.Services.Neo; | ||
using Neo.SmartContract.Framework.Services.System; | ||
|
||
namespace FlamingoSwapPairWhiteList | ||
{ | ||
partial class FlamingoSwapPairWhiteList : SmartContract | ||
{ | ||
|
||
/// <summary> | ||
/// 允许向LP合约转入LP token的白名单地址 | ||
/// </summary> | ||
private const string WhiteList = "WhiteList"; | ||
|
||
|
||
#region 通知 | ||
|
||
/// <summary> | ||
/// params: routerHash | ||
/// </summary> | ||
[DisplayName("addRouter")] | ||
public static event Action<byte[]> onAddRouter; | ||
|
||
/// <summary> | ||
/// params: routerHash | ||
/// </summary> | ||
[DisplayName("removeRouter")] | ||
public static event Action<byte[]> onRemoveRouter; | ||
|
||
|
||
#endregion | ||
|
||
public static object Main(string method, object[] args) | ||
{ | ||
if (Runtime.Trigger == TriggerType.Verification) | ||
{ | ||
return Runtime.CheckWitness(GetAdmin()); | ||
} | ||
else if (Runtime.Trigger == TriggerType.Application) | ||
{ | ||
//合约调用时,等价以太坊的msg.sender | ||
//直接调用时,此处为 tx.Script.ToScriptHash(); | ||
//var msgSender = ExecutionEngine.CallingScriptHash; | ||
if (method == "checkRouter") return CheckRouterWhiteList((byte[])args[0]); | ||
if (method == "addRouter") return AddRouterWhiteList((byte[])args[0]); | ||
if (method == "removeRouter") return RemoveRouterWhiteList((byte[])args[0]); | ||
if (method == "getAllRouter") return GetAllRouterWhiteList(); | ||
if (method == "getAdmin") return GetAdmin(); | ||
if (method == "setAdmin") return SetAdmin((byte[])args[0]); | ||
} | ||
return false; | ||
} | ||
|
||
|
||
|
||
/// <summary> | ||
/// 增加router白名单,加过白名单的router才能完成burn | ||
/// </summary> | ||
/// <param name="router">Nep5 tokenA</param> | ||
/// <returns></returns> | ||
public static bool AddRouterWhiteList(byte[] router) | ||
{ | ||
Assert(Runtime.CheckWitness(GetAdmin()), "Forbidden"); | ||
Assert(router.Length == 20, "Invalid Router Address"); | ||
var key = WhiteList.AsByteArray().Concat(router); | ||
Storage.Put(key, 1); | ||
onAddRouter(router); | ||
return true; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// 移除router白名单,加过白名单的router才能完成burn | ||
/// </summary> | ||
/// <param name="router">Nep5 tokenA</param> | ||
/// <returns></returns> | ||
public static bool RemoveRouterWhiteList(byte[] router) | ||
{ | ||
Assert(Runtime.CheckWitness(GetAdmin()), "Forbidden"); | ||
Assert(router.Length == 20, "Invalid Router Address"); | ||
var key = WhiteList.AsByteArray().Concat(router); | ||
Storage.Delete(key); | ||
onRemoveRouter(router); | ||
return true; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// 检查router白名单 | ||
/// </summary> | ||
/// <param name="router">Nep5 tokenA</param> | ||
/// <returns></returns> | ||
public static bool CheckRouterWhiteList(byte[] router) | ||
{ | ||
if (router.Length != 20) | ||
{ | ||
return false; | ||
} | ||
var key = WhiteList.AsByteArray().Concat(router); | ||
var value = Storage.Get(key).AsBigInteger(); | ||
return value > 0; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// 查询router白名单 | ||
/// </summary> | ||
/// <returns></returns> | ||
public static byte[][] GetAllRouterWhiteList() | ||
{ | ||
var iterator = Storage.Find(WhiteList); | ||
var result = new byte[0][]; | ||
while (iterator.Next()) | ||
{ | ||
if (iterator.Value.AsBigInteger() > 0) | ||
{ | ||
var router = iterator.Key.AsByteArray().Last(20); | ||
Append(result, router); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Swap/flamingo-contract-swap/FlamingoSwapPairWhiteList/FlamingoSwapPairWhiteList.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Neo.SmartContract.Framework" Version="2.10.0.0" /> | ||
</ItemGroup> | ||
|
||
<Target Name="NeoBuild" AfterTargets="AfterBuild"> | ||
<Exec WorkingDirectory="$(OutputPath)" Command="neon $(AssemblyName).dll --compatible"></Exec> | ||
</Target> | ||
</Project> |
Oops, something went wrong.