Skip to content

Commit

Permalink
fix: different monetary policy for different pools
Browse files Browse the repository at this point in the history
  • Loading branch information
Macket committed Jun 9, 2023
1 parent 6e473ed commit 14c07a9
Show file tree
Hide file tree
Showing 5 changed files with 314 additions and 15 deletions.
299 changes: 299 additions & 0 deletions src/constants/abis/MonetaryPolicy2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,299 @@
[
{
"name": "SetAdmin",
"inputs": [
{
"name": "admin",
"type": "address",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"name": "AddPegKeeper",
"inputs": [
{
"name": "peg_keeper",
"type": "address",
"indexed": true
}
],
"anonymous": false,
"type": "event"
},
{
"name": "RemovePegKeeper",
"inputs": [
{
"name": "peg_keeper",
"type": "address",
"indexed": true
}
],
"anonymous": false,
"type": "event"
},
{
"name": "SetRate",
"inputs": [
{
"name": "rate",
"type": "uint256",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"name": "SetSigma",
"inputs": [
{
"name": "sigma",
"type": "uint256",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"name": "SetTargetDebtFraction",
"inputs": [
{
"name": "target_debt_fraction",
"type": "uint256",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"stateMutability": "nonpayable",
"type": "constructor",
"inputs": [
{
"name": "admin",
"type": "address"
},
{
"name": "price_oracle",
"type": "address"
},
{
"name": "controller_factory",
"type": "address"
},
{
"name": "peg_keepers",
"type": "address[5]"
},
{
"name": "rate",
"type": "uint256"
},
{
"name": "sigma",
"type": "uint256"
},
{
"name": "target_debt_fraction",
"type": "uint256"
}
],
"outputs": []
},
{
"stateMutability": "nonpayable",
"type": "function",
"name": "set_admin",
"inputs": [
{
"name": "admin",
"type": "address"
}
],
"outputs": []
},
{
"stateMutability": "nonpayable",
"type": "function",
"name": "add_peg_keeper",
"inputs": [
{
"name": "pk",
"type": "address"
}
],
"outputs": []
},
{
"stateMutability": "nonpayable",
"type": "function",
"name": "remove_peg_keeper",
"inputs": [
{
"name": "pk",
"type": "address"
}
],
"outputs": []
},
{
"stateMutability": "view",
"type": "function",
"name": "rate",
"inputs": [
{
"name": "_for",
"type": "address"
}
],
"outputs": [
{
"name": "",
"type": "uint256"
}
]
},
{
"stateMutability": "nonpayable",
"type": "function",
"name": "rate_write",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint256"
}
]
},
{
"stateMutability": "nonpayable",
"type": "function",
"name": "set_rate",
"inputs": [
{
"name": "rate",
"type": "uint256"
}
],
"outputs": []
},
{
"stateMutability": "nonpayable",
"type": "function",
"name": "set_sigma",
"inputs": [
{
"name": "sigma",
"type": "uint256"
}
],
"outputs": []
},
{
"stateMutability": "nonpayable",
"type": "function",
"name": "set_target_debt_fraction",
"inputs": [
{
"name": "target_debt_fraction",
"type": "uint256"
}
],
"outputs": []
},
{
"stateMutability": "view",
"type": "function",
"name": "admin",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address"
}
]
},
{
"stateMutability": "view",
"type": "function",
"name": "rate0",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint256"
}
]
},
{
"stateMutability": "view",
"type": "function",
"name": "sigma",
"inputs": [],
"outputs": [
{
"name": "",
"type": "int256"
}
]
},
{
"stateMutability": "view",
"type": "function",
"name": "target_debt_fraction",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint256"
}
]
},
{
"stateMutability": "view",
"type": "function",
"name": "peg_keepers",
"inputs": [
{
"name": "arg0",
"type": "uint256"
}
],
"outputs": [
{
"name": "",
"type": "address"
}
]
},
{
"stateMutability": "view",
"type": "function",
"name": "PRICE_ORACLE",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address"
}
]
},
{
"stateMutability": "view",
"type": "function",
"name": "CONTROLLER_FACTORY",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address"
}
]
}
]
3 changes: 3 additions & 0 deletions src/constants/llammas.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { IDict, ILlamma } from "../interfaces";
import MonetaryPolicyABI from "../constants/abis/MonetaryPolicy.json";
import { lowerCaseLlammasAddresses } from "./utils";


export const LLAMMAS: IDict<ILlamma> = lowerCaseLlammasAddresses({
sfrxeth: {
amm_address: '0x136e783846ef68C8Bd00a3369F787dF8d683a696',
controller_address: '0x8472A9A7632b173c8Cf3a86D3afec50c35548e76',
monetary_policy_address: '0xc684432FD6322c6D58b6bC5d28B18569aA0AD0A1',
collateral_address: '0xac3E018457B222d93114458476f3E3416Abbe38F',
collateral_symbol: 'sfrxETH',
collateral_decimals: 18,
min_bands: 4,
max_bands: 50,
default_bands: 10,
A: 100,
monetary_policy_abi: MonetaryPolicyABI,
},
});
11 changes: 6 additions & 5 deletions src/crvusd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Networkish } from "@ethersproject/networks";
import { Provider as MulticallProvider, Contract as MulticallContract } from 'ethcall';
import { Icrvusd, IDict, ILlamma } from "./interfaces";
import ERC20ABI from "./constants/abis/ERC20.json";
import MonetaryPolicyABI from "./constants/abis/MonetaryPolicy.json";
import MonetaryPolicy2ABI from "./constants/abis/MonetaryPolicy2.json";
import FactoryABI from "./constants/abis/Factory.json";
import controllerABI from "./constants/abis/controller.json";
import llammaABI from "./constants/abis/llamma.json";
Expand All @@ -20,7 +20,6 @@ class Crvusd implements Icrvusd {
signer: ethers.Signer | null;
signerAddress: string;
chainId: number;
monetary_policy: string;
contracts: { [index: string]: { contract: Contract, multicallContract: MulticallContract } };
feeData: { gasPrice?: number, maxFeePerGas?: number, maxPriorityFeePerGas?: number };
constantOptions: { gasLimit: number };
Expand All @@ -42,7 +41,6 @@ class Crvusd implements Icrvusd {
this.signer = null;
this.signerAddress = "";
this.chainId = 0;
this.monetary_policy = "0xc684432FD6322c6D58b6bC5d28B18569aA0AD0A1";
// @ts-ignore
this.multicallProvider = null;
this.contracts = {};
Expand Down Expand Up @@ -75,7 +73,6 @@ class Crvusd implements Icrvusd {
this.signer = null;
this.signerAddress = "";
this.chainId = 0;
this.monetary_policy = "0xc684432FD6322c6D58b6bC5d28B18569aA0AD0A1";
// @ts-ignore
this.multicallProvider = null;
this.contracts = {};
Expand Down Expand Up @@ -134,10 +131,10 @@ class Crvusd implements Icrvusd {
await this.updateFeeData();

this.setContract(this.address, ERC20ABI);
this.setContract(this.monetary_policy, MonetaryPolicyABI);
for (const llamma of Object.values(this.constants.LLAMMAS)) {
this.setContract(llamma.amm_address, llammaABI);
this.setContract(llamma.controller_address, controllerABI);
this.setContract(llamma.monetary_policy_address, llamma.monetary_policy_abi);
this.setContract(llamma.collateral_address, ERC20ABI);
}
for (const pegKeeper of this.constants.PEG_KEEPERS) {
Expand Down Expand Up @@ -181,16 +178,20 @@ class Crvusd implements Icrvusd {
const [collateral_symbol, collateral_decimals, amm_address, controller_address] = res.splice(0, 4) as [string, number, string, string];
this.setContract(amm_address, llammaABI);
this.setContract(controller_address, controllerABI);
const monetary_policy_address = await this.contracts[controller_address].contract.monetary_policy(this.constantOptions);
this.setContract(monetary_policy_address, MonetaryPolicy2ABI);
this.constants.LLAMMAS[collateral_symbol.toLowerCase()] = {
amm_address,
controller_address,
monetary_policy_address,
collateral_address,
collateral_symbol,
collateral_decimals,
min_bands: 4,
max_bands: 50,
default_bands: 10,
A: 100,
monetary_policy_abi: MonetaryPolicy2ABI,
}
}
}
Expand Down
Loading

0 comments on commit 14c07a9

Please sign in to comment.