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.