Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to support scval value overhaul #93

Merged
merged 12 commits into from
Apr 3, 2023
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
47 changes: 27 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ codegen-units = 1
lto = true

[workspace.dependencies.soroban-env-common]
version = "0.0.14"
version = "0.0.15"

[workspace.dependencies.soroban-env-guest]
version = "0.0.14"
version = "0.0.15"

[workspace.dependencies.soroban-env-macros]
version = "0.0.14"
version = "0.0.15"

[workspace.dependencies.soroban-env-host]
version = "0.0.14"
version = "0.0.15"

[workspace.dependencies.soroban-native-sdk-macros]
version = "0.0.14"
version = "0.0.15"

[workspace.dependencies.soroban-spec]
version = "0.6.0"
version = "0.7.0"

[workspace.dependencies.soroban-sdk]
version = "0.6.0"
version = "0.7.0"

[workspace.dependencies.soroban-sdk-macros]
version = "0.6.0"
version = "0.7.0"

[workspace.dependencies.stellar-xdr]
version = "0.0.14"
version = "0.0.15"
1 change: 0 additions & 1 deletion components/molecules/deposits/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react'
import * as SorobanClient from 'soroban-client'
import styles from './style.module.css'
import { Utils } from '../../../shared/utils'
import BigNumber from 'bignumber.js'
import { Spacer } from '../../atoms/spacer'
import * as convert from '../../../convert'
import { Constants } from '../../../shared/constants'
Expand Down
16 changes: 1 addition & 15 deletions components/organisms/pledge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ const Pledge: FunctionComponent = () => {
sorobanContext
})

let started = useContractValue({
contractId: Constants.CrowdfundId,
method: 'started',
sorobanContext
})

let targetAmountXdr = useContractValue({
contractId: Constants.CrowdfundId,
method: 'target',
Expand All @@ -84,19 +78,11 @@ const Pledge: FunctionComponent = () => {
deadline.result &&
new Date(
convert.xdrUint64ToNumber(
deadline.result.obj()?.u64() ?? xdr.Int64.fromString('0')
deadline.result.u64() ?? xdr.Int64.fromString('0')
) * 1000
)
const targetAmount = convert.scvalToBigNumber(targetAmountXdr.result)

const startedDate =
started.result &&
new Date(
convert.xdrUint64ToNumber(
started.result.obj()?.u64() ?? xdr.Int64.fromString('0')
) * 1000
)

const isLoading = (): boolean | undefined => {
return (
token.balance.loading ||
Expand Down
Binary file modified contracts/token/soroban_token_spec.wasm
Binary file not shown.
59 changes: 27 additions & 32 deletions convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,37 @@ export function scvalToBigNumber(scval: SorobanClient.xdr.ScVal | undefined): Bi
case undefined: {
return BigNumber(0);
}
case xdr.ScValType.scvU63(): {
const {high, low} = scval.u63();
return bigNumberFromBytes(false, high, low);
}
case xdr.ScValType.scvU32(): {
return BigNumber(scval.u32());
}
case xdr.ScValType.scvI32(): {
return BigNumber(scval.i32());
}
case xdr.ScValType.scvObject(): {
let obj = scval.obj()!;
switch (obj.switch()) {
case xdr.ScObjectType.scoU64(): {
const {high, low} = obj.u64();
return bigNumberFromBytes(false, high, low);
}
case xdr.ScObjectType.scoI64(): {
const {high, low} = obj.i64();
return bigNumberFromBytes(true, high, low);
}
case xdr.ScObjectType.scoU128(): {
const parts = obj.u128();
const a = parts.hi();
const b = parts.lo();
return bigNumberFromBytes(false, a.high, a.low, b.high, b.low);
}
case xdr.ScObjectType.scoI128(): {
const parts = obj.i128();
const a = parts.hi();
const b = parts.lo();
return bigNumberFromBytes(true, a.high, a.low, b.high, b.low);
}
default:
throw new Error(`Invalid type for scvalToBigNumber: ${obj.switch().name}`);
}
case xdr.ScValType.scvU64(): {
const {high, low} = scval.u64();
return bigNumberFromBytes(false, high, low);
}
case xdr.ScValType.scvI64(): {
const {high, low} = scval.i64();
return bigNumberFromBytes(true, high, low);
}
case xdr.ScValType.scvU128(): {
const parts = scval.u128();
const a = parts.hi();
const b = parts.lo();
return bigNumberFromBytes(false, a.high, a.low, b.high, b.low);
}
case xdr.ScValType.scvI128(): {
const parts = scval.i128();
const a = parts.hi();
const b = parts.lo();
return bigNumberFromBytes(true, a.high, a.low, b.high, b.low);
}
case xdr.ScValType.scvU256(): {
return bigNumberFromBytes(false, ...scval.u256());
}
case xdr.ScValType.scvI256(): {
return bigNumberFromBytes(true, ...scval.i256());
}
default: {
throw new Error(`Invalid type for scvalToBigNumber: ${scval?.switch().name}`);
Expand Down Expand Up @@ -96,7 +91,7 @@ export function bigNumberToI128(value: BigNumber): SorobanClient.xdr.ScVal {
bigNumberFromBytes(false, ...padded.slice(8, 12)).toNumber()
);

return xdr.ScVal.scvObject(xdr.ScObject.scoI128(new xdr.Int128Parts({lo, hi})));
return xdr.ScVal.scvI128(new xdr.Int128Parts({lo, hi}));
}

function bigintToBuf(bn: bigint): Buffer {
Expand Down Expand Up @@ -131,6 +126,6 @@ export function xdrUint64ToNumber(value: SorobanClient.xdr.Uint64): number {
}

export function scvalToString(value: SorobanClient.xdr.ScVal): string | undefined {
return value.obj()?.bin().toString();
return value.bytes().toString();
}

5 changes: 3 additions & 2 deletions initialize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ echo "$TOKEN_ADMIN_ADDRESS" > .soroban/token_admin_address
echo Fund token-admin account from friendbot
curl --silent -X POST "$FRIENDBOT_URL?addr=$TOKEN_ADMIN_ADDRESS" >/dev/null

ARGS="--network $NETWORK --identity token-admin"
ARGS="--network $NETWORK --source token-admin"

echo Wrap the Stellar asset
mkdir -p .soroban
Expand All @@ -85,7 +85,8 @@ soroban contract invoke \
$ARGS \
--wasm target/wasm32-unknown-unknown/release/soroban_crowdfund_contract.wasm \
--id "$CROWDFUND_ID" \
--fn initialize -- \
-- \
initialize \
--recipient "$TOKEN_ADMIN_ADDRESS" \
--deadline "$deadline" \
--target_amount "1000000000" \
Expand Down
Loading