Skip to main content

๐Ÿ›  Smart Contracts Interaction

As a developer, you can interact with the APWine smart contracts either through the ๐Ÿ“ฆ SDK (TypeScript/JavaScript) or by building a smart contract that interacts directly on-chain (Solidity). APWine contracts are available on the APWine/apwine-smart-contracts-public repository and can be imported into your own project.

On this page, you will find examples and code snippets of basic interactions with the protocol and AMM. These can serve as building blocks to help you create your own custom interactions.

Deposit an IBT (stETH)#

import ethers from "ethers"// SDK creationimport APWineSDK from "@apwine/sdk"const provider = new ethers.providers.JsonRpcProvider("http://localhost:8545")const signer = new ethers.Wallet(PRIVATE_KEY, provider)const sdk: APWineSDK = new APWineSDK({ provider, signer, network: 1 })await sdk.ready
// Deposit stETH, getting PT and FYTconst STETH_FUTURE_VAULT = "0x35bBdC3FBdC26f7DfEe5670aF50B93c7EaBCe2c0"const depositAmount = ethers.utils.parseEther("1")await sdk.deposit(sdk.FutureVault(STETH_FUTURE_VAULT), depositAmount, {    autoApprove: true, // approve automatically if needed, requiring an additional transaction})

Please note that APWine does not take fees on your deposits. The reason why you get less PT than your deposit amount of IBT is that the FYT already has a value.

Redeem PT and FYT#

// Redeem PT and FYT, getting stETHconst STETH_FUTURE_VAULT = "0x35bBdC3FBdC26f7DfEe5670aF50B93c7EaBCe2c0"const withdrawAmount = ethers.utils.parseEther("1")await sdk.withdraw(sdk.FutureVault(STETH_FUTURE_VAULT), withdrawAmount)

Swap Underlying for PT on the AMM (pool 0)#

const STETH_AMM = "0x35bBdC3FBdC26f7DfEe5670aF50B93c7EaBCe2c0"const swapAmount = ethers.utils.parseEther("1") // amount of ETH to swap for PT
// Swap ETH for PT, resulting in a fixed rate on your ETHawait sdk.swapIn({    amm: await sdk.fetchAMM(STETH_AMM),    from: "UNDERLYING",    to: "PT",    amount: swapAmount,    },     { autoApprove: true } // Approve automatically if needed})

Swap FYT for PT on the AMM (pool 1)#

const STETH_AMM = "0x35bBdC3FBdC26f7DfEe5670aF50B93c7EaBCe2c0"const swapAmount = ethers.utils.parseEther("1") // amount of FYT to swap for PT
// Swap FYT for PT, resulting in a fixed rate on your futureawait sdk.swapIn({    amm: await sdk.fetchAMM(STETH_AMM),    from: "FYT",    to: "PT",    amount: swapAmount,    },     { autoApprove: true } // Approve automatically if needed)

Retrieve Treasury address#

pragma solidity 0.8.11;
import "apwine/protocol/contracts/interfaces/apwine/IController.sol";import "apwine/protocol/contracts/interfaces/apwine/IRegistry.sol";
contract Example {
    address internal constant CONTROLLER = 0x4bA30FA240047c17FC557b8628799068d4396790;
    function run() external {        IRegistry(IController(CONTROLLER).getRegistryAddress()).getTreasuryAddress();    }
}