Skip to content

Commit

Permalink
fix(v4-sdk): Update take command v4 (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
hensha256 authored Sep 27, 2024
1 parent 3417c81 commit 36ea0a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
22 changes: 6 additions & 16 deletions sdks/v4-sdk/src/utils/v4Planner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,33 +199,23 @@ describe('RouterPlanner', () => {

describe('addTrade', () => {
it('completes a take without a specified amount', async () => {
const routerMustCustody = true
planner.addTake(DAI, routerMustCustody)
const recipient = '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
planner.addTake(DAI, recipient)

expect(planner.actions).toEqual('0x12')
expect(planner.params[0]).toEqual(
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000'
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0000000000000000000000000000000000000000000000000000000000000000'
)
})

it('completes a take with a specified amount', async () => {
const routerMustCustody = true
const recipient = '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
const amount = BigNumber.from('8')
planner.addTake(DAI, routerMustCustody, amount)
planner.addTake(DAI, recipient, amount)

expect(planner.actions).toEqual('0x12')
expect(planner.params[0]).toEqual(
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008'
)
})

it('completes a take when router will not custody', async () => {
const routerMustCustody = false
planner.addTake(DAI, routerMustCustody)

expect(planner.actions).toEqual('0x12')
expect(planner.params[0]).toEqual(
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000'
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0000000000000000000000000000000000000000000000000000000000000008'
)
})
})
Expand Down
7 changes: 2 additions & 5 deletions sdks/v4-sdk/src/utils/v4Planner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ const ABI_DEFINITION: { [key in Actions]: string[] } = {
}

const FULL_DELTA_AMOUNT = 0
const MSG_SENDER = '0x0000000000000000000000000000000000000001'
const ADDRESS_THIS = '0x0000000000000000000000000000000000000002'

export class V4Planner {
actions: string
Expand Down Expand Up @@ -159,10 +157,9 @@ export class V4Planner {
this.addAction(Actions.SETTLE, [currencyAddress(currency), amount ?? FULL_DELTA_AMOUNT, payerIsUser])
}

addTake(currency: Currency, routerMustCustody: boolean, amount?: BigNumber): void {
const receiver = routerMustCustody ? ADDRESS_THIS : MSG_SENDER
addTake(currency: Currency, recipient: string, amount?: BigNumber): void {
const takeAmount = amount ?? FULL_DELTA_AMOUNT
this.addAction(Actions.TAKE, [currencyAddress(currency), receiver, takeAmount])
this.addAction(Actions.TAKE, [currencyAddress(currency), recipient, takeAmount])
}

finalize(): string {
Expand Down

0 comments on commit 36ea0a4

Please sign in to comment.