-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
* Added support for transak onramp. Created a new assembly, Integrations (SequenceIntegrations), where this Transak integration (and future integrations) will live * Increment package version * Added a note that the transak on ramp api key can be hardcoded
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "SequenceIntegrations", | ||
"rootNamespace": "", | ||
"references": [ | ||
"GUID:f7fd4ba36aabd1d499450c174865e70b", | ||
"GUID:b4f9c0f8f363f439b9e337f79050f189" | ||
], | ||
"includePlatforms": [], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "SequenceIntegrationsTests", | ||
"rootNamespace": "", | ||
"references": [ | ||
"GUID:a67bc3d548bec4971b914c7b64c9e959", | ||
"GUID:27619889b8ba8c24980f49ee34dbb44a", | ||
"GUID:0acc523941302664db1f4e527237feb3", | ||
"GUID:f7fd4ba36aabd1d499450c174865e70b" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [ | ||
"UNITY_INCLUDE_TESTS" | ||
], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using Sequence.Integrations.Transak; | ||
|
||
namespace Sequence.Integrations.Tests.Transak | ||
{ | ||
public class TransakOnRampTests | ||
{ | ||
[Test] | ||
public async Task TestGetSupportedCountries() | ||
{ | ||
try | ||
{ | ||
SupportedCountry[] supportedCountries = await TransakOnRamp.GetSupportedCountries(); | ||
Assert.IsNotNull(supportedCountries); | ||
Assert.Greater(supportedCountries.Length, 0); | ||
} | ||
catch (Exception e) | ||
{ | ||
Assert.Fail("Expected no exception, but got: " + e.Message); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestGetTransakLink() | ||
{ | ||
TransakOnRamp onRamp = new TransakOnRamp("0xc683a014955b75F5ECF991d4502427c8fa1Aa249"); | ||
string transakOnRampLink = onRamp.GetTransakLink(); | ||
Assert.IsNotNull(transakOnRampLink); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
|
||
namespace Sequence.Integrations.Transak | ||
{ | ||
public class AddFundsSettings | ||
{ | ||
public string walletAddress; | ||
public string fiatCurrency; | ||
public string defaultFiatAmount; | ||
public string defaultCryptoCurrency; | ||
public string networks; | ||
|
||
public const string DefaultNetworks = | ||
"ethereum,mainnet,arbitrum,optimism,polygon,polygonzkevm,zksync,base,bnb,oasys,astar,avaxcchain"; | ||
public const string DefaultCryptoCurrency = "USDC"; | ||
|
||
public AddFundsSettings(string walletAddress, string fiatCurrency = "USD", string defaultFiatAmount = "50", string defaultCryptoCurrency = DefaultCryptoCurrency, string networks = DefaultNetworks) | ||
{ | ||
this.walletAddress = walletAddress; | ||
this.fiatCurrency = fiatCurrency; | ||
this.defaultFiatAmount = defaultFiatAmount; | ||
this.defaultCryptoCurrency = defaultCryptoCurrency; | ||
this.networks = networks; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
using UnityEngine; | ||
|
||
namespace Sequence.Integrations.Transak | ||
{ | ||
public class OnOffRampQueryParameters | ||
{ | ||
public const string apiKey = "5911d9ec-46b5-48fa-a755-d59a715ff0cf"; // This can be hardcoded as it is a public API key | ||
public string referrerDomain; | ||
public string walletAddress; | ||
public string fiatCurrency; | ||
public bool disableWalletAddressForm; | ||
public string defaultFiatAmount; | ||
public string defaultCryptoCurrency; | ||
public string networks; | ||
|
||
public OnOffRampQueryParameters(Address walletAddress, AddFundsSettings addFundsSettings, | ||
bool disableWalletAddressForm = true) | ||
{ | ||
this.walletAddress = walletAddress; | ||
this.referrerDomain = "sequence-unity: " + Application.productName; | ||
this.fiatCurrency = addFundsSettings.fiatCurrency; | ||
this.disableWalletAddressForm = disableWalletAddressForm; | ||
this.defaultFiatAmount = addFundsSettings.defaultFiatAmount; | ||
this.defaultCryptoCurrency = addFundsSettings.defaultCryptoCurrency; | ||
this.networks = addFundsSettings.networks; | ||
} | ||
|
||
public string AsQueryParameters() | ||
{ | ||
return $"apiKey={apiKey}&referrerDomain={referrerDomain}&walletAddress={walletAddress}&fiatCurrency={fiatCurrency}&disableWalletAddressForm={disableWalletAddressForm}&defaultFiatAmount={defaultFiatAmount}&defaultCryptoCurrency={defaultCryptoCurrency}&networks={networks}"; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
|
||
namespace Sequence.Integrations.Transak | ||
{ | ||
[Serializable] | ||
public class Partner | ||
{ | ||
public string name; | ||
public bool isCardPayment; | ||
public string currencyCode; | ||
|
||
public Partner(string name, bool isCardPayment, string currencyCode) | ||
{ | ||
this.name = name; | ||
this.isCardPayment = isCardPayment; | ||
this.currencyCode = currencyCode; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
|
||
namespace Sequence.Integrations.Transak | ||
{ | ||
[Serializable] | ||
public class SupportedCountriesResponse | ||
{ | ||
public SupportedCountry[] response; | ||
|
||
public SupportedCountriesResponse(SupportedCountry[] response) | ||
{ | ||
this.response = response; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
|
||
namespace Sequence.Integrations.Transak | ||
{ | ||
[Serializable] | ||
public class SupportedCountry | ||
{ | ||
public string alpha2; | ||
public string alpha3; | ||
public bool isAllowed; | ||
public bool isLightKycAllowed; | ||
public string name; | ||
public string[] supportedDocuments; | ||
public string currencyCode; | ||
public Partner[] partners; | ||
|
||
public SupportedCountry(string alpha2, string alpha3, bool isAllowed, bool isLightKycAllowed, string name, string[] supportedDocuments, string currencyCode, Partner[] partners) | ||
{ | ||
this.alpha2 = alpha2; | ||
this.alpha3 = alpha3; | ||
this.isAllowed = isAllowed; | ||
this.isLightKycAllowed = isLightKycAllowed; | ||
this.name = name; | ||
this.supportedDocuments = supportedDocuments; | ||
this.currencyCode = currencyCode; | ||
this.partners = partners; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.IO; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
using Sequence.Utils; | ||
using UnityEngine; | ||
using UnityEngine.Networking; | ||
|
||
namespace Sequence.Integrations.Transak | ||
{ | ||
public class TransakOnRamp | ||
{ | ||
private Address _walletAddress; | ||
|
||
public TransakOnRamp(Address walletAddress) | ||
{ | ||
this._walletAddress = walletAddress; | ||
} | ||
|
||
public TransakOnRamp(string walletAddress) | ||
{ | ||
this._walletAddress = new Address(walletAddress); | ||
} | ||
|
||
public static async Task<SupportedCountry[]> GetSupportedCountries() | ||
{ | ||
UnityWebRequest request = UnityWebRequest.Get("https://api.transak.com/api/v2/countries"); | ||
string url = request.url; | ||
string curlRequest = $"curl -X GET {url}"; | ||
try | ||
{ | ||
await request.SendWebRequest(); | ||
|
||
if (request.error != null || request.result != UnityWebRequest.Result.Success || request.responseCode < 200 || request.responseCode > 299) | ||
{ | ||
throw new Exception($"Error sending request to {url}: {request.responseCode} {request.error}"); | ||
} | ||
else | ||
{ | ||
byte[] results = request.downloadHandler.data; | ||
request.Dispose(); | ||
var responseJson = Encoding.UTF8.GetString(results); | ||
try | ||
{ | ||
SupportedCountriesResponse result = JsonConvert.DeserializeObject<SupportedCountriesResponse>(responseJson); | ||
if (result == null) | ||
{ | ||
throw new Exception("Unmarshalled response is null"); | ||
} | ||
|
||
return result.response; | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new Exception($"Error unmarshalling response from {url}: {e.Message} | given: {responseJson}"); | ||
} | ||
} | ||
} | ||
catch (HttpRequestException e) | ||
{ | ||
throw new Exception("HTTP Request failed: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.downloadHandler.data) + "\nCurl-equivalent request: " + curlRequest); | ||
} | ||
catch (FormatException e) | ||
{ | ||
throw new Exception("Invalid URL format: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.downloadHandler.data) + "\nCurl-equivalent request: " + curlRequest); | ||
} | ||
catch (FileLoadException e) | ||
{ | ||
throw new Exception("File load exception: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.downloadHandler.data) + "\nCurl-equivalent request: " + curlRequest); | ||
} | ||
catch (Exception e) { | ||
throw new Exception("An unexpected error occurred: " + e.Message + " reason: " + Encoding.UTF8.GetString(request.downloadHandler.data) + "\nCurl-equivalent request: " + curlRequest); | ||
} | ||
} | ||
|
||
public string GetTransakLink(string fiatCurrency = "USD", string defaultFiatAmount = "50", string defaultCryptoCurrency = AddFundsSettings.DefaultCryptoCurrency, string networks = AddFundsSettings.DefaultNetworks, bool disableWalletAddressForm = true) | ||
{ | ||
AddFundsSettings addFundsSettings = new AddFundsSettings(_walletAddress, fiatCurrency, defaultFiatAmount, defaultCryptoCurrency, networks); | ||
OnOffRampQueryParameters queryParameters = new OnOffRampQueryParameters(_walletAddress, addFundsSettings, disableWalletAddressForm); | ||
return $"https://global.transak.com?{queryParameters.AsQueryParameters()}"; | ||
} | ||
|
||
public void OpenTransakLink(string fiatCurrency = "USD", string defaultFiatAmount = "50", string defaultCryptoCurrency = AddFundsSettings.DefaultCryptoCurrency, string networks = AddFundsSettings.DefaultNetworks, bool disableWalletAddressForm = true) | ||
{ | ||
Application.OpenURL(GetTransakLink(fiatCurrency, defaultFiatAmount, defaultCryptoCurrency, networks, disableWalletAddressForm)); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.