Skip to content

Commit

Permalink
Approve collateral update
Browse files Browse the repository at this point in the history
  • Loading branch information
Rickk137 authored and noisekit committed Nov 6, 2024
1 parent 35ee509 commit bbb3ee0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ it('should be able to unlock USDC collateral after depositing', () => {
cy.connectWallet().then(({ address, privateKey }) => {
cy.task('setEthBalance', { address, balance: 100 });
cy.task('getUSDC', { address: address, amount: 1000 });
cy.task('approveCollateral', { privateKey: privateKey, symbol: 'USDC', target: 'spotMarket' });
cy.task('wrapCollateral', { privateKey, symbol: 'USDC', amount: 500 });
cy.task('approveCollateral', { privateKey: privateKey, symbol: 'sUSDC' });
cy.task('createAccount', { privateKey }).then((accountId) => {
Expand Down
12 changes: 9 additions & 3 deletions liquidity/cypress/cypress/tasks/approveCollateral.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { ethers } from 'ethers';
import { importCoreProxy } from './importCoreProxy';
import { getCollateralConfig } from './getCollateralConfig';
import { importSpotMarketProxy } from './importSpotMarketProxy';

export async function approveCollateral({ address, symbol }) {
const CoreProxy = await importCoreProxy();
export async function approveCollateral({ address, target, symbol }) {
let spender = '';
if (target === 'spotMarket') {
spender = (await importSpotMarketProxy()).address;
} else {
spender = (await importCoreProxy()).address;
}
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545');
const signer = provider.getSigner(address);
const config = await getCollateralConfig(symbol);
Expand All @@ -15,7 +21,7 @@ export async function approveCollateral({ address, symbol }) {
signer
);

const tx = await contract.approve(CoreProxy.address, ethers.constants.MaxUint256);
const tx = await contract.approve(spender, ethers.constants.MaxUint256);
await tx.wait();
return null;
}
2 changes: 1 addition & 1 deletion liquidity/cypress/cypress/tasks/getCollateralConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export async function getCollateralConfig(symbol) {
const collateralConfigs = await importCollateralTokens();
for (const config of collateralConfigs) {
try {
if (config.symbol === symbol && config.depositingEnabled) {
if (config.symbol === symbol) {
return config;
}
} catch (e) {
Expand Down
9 changes: 0 additions & 9 deletions liquidity/cypress/cypress/tasks/wrapCollateral.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ export async function wrapCollateral({ privateKey, symbol, amount }) {
config: config.name,
});

const contract = new ethers.Contract(
config.token.address,
['function approve(address spender, uint256 amount) returns (bool)'],
wallet
);

const tx = await contract.approve(spotMarketProxy.address, ethers.constants.MaxUint256);
await tx.wait();

console.log('wrap token', {
amount,
token: config.token.symbol,
Expand Down

0 comments on commit bbb3ee0

Please sign in to comment.