Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VIP-130- PSM_USDT Deployment and VAI BaseRate => 2.72% #28

Merged
merged 13 commits into from
Aug 7, 2023
Merged
57 changes: 57 additions & 0 deletions simulations/vip-131/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { expect } from "chai";
import { BigNumber, Signer } from "ethers";
import { parseUnits } from "ethers/lib/utils";
import { ethers } from "hardhat";

const MANTISSA_ONE = parseUnits("1", 18);
const BASIS_POINT_DIVISOR = BigNumber.from(10000);
export async function swapStableForVAIAndValidate(
psm: ethers.Contract,
stableToken: ethers.Contract,
stableTokenPrice: BigNumber,
tokenSigner: Signer,
tokenHolder: string,
VAI: ethers.Contract,
feeIn: BigNumber,
tokenDecimals: number,
oneDollar: BigNumber,
) {
const stableTokenAmount = parseUnits("1000", tokenDecimals);
// calculate price of stableToken in USD, applying MIN(1$, oracle_price) thus capping stableToken maximum price to 1$
const feeInTokenPrice = stableTokenPrice.gt(oneDollar) ? oneDollar : stableTokenPrice;
const stableTokenAmountUSD = stableTokenAmount.mul(feeInTokenPrice).div(MANTISSA_ONE);
const fee = stableTokenAmountUSD.mul(feeIn).div(BASIS_POINT_DIVISOR);
const vaiToMint = stableTokenAmountUSD.sub(fee);
await stableToken.connect(tokenSigner).approve(psm.address, stableTokenAmount);
const vaiBalanceBefore = await VAI.balanceOf(tokenHolder);
const tx = await psm.connect(tokenSigner).swapStableForVAI(tokenHolder, stableTokenAmount);
const vaiBalanceAfter = await VAI.balanceOf(tokenHolder);
const vaiBalance = vaiBalanceAfter.sub(vaiBalanceBefore);
expect(vaiBalance).to.equal(vaiToMint);
await expect(tx).to.emit(psm, "StableForVAISwapped").withArgs(stableTokenAmount, vaiToMint, fee);
}

export async function swapVAIForStableAndValidate(
psm: ethers.Contract,
stableTokenPrice: BigNumber,
VAI: ethers.Contract,
vaiSigner: Signer,
feeOut: BigNumber,
stableToken: ethers.Contract,
tokenDecimals: number,
oneDollar: BigNumber,
) {
const tokenAmount = parseUnits("100", tokenDecimals); // token amount to receive
// calculate price of stableToken in USD, applying MAX(1$, oracle_price) thus making stableToken minimum price to 1$
const feeOutTokenPrice = stableTokenPrice.gt(oneDollar) ? stableTokenPrice : oneDollar;
const tokenAmountUsd: BigNumber = tokenAmount.mul(feeOutTokenPrice).div(MANTISSA_ONE); // vai to burn
const fee = tokenAmountUsd.mul(feeOut).div(BASIS_POINT_DIVISOR);
await VAI.connect(vaiSigner).approve(psm.address, tokenAmountUsd.add(fee));
const vaiSignerAddress = await vaiSigner.getAddress();
const tokenBalanceBefore = await stableToken.balanceOf(vaiSignerAddress);
const tx = await psm.connect(vaiSigner).swapVAIForStable(await vaiSigner.getAddress(), tokenAmount);
const tokenBalanceAfter = await stableToken.balanceOf(vaiSignerAddress);
const tokenBalance = tokenBalanceAfter.sub(tokenBalanceBefore);
expect(tokenBalance).to.equal(tokenAmount);
await expect(tx).to.emit(psm, "VAIForStableSwapped").withArgs(tokenAmountUsd, tokenAmount, fee);
}
126 changes: 126 additions & 0 deletions simulations/vip-131/vip-131-testnet/abi/IAccessControlManager_ABI.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
[
{ "inputs": [], "stateMutability": "nonpayable", "type": "constructor" },
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "bytes32", "name": "role", "type": "bytes32" },
{ "indexed": true, "internalType": "bytes32", "name": "previousAdminRole", "type": "bytes32" },
{ "indexed": true, "internalType": "bytes32", "name": "newAdminRole", "type": "bytes32" }
],
"name": "RoleAdminChanged",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "bytes32", "name": "role", "type": "bytes32" },
{ "indexed": true, "internalType": "address", "name": "account", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "sender", "type": "address" }
],
"name": "RoleGranted",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "bytes32", "name": "role", "type": "bytes32" },
{ "indexed": true, "internalType": "address", "name": "account", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "sender", "type": "address" }
],
"name": "RoleRevoked",
"type": "event"
},
{
"inputs": [],
"name": "DEFAULT_ADMIN_ROLE",
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "bytes32", "name": "role", "type": "bytes32" }],
"name": "getRoleAdmin",
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "contractAddress", "type": "address" },
{ "internalType": "string", "name": "functionSig", "type": "string" },
{ "internalType": "address", "name": "accountToPermit", "type": "address" }
],
"name": "giveCallPermission",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "bytes32", "name": "role", "type": "bytes32" },
{ "internalType": "address", "name": "account", "type": "address" }
],
"name": "grantRole",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "bytes32", "name": "role", "type": "bytes32" },
{ "internalType": "address", "name": "account", "type": "address" }
],
"name": "hasRole",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "account", "type": "address" },
{ "internalType": "string", "name": "functionSig", "type": "string" }
],
"name": "isAllowedToCall",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "bytes32", "name": "role", "type": "bytes32" },
{ "internalType": "address", "name": "account", "type": "address" }
],
"name": "renounceRole",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "contractAddress", "type": "address" },
{ "internalType": "string", "name": "functionSig", "type": "string" },
{ "internalType": "address", "name": "accountToRevoke", "type": "address" }
],
"name": "revokeCallPermission",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "bytes32", "name": "role", "type": "bytes32" },
{ "internalType": "address", "name": "account", "type": "address" }
],
"name": "revokeRole",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "bytes4", "name": "interfaceId", "type": "bytes4" }],
"name": "supportsInterface",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "view",
"type": "function"
}
]
Loading
Loading