Skip to content

Commit

Permalink
Merge branch 'Object-oriented-Spell-API'
Browse files Browse the repository at this point in the history
  • Loading branch information
iwankruger committed Jan 19, 2021
2 parents ebb33c5 + 54af8b0 commit baeab3f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 17 deletions.
19 changes: 17 additions & 2 deletions src/dsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,25 @@ export class DSA {
console.log('No spells casted. Add spells with `.add(...)`.')
return
}

return await vm.cast(!!params ? { ...params, spells: this } : this)
}
})()

estimateCastGas = async (params?: Omit<CastHelpers['estimateGas'], 'spells'>) => {
if (!this.data.length) {
console.log('No spells casted. Add spells with `.add(...)`.')
return
}
return await vm.castHelpers.estimateGas({spells: this, ...params})
}

encodeCastABI = async (params?: Omit<CastHelpers['encodeABI'], 'spells'>) => {
if (!this.data.length) {
console.log('No spells casted. Add spells with `.add(...)`.')
return
}
return await vm.encodeCastABI({spells: this, ...params})
}
})()
}

async cast(params: Spells | CastParams) {
Expand Down
52 changes: 37 additions & 15 deletions test/dsa.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,31 @@ test('Cast', async () => {
expect(calldata).toBeDefined()

const txHash = await dsa.cast({ spells: spells, from: process.env.PUBLIC_ADDRESS })

})

test('Object-oriented Spells', async () => {
const usdc_address = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'

const myAddr = process.env.PUBLIC_ADDRESS

const spells = dsa.Spell()

spells.add({
connector: 'basic',
method: 'withdraw',
args: [usdc_address, dsa.maxValue, myAddr, 0, 0],
})

await dsa.setAccount(Number(process.env.DSA_ID))
const calldata = await dsa.encodeCastABI(spells)
expect(calldata).toBeDefined()

const txHash = await spells.cast({ from: process.env.PUBLIC_ADDRESS })
expect(txHash).toBeDefined()

const gas = await spells.estimateCastGas({ from: process.env.PUBLIC_ADDRESS })
expect(gas).toBeDefined()
})

test('Cast with fluid api', async () => {
Expand Down Expand Up @@ -71,22 +95,20 @@ test('get transaction count', async () => {
})


test('test', async () => {
var usdc_address = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48";
await dsa.setAccount(5);
// test('test', async () => {
// var usdc_address = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48";
// await dsa.setAccount(5);

var spells = dsa.Spell();
// var spells = dsa.Spell();

spells.add({
connector: "compound",
method: "withdraw",
args: [usdc_address, dsa.maxValue, 0, 0] // withdraw all USDC
});
// spells.add({
// connector: "compound",
// method: "withdraw",
// args: [usdc_address, dsa.maxValue, 0, 0] // withdraw all USDC
// });

console.log(await dsa.encodeCastABI(spells))
console.log(await dsa.estimateCastGas({spells, from: '0x03d70891b8994feB6ccA7022B25c32be92ee3725'})) //. Error over here.
// console.log(await dsa.encodeCastABI(spells))
// console.log(await dsa.estimateCastGas({spells, from: '0x03d70891b8994feB6ccA7022B25c32be92ee3725'})) //. Error over here.

await dsa.cast(spells)

//expect(nonce).toBeDefined()
})
// await dsa.cast(spells)
// })

0 comments on commit baeab3f

Please sign in to comment.