Skip to content

Commit 231e168

Browse files
rharutyunyanvbrvk
andauthored
fix: maker traits (#9)
* fix: maker traits * chore: lint * chore: remove forge std * maker traits update * update abi * chore: add Order tests/docs * Feat/taker traits (#10) * feat(PT4-566): adjust taker traits * feat(PT3-566): adjustments in taker traits * chore: rename `to` to `customReceiver` --------- Co-authored-by: Vladimir Borovik <[email protected]> * chore: deadline ix --------- Co-authored-by: Vladimir Borovik <[email protected]>
1 parent 1ce1a17 commit 231e168

File tree

24 files changed

+1369
-1345
lines changed

24 files changed

+1369
-1345
lines changed

typescript/aqua/src/abi/Aqua.abi.ts

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
11
export const AQUA_ABI = [
2-
{
3-
type: 'function',
4-
name: 'balances',
5-
inputs: [
6-
{ name: 'maker', type: 'address', internalType: 'address' },
7-
{ name: 'app', type: 'address', internalType: 'address' },
8-
{ name: 'strategyHash', type: 'bytes32', internalType: 'bytes32' },
9-
{ name: 'token', type: 'address', internalType: 'address' },
10-
],
11-
outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
12-
stateMutability: 'view',
13-
},
142
{
153
type: 'function',
164
name: 'dock',
@@ -48,6 +36,37 @@ export const AQUA_ABI = [
4836
outputs: [],
4937
stateMutability: 'nonpayable',
5038
},
39+
{
40+
type: 'function',
41+
name: 'rawBalances',
42+
inputs: [
43+
{ name: 'maker', type: 'address', internalType: 'address' },
44+
{ name: 'app', type: 'address', internalType: 'address' },
45+
{ name: 'strategyHash', type: 'bytes32', internalType: 'bytes32' },
46+
{ name: 'token', type: 'address', internalType: 'address' },
47+
],
48+
outputs: [
49+
{ name: 'balance', type: 'uint248', internalType: 'uint248' },
50+
{ name: 'tokensCount', type: 'uint8', internalType: 'uint8' },
51+
],
52+
stateMutability: 'view',
53+
},
54+
{
55+
type: 'function',
56+
name: 'safeBalances',
57+
inputs: [
58+
{ name: 'maker', type: 'address', internalType: 'address' },
59+
{ name: 'app', type: 'address', internalType: 'address' },
60+
{ name: 'strategyHash', type: 'bytes32', internalType: 'bytes32' },
61+
{ name: 'token0', type: 'address', internalType: 'address' },
62+
{ name: 'token1', type: 'address', internalType: 'address' },
63+
],
64+
outputs: [
65+
{ name: 'balance0', type: 'uint256', internalType: 'uint256' },
66+
{ name: 'balance1', type: 'uint256', internalType: 'uint256' },
67+
],
68+
stateMutability: 'view',
69+
},
5170
{
5271
type: 'function',
5372
name: 'ship',
@@ -131,6 +150,16 @@ export const AQUA_ABI = [
131150
{ name: 'token', type: 'address', internalType: 'address' },
132151
],
133152
},
153+
{
154+
type: 'error',
155+
name: 'SafeBalancesForTokenNotInActiveStrategy',
156+
inputs: [
157+
{ name: 'maker', type: 'address', internalType: 'address' },
158+
{ name: 'app', type: 'address', internalType: 'address' },
159+
{ name: 'strategyHash', type: 'bytes32', internalType: 'bytes32' },
160+
{ name: 'token', type: 'address', internalType: 'address' },
161+
],
162+
},
134163
{
135164
type: 'error',
136165
name: 'SafeCastOverflowedUintDowncast',

typescript/aqua/tests/aqua.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ describe('Aqua', () => {
2121
strategyHash: Hex,
2222
token: Address | Hex,
2323
): Promise<bigint> => {
24-
return forkNode.provider.readContract({
24+
const [balance] = await forkNode.provider.readContract({
2525
address: forkNode.addresses.aqua,
2626
abi: AQUA_ABI,
27-
functionName: 'balances',
27+
functionName: 'rawBalances',
2828
args: [maker.toString() as Hex, app.toString() as Hex, strategyHash, token.toString() as Hex],
2929
})
30+
31+
return balance
3032
}
3133

3234
beforeAll(async () => {

typescript/sdk-core/src/domains/hex-string.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import assert from 'node:assert'
12
import { assertHexString } from '../validators/should-be-hex-string'
23
import type { Hex } from '../types'
34

@@ -8,6 +9,7 @@ export class HexString {
89

910
constructor(hex: string, name = '') {
1011
assertHexString(hex, `hexString ${name}`)
12+
assert(hex.length % 2 === 0, 'Hex string must have an even length')
1113

1214
this.hexString = hex
1315
}
@@ -36,6 +38,22 @@ export class HexString {
3638
return this.hexString === '0x'
3739
}
3840

41+
concat(other: HexString): HexString {
42+
return new HexString(this.hexString + other.hexString.slice(2))
43+
}
44+
45+
bytesCount(): number {
46+
return (this.hexString.length - 2) / 2
47+
}
48+
49+
sliceBytes(start: number, end?: number): HexString {
50+
return new HexString('0x' + this.hexString.slice(start * 2 + 2, end ? end * 2 + 2 : undefined))
51+
}
52+
53+
equal(other: HexString): boolean {
54+
return this.hexString === other.hexString
55+
}
56+
3957
toString(): Hex {
4058
return this.hexString
4159
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { HexString } from './hex-string'
22
export { AddressHalf } from './address-half'
33
export { Address } from './address'
4+
export { Interaction } from './interaction'
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { BytesIter, isHexBytes } from '@1inch/byte-utils'
2+
import assert from 'assert'
3+
import { Address } from './address'
4+
import { HexString } from './hex-string'
5+
6+
export class Interaction {
7+
constructor(
8+
public readonly target: Address,
9+
public readonly data: HexString,
10+
) {
11+
assert(isHexBytes(data.toString()), 'Interaction data must be valid hex bytes')
12+
}
13+
14+
/**
15+
* Create `Interaction` from bytes
16+
*
17+
* @param First 20 bytes are target, then data
18+
*/
19+
public static decode(bytes: HexString): Interaction {
20+
const iter = BytesIter.HexString(bytes.toString())
21+
22+
return new Interaction(new Address(iter.nextUint160()), new HexString(iter.rest()))
23+
}
24+
25+
/**
26+
* First 20 bytes are target, then data
27+
*/
28+
public encode(): HexString {
29+
return new HexString(this.target.toString() + this.data.toString().slice(2))
30+
}
31+
32+
public equal(other: Interaction): boolean {
33+
return this.target.equal(other.target) && this.data.equal(other.data)
34+
}
35+
}

0 commit comments

Comments
 (0)