mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Functional link deposit, borrow, payback, and withdraw
This commit is contained in:
parent
c4421a60f8
commit
0fca7d7d00
|
@ -153,7 +153,6 @@ abstract contract QiDaoResolver is Events, Helpers {
|
||||||
|
|
||||||
erc20StablecoinInterface vault = erc20StablecoinInterface(vaultAddress);
|
erc20StablecoinInterface vault = erc20StablecoinInterface(vaultAddress);
|
||||||
vault.borrowToken(_vaultId, _amt);
|
vault.borrowToken(_vaultId, _amt);
|
||||||
vault.transferVault(_vaultId, address(this));
|
|
||||||
|
|
||||||
setUint(setAmtId, _amt);
|
setUint(setAmtId, _amt);
|
||||||
setUint(getVaultId, _vaultId);
|
setUint(getVaultId, _vaultId);
|
||||||
|
|
|
@ -6,4 +6,11 @@ module.exports = {
|
||||||
"address": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
|
"address": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
|
||||||
"decimals": 18
|
"decimals": 18
|
||||||
},
|
},
|
||||||
|
"link": {
|
||||||
|
"type": "token",
|
||||||
|
"symbol": "LINK",
|
||||||
|
"name": "ChainLink Token",
|
||||||
|
"address": "0x53e0bca35ec356bd5dddfebbd1fc0fd03fabad39",
|
||||||
|
"decimals": 18
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
matic: {
|
matic: {
|
||||||
address: "0xa3fa99a148fa48d14ed51d610c367c61876997f1"
|
address: "0xa3fa99a148fa48d14ed51d610c367c61876997f1"
|
||||||
|
},
|
||||||
|
link: {
|
||||||
|
address: "0x61167073E31b1DAd85a3E531211c7B8F1E5cAE72"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ const mineTx = async (tx: any) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const tokenMapping: Record<string, any> = {
|
const tokenMapping: Record<string, any> = {
|
||||||
|
eth:{
|
||||||
usdc: {
|
usdc: {
|
||||||
impersonateSigner: "0xfcb19e6a322b27c06842a71e8c725399f049ae3a",
|
impersonateSigner: "0xfcb19e6a322b27c06842a71e8c725399f049ae3a",
|
||||||
address: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
address: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
||||||
|
@ -61,18 +62,31 @@ const tokenMapping: Record<string, any> = {
|
||||||
await mineTx(contract.transfer(address, amt));
|
await mineTx(contract.transfer(address, amt));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
polygon: {
|
||||||
|
link: {
|
||||||
|
impersonateSigner: "0x7d3a61907f6e2ef5ed901b6d9e5baf36827625af",
|
||||||
|
abi: ["function transfer(address to, uint value)"],
|
||||||
|
address: "0x53e0bca35ec356bd5dddfebbd1fc0fd03fabad39",
|
||||||
|
process: async function (owner, to, amt) {
|
||||||
|
const contract = new ethers.Contract(this.address, this.abi, owner);
|
||||||
|
await mineTx(contract.transfer(to, amt));
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function addLiquidity(tokenName: string, address: any, amt: any) {
|
export async function addLiquidity(tokenName: string, address: any, amt: any, chain: string) {
|
||||||
const [signer] = await ethers.getSigners();
|
const [signer] = await ethers.getSigners();
|
||||||
|
const _chain = chain ? chain : 'eth';
|
||||||
tokenName = tokenName.toLowerCase();
|
tokenName = tokenName.toLowerCase();
|
||||||
if (!tokenMapping[tokenName]) {
|
if (!tokenMapping[_chain][tokenName]) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Add liquidity doesn't support the following token: ${tokenName}`
|
`Add liquidity doesn't support the following token: ${tokenName}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = tokenMapping[tokenName];
|
const token = tokenMapping[_chain][tokenName];
|
||||||
|
|
||||||
const [impersonatedSigner] = await impersonateAccounts([
|
const [impersonatedSigner] = await impersonateAccounts([
|
||||||
token.impersonateSigner,
|
token.impersonateSigner,
|
||||||
|
|
|
@ -69,6 +69,9 @@ describe("QiDao", function() {
|
||||||
parseEther("10")
|
parseEther("10")
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it("Deposit LINK into DSA wallet", async function() {
|
||||||
|
await addLiquidity("link", dsaWallet0.address, parseEther("100"), "polygon")
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Main", function() {
|
describe("Main", function() {
|
||||||
|
@ -115,6 +118,49 @@ describe("QiDao", function() {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it("should create a LINK vault in QiDao and deposit LINK into that vault", async function() {
|
||||||
|
const amt = parseEther("50");
|
||||||
|
const brwAmt = parseEther("10");
|
||||||
|
const setVaultId = "13571113";
|
||||||
|
const spells = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "createVault",
|
||||||
|
args: [vaults.link.address, setVaultId],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "deposit",
|
||||||
|
args: [polygonTokens.link.address, vaults.link.address, 0, amt, setVaultId, 0, 0, 0],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "borrow",
|
||||||
|
args: [vaults.link.address, 0, brwAmt, setVaultId, 0, 0 , 0]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "payback",
|
||||||
|
args: [vaults.link.address, 0, brwAmt, setVaultId, 0, 0 , 0],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "withdraw",
|
||||||
|
args: [polygonTokens.link.address, vaults.link.address, 0, amt.mul(995).div(1000), setVaultId, 0, 0, 0],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const tx = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spells), wallet1.address);
|
||||||
|
|
||||||
|
await tx.wait();
|
||||||
|
|
||||||
|
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.eq(
|
||||||
|
parseEther("9.975")
|
||||||
|
);
|
||||||
|
});
|
||||||
// it("Should borrow and payback half DAI from Aave V2", async function() {
|
// it("Should borrow and payback half DAI from Aave V2", async function() {
|
||||||
// const amt = parseEther("100"); // 100 DAI
|
// const amt = parseEther("100"); // 100 DAI
|
||||||
// // const setId = "83478237";
|
// // const setId = "83478237";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user