Skip to content

Commit

Permalink
feat: Convert indexer table to GRT type
Browse files Browse the repository at this point in the history
Signed-off-by: Anirudh <[email protected]>
  • Loading branch information
anirudh2 committed Mar 9, 2023
1 parent e0ef0e6 commit 19bd0ac
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,40 @@ function write(i::FlexTable, a::FlexTable, s::FlexTable, n::FlexTable, config::A
end
return ps
end

"""
correcttypes!(::Val{:indexer}, i::FlexTable)
Converts the string currency fields in the indexer table to be in GRT.
```julia
julia> using AllocationOpt
julia> i = flextable([
Dict(
"stakedTokens" => "1",
"delegatedTokens" => "0",
"id" => "0xa",
"lockedTokens" => "0",
),
Dict(
"stakedTokens" => "1",
"delegatedTokens" => "0",
"id" => "0xb",
"lockedTokens" => "0",
),
Dict(
"stakedTokens" => "1",
"delegatedTokens" => "0",
"id" => "0xc",
"lockedTokens" => "0",
),
])
julia> AllocationOpt.correcttypes!(Val(:indexer), i)
```
"""
function correcttypes!(::Val{:indexer}, i::FlexTable)
i.stakedTokens = i.stakedTokens .|> togrt
i.delegatedTokens = i.delegatedTokens .|> togrt
i.lockedTokens = i.lockedTokens .|> togrt
return i
end
30 changes: 30 additions & 0 deletions test/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,34 @@
]
end
end

@testset "correcttypes!" begin
@testset "indexer" begin
i = flextable([
Dict(
"stakedTokens" => "1",
"delegatedTokens" => "0",
"id" => "0xa",
"lockedTokens" => "0",
),
Dict(
"stakedTokens" => "1",
"delegatedTokens" => "0",
"id" => "0xb",
"lockedTokens" => "0",
),
Dict(
"stakedTokens" => "1",
"delegatedTokens" => "0",
"id" => "0xc",
"lockedTokens" => "0",
),
])
AllocationOpt.correcttypes!(Val(:indexer), i)
@test i.stakedTokens == [1e-18, 1e-18, 1e-18]
@test i.delegatedTokens == [0, 0, 0]
@test i.id == ["0xa", "0xb", "0xc"]
@test i.lockedTokens == [0, 0, 0]
end
end
end

0 comments on commit 19bd0ac

Please sign in to comment.