-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
367 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"version": "v3.5.0", | ||
"name": "Transact", | ||
"bytecode": "01034027404e405c010100000009d353dbb7aab413c40de0b6b3a7640000a9a00013c40de0b6b3a76400002aa10002010200000009d3a248861cb413c40de0b6b3a7640000a8a00013c40de0b6b3a76400002ba10002010000000103d376c7c673a00002", | ||
"codeHash": "e69364160d369d3459e19d1b2fcaae7f0cac7059357dba5616147ea18d0c1f0e", | ||
"fieldsSig": { | ||
"names": [ | ||
"totalDeposits" | ||
], | ||
"types": [ | ||
"U256" | ||
], | ||
"isMutable": [ | ||
true | ||
] | ||
}, | ||
"eventsSig": [], | ||
"functions": [ | ||
{ | ||
"name": "deposit", | ||
"paramNames": [], | ||
"paramTypes": [], | ||
"paramIsMutable": [], | ||
"returnTypes": [] | ||
}, | ||
{ | ||
"name": "withdraw", | ||
"paramNames": [], | ||
"paramTypes": [], | ||
"paramIsMutable": [], | ||
"returnTypes": [] | ||
}, | ||
{ | ||
"name": "getTotalDeposits", | ||
"paramNames": [], | ||
"paramTypes": [], | ||
"paramIsMutable": [], | ||
"returnTypes": [ | ||
"U256" | ||
] | ||
} | ||
], | ||
"constants": [], | ||
"enums": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,234 @@ | ||
/* Autogenerated file. Do not edit manually. */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
|
||
import { | ||
Address, | ||
Contract, | ||
ContractState, | ||
TestContractResult, | ||
HexString, | ||
ContractFactory, | ||
EventSubscribeOptions, | ||
EventSubscription, | ||
CallContractParams, | ||
CallContractResult, | ||
TestContractParams, | ||
ContractEvent, | ||
subscribeContractEvent, | ||
subscribeContractEvents, | ||
testMethod, | ||
callMethod, | ||
multicallMethods, | ||
fetchContractState, | ||
ContractInstance, | ||
getContractEventsCurrentCount, | ||
TestContractParamsWithoutMaps, | ||
TestContractResultWithoutMaps, | ||
SignExecuteContractMethodParams, | ||
SignExecuteScriptTxResult, | ||
signExecuteMethod, | ||
addStdIdToFields, | ||
encodeContractFields, | ||
} from "@alephium/web3"; | ||
import { default as TransactContractJson } from "../test/Transact.ral.json"; | ||
import { getContractByCodeHash } from "./contracts"; | ||
import { | ||
AddStruct1, | ||
AddStruct2, | ||
Balances, | ||
MapValue, | ||
TokenBalance, | ||
AllStructs, | ||
} from "./types"; | ||
|
||
// Custom types for the contract | ||
export namespace TransactTypes { | ||
export type Fields = { | ||
totalDeposits: bigint; | ||
}; | ||
|
||
export type State = ContractState<Fields>; | ||
|
||
export interface CallMethodTable { | ||
deposit: { | ||
params: Omit<CallContractParams<{}>, "args">; | ||
result: CallContractResult<null>; | ||
}; | ||
withdraw: { | ||
params: Omit<CallContractParams<{}>, "args">; | ||
result: CallContractResult<null>; | ||
}; | ||
getTotalDeposits: { | ||
params: Omit<CallContractParams<{}>, "args">; | ||
result: CallContractResult<bigint>; | ||
}; | ||
} | ||
export type CallMethodParams<T extends keyof CallMethodTable> = | ||
CallMethodTable[T]["params"]; | ||
export type CallMethodResult<T extends keyof CallMethodTable> = | ||
CallMethodTable[T]["result"]; | ||
export type MultiCallParams = Partial<{ | ||
[Name in keyof CallMethodTable]: CallMethodTable[Name]["params"]; | ||
}>; | ||
export type MultiCallResults<T extends MultiCallParams> = { | ||
[MaybeName in keyof T]: MaybeName extends keyof CallMethodTable | ||
? CallMethodTable[MaybeName]["result"] | ||
: undefined; | ||
}; | ||
export type MulticallReturnType<Callss extends MultiCallParams[]> = | ||
Callss["length"] extends 1 | ||
? MultiCallResults<Callss[0]> | ||
: { [index in keyof Callss]: MultiCallResults<Callss[index]> }; | ||
|
||
export interface SignExecuteMethodTable { | ||
deposit: { | ||
params: Omit<SignExecuteContractMethodParams<{}>, "args">; | ||
result: SignExecuteScriptTxResult; | ||
}; | ||
withdraw: { | ||
params: Omit<SignExecuteContractMethodParams<{}>, "args">; | ||
result: SignExecuteScriptTxResult; | ||
}; | ||
getTotalDeposits: { | ||
params: Omit<SignExecuteContractMethodParams<{}>, "args">; | ||
result: SignExecuteScriptTxResult; | ||
}; | ||
} | ||
export type SignExecuteMethodParams<T extends keyof SignExecuteMethodTable> = | ||
SignExecuteMethodTable[T]["params"]; | ||
export type SignExecuteMethodResult<T extends keyof SignExecuteMethodTable> = | ||
SignExecuteMethodTable[T]["result"]; | ||
} | ||
|
||
class Factory extends ContractFactory<TransactInstance, TransactTypes.Fields> { | ||
encodeFields(fields: TransactTypes.Fields) { | ||
return encodeContractFields( | ||
addStdIdToFields(this.contract, fields), | ||
this.contract.fieldsSig, | ||
AllStructs | ||
); | ||
} | ||
|
||
at(address: string): TransactInstance { | ||
return new TransactInstance(address); | ||
} | ||
|
||
tests = { | ||
deposit: async ( | ||
params: Omit< | ||
TestContractParamsWithoutMaps<TransactTypes.Fields, never>, | ||
"testArgs" | ||
> | ||
): Promise<TestContractResultWithoutMaps<null>> => { | ||
return testMethod(this, "deposit", params, getContractByCodeHash); | ||
}, | ||
withdraw: async ( | ||
params: Omit< | ||
TestContractParamsWithoutMaps<TransactTypes.Fields, never>, | ||
"testArgs" | ||
> | ||
): Promise<TestContractResultWithoutMaps<null>> => { | ||
return testMethod(this, "withdraw", params, getContractByCodeHash); | ||
}, | ||
getTotalDeposits: async ( | ||
params: Omit< | ||
TestContractParamsWithoutMaps<TransactTypes.Fields, never>, | ||
"testArgs" | ||
> | ||
): Promise<TestContractResultWithoutMaps<bigint>> => { | ||
return testMethod( | ||
this, | ||
"getTotalDeposits", | ||
params, | ||
getContractByCodeHash | ||
); | ||
}, | ||
}; | ||
} | ||
|
||
// Use this object to test and deploy the contract | ||
export const Transact = new Factory( | ||
Contract.fromJson( | ||
TransactContractJson, | ||
"", | ||
"e69364160d369d3459e19d1b2fcaae7f0cac7059357dba5616147ea18d0c1f0e", | ||
AllStructs | ||
) | ||
); | ||
|
||
// Use this class to interact with the blockchain | ||
export class TransactInstance extends ContractInstance { | ||
constructor(address: Address) { | ||
super(address); | ||
} | ||
|
||
async fetchState(): Promise<TransactTypes.State> { | ||
return fetchContractState(Transact, this); | ||
} | ||
|
||
view = { | ||
deposit: async ( | ||
params?: TransactTypes.CallMethodParams<"deposit"> | ||
): Promise<TransactTypes.CallMethodResult<"deposit">> => { | ||
return callMethod( | ||
Transact, | ||
this, | ||
"deposit", | ||
params === undefined ? {} : params, | ||
getContractByCodeHash | ||
); | ||
}, | ||
withdraw: async ( | ||
params?: TransactTypes.CallMethodParams<"withdraw"> | ||
): Promise<TransactTypes.CallMethodResult<"withdraw">> => { | ||
return callMethod( | ||
Transact, | ||
this, | ||
"withdraw", | ||
params === undefined ? {} : params, | ||
getContractByCodeHash | ||
); | ||
}, | ||
getTotalDeposits: async ( | ||
params?: TransactTypes.CallMethodParams<"getTotalDeposits"> | ||
): Promise<TransactTypes.CallMethodResult<"getTotalDeposits">> => { | ||
return callMethod( | ||
Transact, | ||
this, | ||
"getTotalDeposits", | ||
params === undefined ? {} : params, | ||
getContractByCodeHash | ||
); | ||
}, | ||
}; | ||
|
||
transact = { | ||
deposit: async ( | ||
params: TransactTypes.SignExecuteMethodParams<"deposit"> | ||
): Promise<TransactTypes.SignExecuteMethodResult<"deposit">> => { | ||
return signExecuteMethod(Transact, this, "deposit", params); | ||
}, | ||
withdraw: async ( | ||
params: TransactTypes.SignExecuteMethodParams<"withdraw"> | ||
): Promise<TransactTypes.SignExecuteMethodResult<"withdraw">> => { | ||
return signExecuteMethod(Transact, this, "withdraw", params); | ||
}, | ||
getTotalDeposits: async ( | ||
params: TransactTypes.SignExecuteMethodParams<"getTotalDeposits"> | ||
): Promise<TransactTypes.SignExecuteMethodResult<"getTotalDeposits">> => { | ||
return signExecuteMethod(Transact, this, "getTotalDeposits", params); | ||
}, | ||
}; | ||
|
||
async multicall<Callss extends TransactTypes.MultiCallParams[]>( | ||
...callss: Callss | ||
): Promise<TransactTypes.MulticallReturnType<Callss>> { | ||
return (await multicallMethods( | ||
Transact, | ||
this, | ||
callss, | ||
getContractByCodeHash | ||
)) as TransactTypes.MulticallReturnType<Callss>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Contract Transact( | ||
mut totalDeposits: U256 | ||
) { | ||
@using(preapprovedAssets = true, assetsInContract = true) | ||
pub fn deposit() -> () { | ||
transferTokenToSelf!(callerAddress!(), ALPH, 1 alph) | ||
totalDeposits = totalDeposits + 1 alph | ||
return | ||
} | ||
|
||
@using(preapprovedAssets = false, assetsInContract = true) | ||
pub fn withdraw() -> () { | ||
transferTokenFromSelf!(callerAddress!(), ALPH, 1 alph) | ||
totalDeposits = totalDeposits - 1 alph | ||
return | ||
} | ||
|
||
pub fn getTotalDeposits() -> U256 { | ||
return totalDeposits | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.