Skip to main content

Corn Silo Implementation

GitHub Repo​

The Corn Silo implementation is available on the following repo.

Overview​

  • Inherits: ICornSilo, UUPSUpgradeable, PausableUpgradeable, ReentrancyGuardUpgradeable, AuthNoOwner

Callable Functions​

Admin Functions​

initialize​

Sets up the Silo contract parameters and initializes the authority for access control.

function initialize(
address _authority,
address[] memory _initialApprovedTokens
) external initializer;

pause​

Pauses all deposit and bridge-related actions. Redemption remains available.

function pause() external nonReentrant requiresAuth;

unpause​

Unpauses the contract, allowing deposits and bridge-related actions to resume.

function unpause() external nonReentrant requiresAuth;

enableBridge​

Enables bridging to Corn by setting the gateway, ERC20 inbox, and Swap Facility vault. Once enabled, the bridge cannot be disabled.

function enableBridge(
address gatewayRouter,
address erc20Inbox,
address swapFacilityVault
) external nonReentrant requiresAuth;

setWithdrawalFee​

Sets a withdrawal fee within the specified basis points (BPS) range.

function setWithdrawalFee(uint256 _fee) external requiresAuth;

Deposit Functions​

deposit​

Deposits an approved token amount into the Silo for the sender, returning issued shares.

function deposit(address token, uint256 assets) external nonReentrant whenNotPaused;

depositFor​

Deposits an approved token amount for a specified recipient, returning issued shares.

function depositFor(address recipient, address token, uint256 assets) external nonReentrant whenNotPaused;

mintAndDepositBitcorn​

Mints BTCN with the specified bitcorn minter asset amount and deposits it into the Silo.

function mintAndDepositBitcorn(uint256 assets) external nonReentrant whenNotPaused;

mintAndDepositBitcornFor​

Mints BTCN with the specified bitcorn minter asset amount for a recipient and deposits it into the Silo.

function mintAndDepositBitcornFor(address recipient, uint256 assets) external nonReentrant whenNotPaused;

Withdrawal Functions​

redeemToken​

Redeems a specific token from the user’s shares in the Silo, subject to fees.

function redeemToken(address token, uint256 shares) external nonReentrant;

redeemBitcorn​

Redeems BTCN shares and returns the minter asset balance to the user.

function redeemBitcorn(uint256 shares) external nonReentrant;

redeemAll​

Redeems all deposited assets, returning the asset balances for each approved token and BTCN.

function redeemAll() external nonReentrant;

Bridge Functions​

bridgeToken​

Bridges an approved token to the Corn network, using BTCN shares to cover gas fees.

function bridgeToken(address token, address recipient, uint256 maxGas, uint256 gasPriceBid, bytes calldata data) external nonReentrant;

bridgeAllTokens​

Bridges all approved tokens for a user to the Corn network in one transaction.

function bridgeAllTokens(address recipient, uint256 cost, uint256 maxGas, uint256 gasPriceBid, bytes calldata data) external nonReentrant;

bridgeBitcorn​

Bridges BTCN to the Corn network, using BTCN shares to cover gas fees.

function bridgeBitcorn(address recipient, uint256 cost, uint256 maxGas, uint256 gasPriceBid) external nonReentrant;

View Functions​

sharesOf​

Returns the balance of shares for a user and token.

function sharesOf(address user, address token) external view returns (uint256);

fromAssetDecimalsTo18Decimals​

Converts the asset amount from minter asset decimals to 18 decimals.

function fromAssetDecimalsTo18Decimals(uint256 amount) public view returns (uint256);

from18DecimalsToAssetDecimals​

Converts an 18-decimal amount to the minter asset’s decimals.

function from18DecimalsToAssetDecimals(uint256 amountIn18Decimals) public view returns (uint256);

getGatewayRouter​

Returns the address of the gateway router once set.

function getGatewayRouter() public view returns (IGatewayRouter gatewayRouter);

getERC20Inbox​

Returns the address of the ERC20 inbox once set.

function getERC20Inbox() public view returns (IERC20Inbox erc20Inbox);

getSwapFacilityVault​

Returns the address of the swap facility vault.

function getSwapFacilityVault() external view returns (address);

getApprovedTokens​

Returns a list of approved tokens.

function getApprovedTokens() public view returns (address[] memory);

Constants​

  • MAX_WITHDRAWAL_FEE_BPS: Maximum allowable withdrawal fee in basis points (currently 0).
  • BPS_DIVISOR: Constant divisor for basis points (10,000).
  • ONE_SATOSHI_OF_BITCOIN_SHARES: One satoshi in 18 decimals, for precise share management.