Skip to content
Merged
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
53 changes: 41 additions & 12 deletions typescript/aqua/src/abi/Aqua.abi.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
export const AQUA_ABI = [
{
type: 'function',
name: 'balances',
inputs: [
{ name: 'maker', type: 'address', internalType: 'address' },
{ name: 'app', type: 'address', internalType: 'address' },
{ name: 'strategyHash', type: 'bytes32', internalType: 'bytes32' },
{ name: 'token', type: 'address', internalType: 'address' },
],
outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'dock',
Expand Down Expand Up @@ -48,6 +36,37 @@ export const AQUA_ABI = [
outputs: [],
stateMutability: 'nonpayable',
},
{
type: 'function',
name: 'rawBalances',
inputs: [
{ name: 'maker', type: 'address', internalType: 'address' },
{ name: 'app', type: 'address', internalType: 'address' },
{ name: 'strategyHash', type: 'bytes32', internalType: 'bytes32' },
{ name: 'token', type: 'address', internalType: 'address' },
],
outputs: [
{ name: 'balance', type: 'uint248', internalType: 'uint248' },
{ name: 'tokensCount', type: 'uint8', internalType: 'uint8' },
],
stateMutability: 'view',
},
{
type: 'function',
name: 'safeBalances',
inputs: [
{ name: 'maker', type: 'address', internalType: 'address' },
{ name: 'app', type: 'address', internalType: 'address' },
{ name: 'strategyHash', type: 'bytes32', internalType: 'bytes32' },
{ name: 'token0', type: 'address', internalType: 'address' },
{ name: 'token1', type: 'address', internalType: 'address' },
],
outputs: [
{ name: 'balance0', type: 'uint256', internalType: 'uint256' },
{ name: 'balance1', type: 'uint256', internalType: 'uint256' },
],
stateMutability: 'view',
},
{
type: 'function',
name: 'ship',
Expand Down Expand Up @@ -131,6 +150,16 @@ export const AQUA_ABI = [
{ name: 'token', type: 'address', internalType: 'address' },
],
},
{
type: 'error',
name: 'SafeBalancesForTokenNotInActiveStrategy',
inputs: [
{ name: 'maker', type: 'address', internalType: 'address' },
{ name: 'app', type: 'address', internalType: 'address' },
{ name: 'strategyHash', type: 'bytes32', internalType: 'bytes32' },
{ name: 'token', type: 'address', internalType: 'address' },
],
},
{
type: 'error',
name: 'SafeCastOverflowedUintDowncast',
Expand Down
6 changes: 4 additions & 2 deletions typescript/aqua/tests/aqua.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ describe('Aqua', () => {
strategyHash: Hex,
token: Address | Hex,
): Promise<bigint> => {
return forkNode.provider.readContract({
const [balance] = await forkNode.provider.readContract({
address: forkNode.addresses.aqua,
abi: AQUA_ABI,
functionName: 'balances',
functionName: 'rawBalances',
args: [maker.toString() as Hex, app.toString() as Hex, strategyHash, token.toString() as Hex],
})

return balance
}

beforeAll(async () => {
Expand Down
18 changes: 18 additions & 0 deletions typescript/sdk-core/src/domains/hex-string.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import assert from 'node:assert'
import { assertHexString } from '../validators/should-be-hex-string'
import type { Hex } from '../types'

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

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

this.hexString = hex
}
Expand Down Expand Up @@ -36,6 +38,22 @@ export class HexString {
return this.hexString === '0x'
}

concat(other: HexString): HexString {
return new HexString(this.hexString + other.hexString.slice(2))
}

bytesCount(): number {
return (this.hexString.length - 2) / 2
}

sliceBytes(start: number, end?: number): HexString {
return new HexString('0x' + this.hexString.slice(start * 2 + 2, end ? end * 2 + 2 : undefined))
}

equal(other: HexString): boolean {
return this.hexString === other.hexString
}

toString(): Hex {
return this.hexString
}
Expand Down
1 change: 1 addition & 0 deletions typescript/sdk-core/src/domains/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { HexString } from './hex-string'
export { AddressHalf } from './address-half'
export { Address } from './address'
export { Interaction } from './interaction'
35 changes: 35 additions & 0 deletions typescript/sdk-core/src/domains/interaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { BytesIter, isHexBytes } from '@1inch/byte-utils'
import assert from 'assert'
import { Address } from './address'
import { HexString } from './hex-string'

export class Interaction {
constructor(
public readonly target: Address,
public readonly data: HexString,
) {
assert(isHexBytes(data.toString()), 'Interaction data must be valid hex bytes')
}

/**
* Create `Interaction` from bytes
*
* @param First 20 bytes are target, then data
*/
public static decode(bytes: HexString): Interaction {
const iter = BytesIter.HexString(bytes.toString())

return new Interaction(new Address(iter.nextUint160()), new HexString(iter.rest()))
}

/**
* First 20 bytes are target, then data
*/
public encode(): HexString {
return new HexString(this.target.toString() + this.data.toString().slice(2))
}

public equal(other: Interaction): boolean {
return this.target.equal(other.target) && this.data.equal(other.data)
}
}
Loading
Loading