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

{
  "amount": 5,
  "address": "0xf04349b4a760f5aed02131e0daa9bb99a1d1d1e5",
  "ApproveTxnSignature": "0xf8aa81b4843b9aca0083086470944dbcdf9b62e891a7cec5a2568c3f4faf9e8abe2b80b844095ea7b300000000000000000000000071b7e714f87d8b46711a2533c9783d73386b828700000000000000000000000000000000000000000000000000000000004c4b401ca028538b7cb0f280681aabc730b1ee78ddf6279246ef5a8b40e3892c05a644a6f6a00373096b304110857e64cb1e37a83213f2a73a466d72c11bdd98a984d5b523b1",
  "SourceToken": "USDC",
  "TargetToken": "USDCG",
  "MintTxnSignature": "0xf88981b5843b9aca00830864709471b7e714f87d8b46711a2533c9783d73386b828780a4a0712d6800000000000000000000000000000000000000000000000000000000004c4b401ba02cb8352f8692f45ae0fde67f85f6bd4097187a1439aca08e7e0cfc2b1c2a955da061eb5c18a9e7ce00ee2eb96584c1225b3b676507642aa51136493aaf0eda9f74", 
  "IdempotentKey": null
}

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

public static string generateApproveRawSignature(string RPC_HTTPS_Endpoint, BigInteger GasLimit, BigInteger GasPrice, string ContractAddress, string ContractABI, string ApproverPrivateKey, string SpenderAddress, BigInteger amount)
        {
            Account approverAccount = new Account(ApproverPrivateKey);
            Web3 web3 = new Web3(RPC_HTTPS_Endpoint);

            Contract contract = web3.Eth.GetContract(ContractABI, ContractAddress);

            Function contractFunction = contract.GetFunction("approve");

            TransactionInput input = contractFunction.CreateTransactionInput(approverAccount.Address,
                new HexBigInteger(GasLimit),
                new HexBigInteger(GasPrice),
                new HexBigInteger(BigInteger.Zero),
                SpenderAddress,
                amount);

            HexBigInteger txCount = web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(approverAccount.Address).Result;

            string signedTxn = Web3.OfflineTransactionSigner.SignTransaction(
                ApproverPrivateKey,
                input.To,
                input.Value,
                txCount.Value,
                input.GasPrice,
                input.Gas,
                input.Data);

            Debug.Assert(Web3.OfflineTransactionSigner.VerifyTransaction(signedTxn));

            return signedTxn.EnsureHexPrefix();
        }

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

public static string GenerateMintSignature(string USDCG_ContractAddress, int ChainId, string MinterAddress,
            string MinterPrivateKey, BigInteger amount,
            BigInteger fee, BigInteger nonce)
        {
            ABIEncode abiEncode = new ABIEncode();
            byte[] messageHash = abiEncode.GetSha3ABIEncodedPacked(
                new ABIValue("uint8", 2),
                new ABIValue("uint256", ChainId),
                new ABIValue("address", USDCG_ContractAddress),
                new ABIValue("address", MinterAddress),
                new ABIValue("uint256", amount),
                new ABIValue("uint256", fee),
                new ABIValue("uint256", nonce)
            );
            EthereumMessageSigner signer = new EthereumMessageSigner();
            string signature = signer.Sign(messageHash, MinterPrivateKey);
            return signature;
        }

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

{
  "amount": 5,
  "address": "0xd9d097435E7CF8e663CcB26daB9C31A7F2B64ab4",
  "SourceToken": "USDCG",
  "TargetToken": "USDC",
  "BurnSignature": "0x332ebd2c7bc690984fac572d1c562beb3f86da947f0f73c59521666fe619b9d73d794897cbd7cf5abe7ebec4d68cb62b59cf8466a47fe39ec7a8c32a83090a351c",
  "Nonce": 124,
  "Fee": 1,
  "IdempotentKey": null
}

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

public static string GenerateBurnSignature(string USDCG_ContractAddress, int ChainId, string BurnerAddress,
            string BurnerPrivateKey, BigInteger amount,
            BigInteger fee, BigInteger nonce)
        {
            ABIEncode abiEncode = new ABIEncode();
            byte[] messageHash = abiEncode.GetSha3ABIEncodedPacked(
                new ABIValue("uint8", 1),
                new ABIValue("uint256", ChainId),
                new ABIValue("address", USDCG_ContractAddress),
                new ABIValue("address", BurnerAddress),
                new ABIValue("uint256", amount),
                new ABIValue("uint256", fee),
                new ABIValue("uint256", nonce)
            );
            EthereumMessageSigner signer = new EthereumMessageSigner();
            string signature = signer.Sign(messageHash, BurnerPrivateKey);
            return signature;
        }

Last updated