For the complete documentation index, see llms.txt. This page is also available as Markdown.

Unwind Tokens (without dApp)

How to Withdraw Collateral Assets early using an atomic EIP-5792 capable wallet

Withdraw collateral assets from a Cork Pool before its expiry, by performing a redemption of both Cork Principal Token and Cork Swap Token, without using our dApp.

This operation, called an "Unwind Mint":

  • returns and burns shares (i.e. reduces circulating supply of cPT & cST tokens)

How to Redeem Shares via an Escrowed Unwind-Mint

You will be performing a trust-minimized escrowed operation. This is enforced by our escrow manager contract (CorkAdapter) to ensure that the end-user's desired intent is fulfilled properly with the expected outcomes. A deadline also ensures that your tokens are never stuck in an inconsistent state.

Prerequisites:


The instructions below are prepared using SAFE Wallet by SAFE Labs (safe.global), but also applies to any atomic EIP-5792 capable wallet.

Step 1: Open your Wallet's Transaction Builder

Open the SAFE Wallet's Transaction Builder using this link: https://app.safe.global/share/safe-app?appUrl=https%3A%2F%2Fapps-portal.safe.global%2Ftx-builder

Alternatively, you may navigate to the Transaction Builder by following these steps:
SAFE Wallet Connect Button
a. Press [Connect]
SAFE's Connect Wallet Modal Window
b. Select your wallet
SAFE Wallet Sidebar
c. Press the [☰] hamburger button (if you do not see the sidebar), and select [New transaction].
SAFE Wallet New Transaction Modal
d. Select [Transaction Builder].

Step 2: Add Transaction #1 – Allow spending of Principal Tokens by Escrow Manager Contract

Add the 1st transaction to allow the trust-minimized escrow manager contract (CorkAdapter) to spend your Cork Principal Tokens:

  • Enter Address: eth:<ERC20 token address of Cork Principal Token>

  • Enter ABI: Copy from here

  • To Address: <ERC20 token address of Cork Principal Token>

  • Contract Method Selector: approve

    • spender (escrow contract): 0xCCcCcCCCcccCBaD6F772a511B337d9CCc9570407

    • amount (of cPT): <wei amount of principal tokens to redeem>

By following these instructions:

1

Enter Address of Cork Principal Token to redeem

Cork Principal Token (cPT) represents a share of the Cork Pool.

Using the Cork Pool id, the cPT address and cST address may be obtained by calling CorkPoolManager.shares(poolId) using either:

  • Etherscan Website: Link

  • Blockscout Website: Link

  • Foundry Command Line:

    • cast call 0xccCCcCcCCccCfAE2Ee43F0E727A8c2969d74B9eC "shares(bytes32)(address corkPrincipalToken, address corkSwapToken)" <POOL_ID> --rpc-url https://eth.drpc.org

Input the cPT address & ABI as shown below (prefixed with eth:). If the ABI does not load automatically, copy and paste the ABI from here.

Input cPT address & ABI
2

Calculate the amount in wei

Cork Principal Tokens have 18 decimals (i.e. 10^18 precision). To calculate the right wei-amount of principal tokens, use a unit converter such as: https://converter.swiss-knife.xyz/eth or https://etherscan.io/unitconverter

Press [Copy] button of "Wei"
3

Input the Transaction #1 Details

  • To Address: <ERC20 token address of Cork Principal Token>

  • Contract Method Selector: approve

  • spender (address): 0xCCcCcCCCcccCBaD6F772a511B337d9CCc9570407

  • amount (uint256): <wei amount of cPT to redeem copied from above>

Input transaction details under Transaction Information
4

Press [+ Add new transaction]

Verify that transaction #1 has been added to the Transactions Batch.

Press [Add new transaction]

Step 3: Add Transaction #2 – Allow spending of Swap Tokens by Escrow Manager Contract

Add the 2nd transaction to allow the trust-minimized escrow manager contract (CorkAdapter) to spend your Cork Swap Tokens:

  • Enter Address: eth:<ERC20 token address of Cork Swap Token>

  • Enter ABI: Copy from here

  • To Address: <ERC20 token address of Cork Swap Token>

  • Contract Method Selector: approve

    • spender (escrow contract): 0xCCcCcCCCcccCBaD6F772a511B337d9CCc9570407

    • amount (of cST): <wei amount of swap tokens to redeem>

By following these instructions:

1

Obtain the Cork Swap Token address

Cork Swap Token (cST) is paired with their corresponding Cork Principal Token (cPT).

Using the Cork Pool id, the cPT address and cST address may be obtained by calling CorkPoolManager.shares(poolId) using either:

  • Etherscan Website: Link

  • Blockscout Website: Link

  • Foundry Command Line:

    • cast call 0xccCCcCcCCccCfAE2Ee43F0E727A8c2969d74B9eC "shares(bytes32)(address corkPrincipalToken, address corkSwapToken)" <POOL_ID> --rpc-url https://eth.drpc.org

2

Enter Address of Cork Swap Token to redeem

Input the cST address & ABI as shown below (prefixed with eth:). If the ABI does not load automatically, copy and paste the ABI from here.

Input cST address & ABI
3

Input the Transaction #2 Details

  • To Address: <ERC20 token address of Cork Swap Token>

  • Contract Method Selector: approve

  • spender (address): 0xCCcCcCCCcccCBaD6F772a511B337d9CCc9570407

  • amount (uint256): <wei amount of cST to redeem, copied from the wei amount of cPT in the previous step>

Input transaction details under Transaction Information
4

Press [+ Add new transaction]

Verify that transaction #2 has been added to the Transactions Batch.

Press [Add new transaction]

Step 4: Add Transaction #3 – Request an escrowed Unwind-Mint

Add the 3rd transaction to withdraw collateral assets from a Cork Pool by redeeming both cPT (Cork Principal Token) and cST (Cork Swap Token):

  • Enter Address: eth:0xCCcCcCCCcccCBaD6F772a511B337d9CCc9570407

  • Enter ABI: Copied from here

  • To Address: 0xCCcCcCCCcccCBaD6F772a511B337d9CCc9570407

  • Contract Method Selector: safeUnwindMint

    • params: [comma separated values as below...]

      • "<poolId>",

        • The cork pool market id

      • "<cptAndCstSharesIn>",

        • The wei amount of shares to redeem. Copied from the previous step.

      • "<ownerAddress>",

        • Your wallet address (or the address that owns the cPT and cST shares to be burned).

      • "<receiverAddress>",

        • Your wallet address (or the address to which collateral assets and any excess shares will be sent).

      • "<minCollateralAssetsOut>",

        • The minimum wei amount of collateral assets to receive from the unwind operation. From unit-converter.

      • "<deadline>"

        • The numeric deadline by which the transaction must be completed. From epoch-converter.

    • Example params:

By following these instructions:

1

Enter Address or ENS Name of CorkAdapter address

Input the CorkAdapter contract address & ABI as shown below. If the ABI does not load automatically, copy and paste the ABI from here.

Input CorkAdapter address
2

Calculate the deadline in seconds since epoch

Choose a future timestamp using an epoch-converter. We recommend setting it at least 1 hour from now to allow sufficient time for cosigning. Since the batch executes atomically, offline ERC-20 permits are unnecessary, allowing this deadline to be set as far in the future as desired. Use this timestamp as the deadline in the next step.

Input your desired duration from now

If missing, scroll to the right of the page to see the copy button:

Press [Copy] button
3

Input the Transaction #3 Details

  • To Address: 0xCCcCcCCCcccCBaD6F772a511B337d9CCc9570407

  • Contract Method Selector: safeUnwindMint

    • params: [comma separated values as below...]

      • "<poolId>",

        • The cork pool market id

      • "<cptAndCstSharesIn>",

        • The wei amount of shares to redeem. Copied from the previous step.

      • "<ownerAddress>",

        • Your wallet address (or the address that owns the cPT and cST shares to be burned).

      • "<receiverAddress>",

        • Your wallet address (or the address to which collateral assets and any excess shares will be sent).

      • "<minCollateralAssetsOut>",

        • The minimum wei amount of collateral assets to receive from the unwind operation. From unit-converter.

      • "<deadline>"

        • The numeric deadline by which the transaction must be completed. From epoch-converter.

Input transaction details under Transaction Information
4

Press [+ Add new transaction]

Verify that transaction #3 has been added to the Transactions Batch.

Press [Add new transaction]

Step 4: Create, Review & Simulate Batch

Press [Create Batch] and follow these instructions:

1

Review and Confirm batch

Make sure that you see this "Review and Confirm" screen.

Important: Enable atomic batch if asked by your EIP-5792 capable wallet. Using non-atomic batch mode can lead to lost of funds!

Ensure that there are 3 items in the Atomic Batch
2

Verify each transaction in your batch

An example of each transaction in the batch:
Ensure that "method", "spender" and "amount" is correct
Ensure that "method", "spender" and "amount" is correct
Ensure that "to", "method", and "params" are correct
3

Simulate the batch

Press [Simulate Batch] and ensure that the simulated outcomes are as expected.

4

Send Batch

Once the simulation has completed successfully, press [Send Batch].


Step 5: Sign and Execute transaction

Ask each co-signer/co-owner to follow these instructions:

1

Select the Batch in the Wallet Queue

Select the batch and open the details of each transaction within the batch.

2

Verify the Calldata of each transaction in the batch

Each cosigner copies the calldata of each transaction into a safe decoder, and verifies that the decoded data contains the correct amounts and addresses.

DO NOT CONTINUE if they do not match!

3

Approve the Batch

Each cosigner ensures that the batch's safeTxHash (or EIP-712 messageHash), displayed on their signing device (e.g. wallet hardware), matches completely before signing an approval of the batch.

4

Execute the Batch

Once the threshold of cosigners have approved the batch, one of the wallet owners/signers has to execute the transaction (using the wallet) and pay gas.


Step 6: Wait for Confirmation and Verify token balances

Once the batch transaction is confirmed, follow your wallet-specific instructions to check your collateral asset balance.

Using the Cork Pool id, the Collateral asset (CA) address and Reference asset (REF) address may be obtained by calling CorkPoolManager.assets(poolId) using either:

  • Etherscan Website: Link

  • Blockscout Website: Link

  • Foundry Command Line:

    • cast call 0xccCCcCcCCccCfAE2Ee43F0E727A8c2969d74B9eC "assets(bytes32)(address collateralAsset, address referenceAsset)" <POOL_ID> --rpc-url https://eth.drpc.org


Last updated