Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/waa s integration new api #42

Merged
merged 20 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
830110d
Rename RegisterSessionPayload to WaaSPayload
BellringerQuinn Nov 20, 2023
55b7928
Send sign message intent to WaaS.
BellringerQuinn Nov 21, 2023
119c710
Removed unused class.
BellringerQuinn Nov 21, 2023
444b6b5
Setup for sending transactions using WaaS intents
BellringerQuinn Nov 21, 2023
951eea4
Put waas transaction arg parameters in alphabetical order as the API …
BellringerQuinn Nov 21, 2023
9a06a2f
Rename SendTransactionReturn to SuccessfulTransactionReturn. Added Fa…
BellringerQuinn Nov 22, 2023
755128a
Send transaction intent to WaaS. Demo sending successful transaction
BellringerQuinn Nov 22, 2023
23ff460
Handle failed transactions
BellringerQuinn Nov 23, 2023
252c027
Drop WaaS session
BellringerQuinn Nov 23, 2023
204a034
Refactor to re-use more code when sending messages to WaaS. Fix unmar…
BellringerQuinn Nov 23, 2023
2ff1037
Added DecimalNormalizer to make it easier to convert from human reada…
BellringerQuinn Nov 23, 2023
1b460d2
Send erc20 transfer using WaaS
BellringerQuinn Nov 23, 2023
f40ba6c
Send ERC721 and send multiple transaction types at once
BellringerQuinn Nov 23, 2023
d8ad331
Use adapter to generate a RawTransaction that transfers an ERC721 token
BellringerQuinn Nov 23, 2023
48e9af9
Generate multiple RawTransactions using the adapter and batch them to…
BellringerQuinn Nov 24, 2023
ee37781
Added custom json converter for DelayedEncodeData so that we can send…
BellringerQuinn Nov 24, 2023
0f0eeb6
List WaaS Sessions
BellringerQuinn Nov 27, 2023
f8e7498
Fixed canonical ordering for parameter types so that transactions go …
BellringerQuinn Nov 30, 2023
1b0577e
Remove todos that are no longer needed as they are done
BellringerQuinn Dec 1, 2023
4146249
Merge remote-tracking branch 'origin/master' into Feature/WaaSIntegra…
BellringerQuinn Dec 20, 2023
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
8,014 changes: 6,017 additions & 1,997 deletions Assets/SequenceExamples/Scenes/Demo.unity

Large diffs are not rendered by default.

22 changes: 18 additions & 4 deletions Assets/SequenceExamples/Scripts/UI/LoginPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class LoginPanel : UIPanel
private LoginPage _loginPage;
private MultifactorAuthenticationPage _mfaPage;
private LoginSuccessPage _loginSuccessPage;
private WaaSDemoPage _waasDemoPage;

protected override void Awake()
{
base.Awake();
Expand All @@ -20,6 +22,8 @@ protected override void Awake()
_connectPage = GetComponentInChildren<ConnectPage>();
_loginPage = GetComponentInChildren<LoginPage>();
_mfaPage = GetComponentInChildren<MultifactorAuthenticationPage>();

_waasDemoPage = FindObjectOfType<WaaSDemoPage>();

ILogin loginHandler = new WaaSLogin(new AWSConfig(
"us-east-2",
Expand All @@ -34,12 +38,17 @@ protected override void Awake()
public void SetupLoginHandler(ILogin loginHandler)
{
_loginPage.SetupLogin(loginHandler);
_loginPage.LoginHandler.OnMFAEmailSent += OnMFAEmailSentHandler;
_loginPage.LoginHandler.OnMFAEmailFailedToSend += OnMFAEmailFailedToSendHandler;
loginHandler.OnMFAEmailSent += OnMFAEmailSentHandler;
loginHandler.OnMFAEmailFailedToSend += OnMFAEmailFailedToSendHandler;

_mfaPage.SetupLogin(loginHandler);
_mfaPage.LoginHandler.OnLoginSuccess += OnLoginSuccessHandler;
_mfaPage.LoginHandler.OnLoginFailed += OnLoginFailedHandler;
loginHandler.OnLoginSuccess += OnLoginSuccessHandler;
loginHandler.OnLoginFailed += OnLoginFailedHandler;

if (loginHandler is WaaSLogin waaSLogin)
{
waaSLogin.OnWaaSWalletCreated += OnWaaSWalletCreatedHandler;
}
}

public void OpenTransitionPanel()
Expand Down Expand Up @@ -86,5 +95,10 @@ private static void PassDeepLinkViaLocalServer()
}
}
#endif

private void OnWaaSWalletCreatedHandler(WaaSWallet wallet)
{
_waasDemoPage.Open(wallet);
}
}
}
271 changes: 271 additions & 0 deletions Assets/SequenceExamples/Scripts/UI/WaaSDemoPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
using System;
using System.ComponentModel;
using System.Numerics;
using System.Threading.Tasks;
using Sequence.Contracts;
using Sequence.Provider;
using Sequence.Transactions;
using Sequence.Utils;
using Sequence.WaaS;
using Sequence.WaaS.Authentication;
using SequenceSDK.Ethereum.Utils;
using SequenceSDK.WaaS;
using TMPro;
using UnityEngine;
using IWallet = Sequence.Wallet.IWallet;

namespace Sequence.Demo
{
public class WaaSDemoPage : UIPage
{
[SerializeField] private TextMeshProUGUI _resultText;

private WaaSWallet _wallet;
private Address _address;
private IWallet _adapter;

public override void Open(params object[] args)
{
_wallet =
args.GetObjectOfTypeIfExists<WaaSWallet>();
if (_wallet == default)
{
throw new SystemException(
$"Invalid use. {GetType().Name} must be opened with a {typeof(WaaSWallet)} as an argument");
}
_gameObject.SetActive(true);
_animator.AnimateIn( _openAnimationDurationInSeconds);

SetAddress();

_wallet.OnSignMessageComplete += OnSignMessageComplete;
_wallet.OnSendTransactionComplete += OnSuccessfulTransaction;
_wallet.OnSendTransactionFailed += OnFailedTransaction;
_wallet.OnDropSessionComplete += OnDropSessionComplete;

CreateAdapter();
}

private async Task CreateAdapter()
{
_adapter = await WaaSToWalletAdapter.CreateAsync(_wallet);
}

private async Task SetAddress()
{
var addressReturn = await _wallet.GetWalletAddress(new GetWalletAddressArgs(0));
_address = new Address(addressReturn.address);
}

public void SignMessage()
{
_wallet.SignMessage(new SignMessageArgs(_address, Chain.Polygon, "Hello World!"));
}

private void OnSignMessageComplete(SignMessageReturn result)
{
_resultText.text = result.signature;
}

public void SendTransfer()
{
_wallet.SendTransaction(new SendTransactionArgs(
_address,
Chain.Polygon,
new SequenceSDK.WaaS.Transaction[]
{
new RawTransaction("0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f", "1")
}));
}

private void OnSuccessfulTransaction(SuccessfulTransactionReturn result)
{
_resultText.text = $"https://polygonscan.com/tx/{result.txHash}";
Debug.Log("Transaction successful: " + result.txHash);
}

private void OnFailedTransaction(FailedTransactionReturn result)
{
_resultText.text = result.error;
Debug.LogError("Transaction failed: " + result.error);
}

public void SendFailingTransfer()
{
_wallet.SendTransaction(new SendTransactionArgs(
_address,
Chain.Polygon,
new SequenceSDK.WaaS.Transaction[]
{
new RawTransaction("0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f", "99000000000000000000")
}));
}

public void DropSession()
{
_wallet.DropThisSession();
}

private void OnDropSessionComplete(string droppedSessionId)
{
Debug.Log("Session dropped: " + droppedSessionId);
_wallet = null;
Close();
}

public void SendErc20Transfer()
{
_wallet.SendTransaction(new SendTransactionArgs(
_address, Chain.Polygon, new SequenceSDK.WaaS.Transaction[]
{
new SendERC20(
"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
"0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f",
"1"),
}));
}

public void SendErc721Transfer()
{
_wallet.SendTransaction(new SendTransactionArgs(
_address, Chain.Polygon, new SequenceSDK.WaaS.Transaction[]
{
new SendERC721(
"0xa9a6A3626993D487d2Dbda3173cf58cA1a9D9e9f",
"0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f",
"54530968763798660137294927684252503703134533114052628080002308208148824588621"),
}));
}

public void SendErc1155Transfer()
{
_wallet.SendTransaction(new SendTransactionArgs(
_address, Chain.Polygon, new SequenceSDK.WaaS.Transaction[]
{
new SendERC1155(
"0x44b3f42e2bf34f62868ff9e9dab7c2f807ba97cb",
"0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f",
new SendERC1155Values[]
{
new SendERC1155Values("86", "1")
}),
}));
}

public void SendMultipleTransferTypes()
{
_wallet.SendTransaction(new SendTransactionArgs(
_address, Chain.Polygon, new SequenceSDK.WaaS.Transaction[]
{
new RawTransaction("0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f", "1"),
new SendERC20(
"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
"0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f",
"1"),
new RawTransaction("0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f", "1"),
new SendERC721(
"0xa9a6A3626993D487d2Dbda3173cf58cA1a9D9e9f",
"0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f",
"54530968763798660137294927684252503703134533114052628080002308208148824588621"),
new RawTransaction("0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f", "1"),
}));
}

public void SendWithAdapter()
{
DoSendWithAdapter();
}

private async Task DoSendWithAdapter()
{
ERC721 nft = new ERC721("0xa9a6A3626993D487d2Dbda3173cf58cA1a9D9e9f");
var receipt = await nft.TransferFrom(_adapter.GetAddress(), "0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f",
"54530968763798660137294927684252503703134533114052628080002308208148824588621")
.SendTransactionMethodAndWaitForReceipt(_adapter, new SequenceEthClient("https://polygon-bor.publicnode.com"));
Debug.LogError($"Transaction hash: {receipt.transactionHash}");

}

public void SendMultipleWithAdapter()
{
DoSendMultipleWithAdapter();
}

private async Task DoSendMultipleWithAdapter()
{
ERC721 nft = new ERC721("0xa9a6A3626993D487d2Dbda3173cf58cA1a9D9e9f");
ERC1155 sft = new ERC1155("0x44b3f42e2bf34f62868ff9e9dab7c2f807ba97cb");
SequenceEthClient client = new SequenceEthClient("https://polygon-bor.publicnode.com");
var nftTransfer = await nft.TransferFrom(_adapter.GetAddress(),
"0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f",
"54530968763798660137294927684252503703134533114052628080002308208148824588621")(client, new ContractCall(_adapter.GetAddress()));
var sftTransfer = await sft.SafeTransferFrom(_adapter.GetAddress(),
"0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f",
"86",
1)(client, new ContractCall(_adapter.GetAddress()));

var receipt = await _adapter.SendTransactionBatchAndWaitForReceipts(client, new EthTransaction[]
{
nftTransfer, sftTransfer
});
Debug.LogError($"Transaction hash: {receipt[0].transactionHash}");

// or

// _wallet.SendTransaction(new SendTransactionArgs(
// _address, Chain.Polygon, new SequenceSDK.WaaS.Transaction[]
// {
// new RawTransaction(nftTransfer),
// new RawTransaction(sftTransfer),
// }));
}

public void SendMultipleWithAdapter2()
{
DoSendMultipleWithAdapter2();
}

private async Task DoSendMultipleWithAdapter2()
{
ERC721 nft = new ERC721("0xa9a6A3626993D487d2Dbda3173cf58cA1a9D9e9f");
ERC1155 sft = new ERC1155("0x44b3f42e2bf34f62868ff9e9dab7c2f807ba97cb");
_wallet.SendTransaction(new SendTransactionArgs(
_address, Chain.Polygon, new SequenceSDK.WaaS.Transaction[]
{
new RawTransaction(nft.Contract, "transferFrom", _adapter.GetAddress().Value,
"0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f",
BigInteger.Parse("54530968763798660137294927684252503703134533114052628080002308208148824588621")),
new RawTransaction(sft.Contract, "safeTransferFrom", _adapter.GetAddress().Value,
"0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f",
86,
1, "data".ToByteArray()), // Todo figure out why data is required
}));
}

public void DelayedEncode()
{
_wallet.SendTransaction(new SendTransactionArgs(
_address, Chain.Polygon, new SequenceSDK.WaaS.Transaction[]
{
new DelayedEncode("0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359", "0", new DelayedEncodeData(
"transfer(address,uint256)",
new object[]
{
"0x9766bf76b2E3e7BCB8c61410A3fC873f1e89b43f", "1"
},
"transfer")),
}));
}

public void ListSessions()
{
_wallet.OnSessionsFound += OnSessionsListed;
_wallet.ListSessions();
}

private void OnSessionsListed(WaaSSession[] sessions)
{
_resultText.text = $"Found {sessions.Length} sessions";
}
}
}
3 changes: 3 additions & 0 deletions Assets/SequenceExamples/Scripts/UI/WaaSDemoPage.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Assets/SequenceSDK/Ethereum/Contract/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public async Task<string> Deploy(string bytecode, params object[] constructorArg
{
throw new NotImplementedException();
}

public string AssembleCallData(string functionName, params object[] functionArgs)
{
return GetData(functionName, functionArgs);
}

public CallContractFunctionTransactionCreator CallFunction(string functionName, params object[] functionArgs)
{
Expand Down
Loading