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

Add Collateral Swap Extension #29

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/Extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,34 @@ export const extensions: Extension[] = [
supportedMarkets: {
'1_USDC_0xc3d688B66703497DAA19211EEdff47f25384cdc3': null
}
},
{
id: 'collateral_swap',
name: 'Collateral Swap',
description: 'Enables swapping collateral on open loan positions without the need to repay the loan, in a single transaction',
developer: 'Wido Labs',
links: {
github: 'https://github.com/widolabs/compound-collateral-extension-ui',
website: 'https://www.joinwido.com/'
},
permissions: {
sign: '*',
trx: [
{
contract: '$operator',
abi: 'swapCollateral((address,uint256),(address,uint256),((uint8,bytes32,bytes32),(uint8,bytes32,bytes32)),(address,address,bytes),address)',
params: '*'
}
]
Comment on lines +70 to +76
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevincheng96 @hayesgm @mykelp I have added the required permission for the app to execute the transaction. Could you verify that it looks fine? I am most interested in the contract: '$operator' line, since I'm not sure what the "$operator" placeholder is replaced with.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the trx object does look ok to me. $operator is meant to signal your smart contract and you do look to have it specified correctly. What error are you currently getting?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@torreyatcitty thanks, with this changes it should work fine then.

Currently the issue is that the deployed version didn't include the trx permissions, so it's failing at the time of actually executing the transaction.

On the embedded sandbox it works fine, with or without the permissions, but once deployed it gets blocked without them.

Being this correct, I think next step would be to re-deploy so it takes the right permissions on the prod app?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah i see, yes the current version on prod does not have the trx permission. Will share an updated test build with the newer permission.

},
source: {
url: "https://ipfs.fleek.co/ipfs/QmcEEQekV9Vz4oN519uBsPLqjXUs7YathsvGvjNtbC3Y88/embedded.html"
},
supportedMarkets: {
'1_USDC_0xc3d688B66703497DAA19211EEdff47f25384cdc3': '0xaAA9f2FeE419977804eBD06F6E121f76FbcE8498',
'1_ETH_0xA17581A9E3356d9A858b789D68B4d866e593aE94': '0xaAA9f2FeE419977804eBD06F6E121f76FbcE8498',
'137_USDC_0xF25212E676D1F7F89Cd72fFEe66158f541246445': '0x17000CdCCCFf2D0B2d8958BA40c751Fa9b4BE089',
'42161_USDC.e_0xA5EDBDD9646f8dFF606d7448e414884C7d905dCA': '0x74436167012475749168f33324e84990C8013647'
}
}
];
14 changes: 14 additions & 0 deletions src/Permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ function isTypeParams(params: any[]): params is [ string, TypeParams ] {
}

function checkSendTransaction(params: any[], { trx }: Permissions, operator: string | null): null | string {
console.log('params', params);
console.log('trx', trx);
console.log('operator', operator);
if (trx === '*') {
return null;
} else {
Expand All @@ -105,13 +108,18 @@ function checkSendTransaction(params: any[], { trx }: Permissions, operator: str
let contract = trxPerm.contract;
if (contract === '$operator') {
if (!operator) {
console.log('Operator is null');
console.log('operator', operator);
return false;
}

contract = operator;
}

if (!strEq(contract, callParams.to)) {
console.log('Contract is not equal to callParams.to');
console.log('contract', contract);
console.log('callParams.to', callParams.to);
return false;
}
}
Expand All @@ -129,12 +137,18 @@ function checkSendTransaction(params: any[], { trx }: Permissions, operator: str
}
let func = Object.values(iface.functions)[0];
if (!strEq(callParams.data.slice(0, 10), iface.getSighash(func.name))) {
console.log(`Mismatch. Expected: ${iface.getSighash(func.name)}, Received: ${callParams.data.slice(0, 10)}`);
console.log('callParams.data', callParams.data);
console.log('func.name', func.name);
console.log('abi', abi.toString());
return false;
}
let funcParamsEnc = callParams.data.slice(10);
if (trxPerm.params === undefined || trxPerm.params === '*') {
return true;
} else {
console.log('trxPerm.params is not equal to undefined or "*"');
console.log('trxPerm.params', trxPerm.params);
let decodedParams = iface.decodeFunctionData(func, callParams.data);
let matchesParams = trxPerm.params.every((param, index) => {
let decodedParam = decodedParams[index];
Expand Down