Wrap / Unwrap

Wrapping:

POST /v1/TokenWrapping/Request

Submit a request to wrap a token to receipt token
Note: currently we only support wrapping from USDC to USDC-G

Request

Headers

Header
Type
Description
Content-Type
string
application/json

Request Body

Attribute
Type
Description
SourceToken
string
The gluwacoin token to be wrapped to TargetToken. Eg: USDC
TargetToken
string
The gluwacoin token the user will receive after wrapping SourceToken. Eg: USDC-G
Amount
number
The amount of Source tokens to be wrapped with decimal places if any.
ApproveTxnSignature
string
The raw transaction of approve function signed by the user private key to allow the TargetToken contract withdraw the Amount from SourceToken
Refer: see example Approve Raw Signature
MintTxnSignature
string
The raw transaction of mint function of TargetToken contract signed by the user private key to withdraw the Amount from SourceToken and receive the TargetToken
Refer: see example Ethless Mint Signature
Address
string
The user’s address which has SourceToken and is used to receive TargetToken after wrapping
IdempotentKey
string
Optional. The unique id generated by Gluwa SDK

Sample Request

1
{
2
"amount": 5,
3
"address": "0xf04349b4a760f5aed02131e0daa9bb99a1d1d1e5",
4
"ApproveTxnSignature": "0xf8aa81b4843b9aca0083086470944dbcdf9b62e891a7cec5a2568c3f4faf9e8abe2b80b844095ea7b300000000000000000000000071b7e714f87d8b46711a2533c9783d73386b828700000000000000000000000000000000000000000000000000000000004c4b401ca028538b7cb0f280681aabc730b1ee78ddf6279246ef5a8b40e3892c05a644a6f6a00373096b304110857e64cb1e37a83213f2a73a466d72c11bdd98a984d5b523b1",
5
"SourceToken": "USDC",
6
"TargetToken": "USDCG",
7
"MintTxnSignature": "0xf88981b5843b9aca00830864709471b7e714f87d8b46711a2533c9783d73386b828780a4a0712d6800000000000000000000000000000000000000000000000000000000004c4b401ba02cb8352f8692f45ae0fde67f85f6bd4097187a1439aca08e7e0cfc2b1c2a955da061eb5c18a9e7ce00ee2eb96584c1225b3b676507642aa51136493aaf0eda9f74",
8
"IdempotentKey": null
9
}
Copied!

Response

Response
202 Accepted
Example ApproveTxnSignature: Approve Raw Signature
For a token owner to approve a spender to transfer(spend) an “amount“ of his/her token from a contract on his/her behalf Spender can be a contract address or a typical Ethereum address.
Note: the amount must include the fee, which means: approved amount = amount (to transfer) + fee
1
public static string generateApproveRawSignature(string RPC_HTTPS_Endpoint, BigInteger GasLimit, BigInteger GasPrice, string ContractAddress, string ContractABI, string ApproverPrivateKey, string SpenderAddress, BigInteger amount)
2
{
3
Account approverAccount = new Account(ApproverPrivateKey);
4
Web3 web3 = new Web3(RPC_HTTPS_Endpoint);
5
6
Contract contract = web3.Eth.GetContract(ContractABI, ContractAddress);
7
8
Function contractFunction = contract.GetFunction("approve");
9
10
TransactionInput input = contractFunction.CreateTransactionInput(approverAccount.Address,
11
new HexBigInteger(GasLimit),
12
new HexBigInteger(GasPrice),
13
new HexBigInteger(BigInteger.Zero),
14
SpenderAddress,
15
amount);
16
17
HexBigInteger txCount = web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(approverAccount.Address).Result;
18
19
string signedTxn = Web3.OfflineTransactionSigner.SignTransaction(
20
ApproverPrivateKey,
21
input.To,
22
input.Value,
23
txCount.Value,
24
input.GasPrice,
25
input.Gas,
26
input.Data);
27
28
Debug.Assert(Web3.OfflineTransactionSigner.VerifyTransaction(signedTxn));
29
30
return signedTxn.EnsureHexPrefix();
31
}
Copied!
Example MintTxnSignature: Ethless Mint Signature
  • MinterAddress: the address which will receive the minted token
Note 1: only used for wrapping USCD -> USDC-G Note 2: for Mint, after minting "amount" successful, the Minter need to pay "fee" from the "amount" to the Wrapper Note 3: the prerequisite for Mint function is that the Minter need to approve USDC-G contract to spend "amount" of USDC token on behalf of him/her
1
public static string GenerateMintSignature(string USDCG_ContractAddress, int ChainId, string MinterAddress,
2
string MinterPrivateKey, BigInteger amount,
3
BigInteger fee, BigInteger nonce)
4
{
5
ABIEncode abiEncode = new ABIEncode();
6
byte[] messageHash = abiEncode.GetSha3ABIEncodedPacked(
7
new ABIValue("uint8", 2),
8
new ABIValue("uint256", ChainId),
9
new ABIValue("address", USDCG_ContractAddress),
10
new ABIValue("address", MinterAddress),
11
new ABIValue("uint256", amount),
12
new ABIValue("uint256", fee),
13
new ABIValue("uint256", nonce)
14
);
15
EthereumMessageSigner signer = new EthereumMessageSigner();
16
string signature = signer.Sign(messageHash, MinterPrivateKey);
17
return signature;
18
}
Copied!

Unwrapping:

POST /v1/TokenUnwrapping/Request

Submit a request to unwrap a token to receive another token
Note: currently we only support unwrapping from USDC-G to USDC

Request

Headers

Header
Type
Description
Content-Type
string
application/json

Request Body

Attribute
Type
Description
SourceToken
string
The gluwacoin token to be unwrapped to TargetToken. Eg: USDC-G
TargetToken
string
The gluwacoin token the user will receive after unwrapping SourceToken. Eg: USDC
Amount
number
The amount of Source tokens to be unwrapped with decimal places if any.
Note: Amount is a component to create BurnSignature
BurnSignature
string
The Burn signature signed by a user’s private key to authorize burning USDC-G to get USDC
Refer: see example Ethless Burn Signature
Nonce
number
A unique random number generated by Gluwa client
Note: Nonce is a component to create BurnSignature
Fee
number
Fee of burning retrieved from Fee API
/v1/{Currency}/fee?function=Burn
Note: Fee is a component to create BurnSignature
Address
string
The user’s address which has SourceToken and is used to receive TargetToken after unwrapping
Note: Address is a component to create BurnSignature
IdempotentKey
string
Optional. The unique id generated by Gluwa SDK

Sample Request

1
{
2
"amount": 5,
3
"address": "0xd9d097435E7CF8e663CcB26daB9C31A7F2B64ab4",
4
"SourceToken": "USDCG",
5
"TargetToken": "USDC",
6
"BurnSignature": "0x332ebd2c7bc690984fac572d1c562beb3f86da947f0f73c59521666fe619b9d73d794897cbd7cf5abe7ebec4d68cb62b59cf8466a47fe39ec7a8c32a83090a351c",
7
"Nonce": 124,
8
"Fee": 1,
9
"IdempotentKey": null
10
}
Copied!

Response

Response
202 Accepted
Example BurnSignature: Ethless Burn Signature
  • BurnerAddress: the address which will withdraw USDC-G token -> USDC token
Note 1: only used for unwrapping USCD-G -> USDC
Note 2: for Burn, after burning "amount" successful, the Burner need to pay "fee" from the "amount" to the Wrapper
Note 3: the prerequisite for Burn function is that the Burner need to approve USDC-G contract to spend "amount" of USDC token on behalf of him/her
1
public static string GenerateBurnSignature(string USDCG_ContractAddress, int ChainId, string BurnerAddress,
2
string BurnerPrivateKey, BigInteger amount,
3
BigInteger fee, BigInteger nonce)
4
{
5
ABIEncode abiEncode = new ABIEncode();
6
byte[] messageHash = abiEncode.GetSha3ABIEncodedPacked(
7
new ABIValue("uint8", 1),
8
new ABIValue("uint256", ChainId),
9
new ABIValue("address", USDCG_ContractAddress),
10
new ABIValue("address", BurnerAddress),
11
new ABIValue("uint256", amount),
12
new ABIValue("uint256", fee),
13
new ABIValue("uint256", nonce)
14
);
15
EthereumMessageSigner signer = new EthereumMessageSigner();
16
string signature = signer.Sign(messageHash, BurnerPrivateKey);
17
return signature;
18
}
Copied!